Exemplo n.º 1
0
        /// <summary>
        /// Computes a 2-D convolution given 4-D `input` and `filter` tensors.
        ///
        /// Given an input tensor of shape `[batch, in_height, in_width, in_channels]`
        /// and a filter / kernel tensor of shape
        /// `[filter_height, filter_width, in_channels, out_channels]`, this op
        /// performs the following:
        ///
        /// 1. Flattens the filter to a 2-D matrix with shape
        ///    `[filter_height * filter_width * in_channels, output_channels]`.
        /// 2. Extracts image patches from the input tensor to form a *virtual*
        ///    tensor of shape `[batch, out_height, out_width,
        ///    filter_height * filter_width * in_channels]`.
        /// 3. For each patch, right-multiplies the filter matrix and the image patch
        ///    vector.
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public static Tensor conv2d(Conv2dParams parameters)
        {
            var _op = _op_def_lib._apply_op_helper("Conv2D", name: parameters.Name, args: new
            {
                input             = parameters.Input,
                filter            = parameters.Filter,
                strides           = parameters.Strides,
                padding           = parameters.Padding,
                use_cudnn_on_gpu  = parameters.UseCudnnOnGpu,
                explicit_paddings = parameters.ExplicitPaddings,
                data_format       = parameters.DataFormat,
                dilations         = parameters.Dilations
            });

            return(_op.outputs[0]);
        }
Exemplo n.º 2
0
            public Tensor conv2d(Tensor input, RefVariable filter, int[] strides, string padding, bool use_cudnn_on_gpu = true,
                                 string data_format = "NHWC", int[] dilations = null, string name = null)
            {
                var parameters = new Conv2dParams
                {
                    Input         = input,
                    Filter        = filter,
                    Strides       = strides,
                    Padding       = padding,
                    UseCudnnOnGpu = use_cudnn_on_gpu,
                    DataFormat    = data_format,
                    Name          = name
                };

                if (dilations != null)
                {
                    parameters.Dilations = dilations;
                }

                return(gen_nn_ops.conv2d(parameters));
            }