3using System.Collections.Generic;
6using System.Threading.Tasks;
10 class ConvolutionLayerInfo : LayerInfo
12 public ConvolutionLayerInfo(
LayerParameter layer, VariableCollection inputs) : base(layer, inputs)
19 m_outputs[0].Shape[2] = (
int)Math.Floor((
double)(m_inputs[0].Shape[2] + 2 * nPad - nKernel) / nStride) + 1;
20 m_outputs[0].Shape[3] = (int)Math.Floor((
double)(m_inputs[0].Shape[3] + 2 * nPad - nKernel) / nStride) + 1;
23 public override string Generate(GENERATE gen)
25 int nPad = (m_layer.convolution_param.pad !=
null && m_layer.convolution_param.pad.Count > 0) ? (
int)m_layer.convolution_param.pad[0] : 0;
26 int nKernel = (m_layer.convolution_param.kernel_size !=
null && m_layer.convolution_param.kernel_size.Count > 0) ? (
int)m_layer.convolution_param.kernel_size[0] : 1;
27 int nStride = (m_layer.convolution_param.stride !=
null && m_layer.convolution_param.stride.Count > 0) ? (
int)m_layer.convolution_param.stride[0] : 1;
28 int nDilation = (m_layer.convolution_param.dilation !=
null && m_layer.convolution_param.dilation.Count > 0) ? (
int)m_layer.convolution_param.dilation[0] : 1;
31 if (gen == GENERATE.DEFINITION)
32 strCode +=
" self." + m_layer.name +
" = nn.Conv2d(in_channels=" + m_inputs[0].Shape[1] +
", out_channels=" + m_layer.convolution_param.num_output.ToString() +
", kernel_size=" + nKernel.ToString() +
", stride=" + nStride.ToString() +
", padding=" + nPad.ToString() +
", dilation=" + nDilation.ToString() +
", groups=" + m_layer.convolution_param.group.ToString() +
", bias=" + m_layer.convolution_param.bias_term.ToString() +
")" + Environment.NewLine;
33 else if (gen == GENERATE.INITWEIGHTS)
34 strCode += initWeights(
"", m_layer.name, m_layer.convolution_param.bias_term, m_layer.convolution_param.weight_filler, m_layer.convolution_param.bias_filler);
35 else if (gen == GENERATE.FORWARD)
36 strCode +=
" " + m_outputs.AsText +
" = self." + m_layer.name +
"(" + m_inputs.AsText +
")" + Environment.NewLine;
42 class PoolingLayerInfo : LayerInfo
44 public PoolingLayerInfo(
LayerParameter layer, VariableCollection inputs) : base(layer, inputs)
50 m_outputs[0].Shape[2] = (int)Math.Floor((
double)(m_inputs[0].Shape[2] + 2 * nPad - nKernel) / nStride) + 1;
51 m_outputs[0].Shape[3] = (int)Math.Floor((
double)(m_inputs[0].Shape[3] + 2 * nPad - nKernel) / nStride) + 1;
54 public override string Generate(GENERATE gen)
56 int nPad = (m_layer.pooling_param.pad !=
null && m_layer.pooling_param.pad.Count > 0) ? (
int)m_layer.pooling_param.pad[0] : 0;
57 int nKernel = (m_layer.pooling_param.kernel_size !=
null && m_layer.pooling_param.kernel_size.Count > 0) ? (
int)m_layer.pooling_param.kernel_size[0] : 1;
58 int nStride = (m_layer.pooling_param.stride !=
null && m_layer.pooling_param.stride.Count > 0) ? (
int)m_layer.pooling_param.stride[0] : 1;
59 int nDilation = (m_layer.pooling_param.dilation !=
null && m_layer.pooling_param.dilation.Count > 0) ? (
int)m_layer.pooling_param.dilation[0] : 1;
62 if (gen == GENERATE.DEFINITION)
63 strCode +=
" self." + m_layer.name +
" = nn.MaxPool2d(kernel_size=" + nKernel.ToString() +
", stride=" + nStride.ToString() +
", padding=" + nPad.ToString() +
", dilation=" + nDilation.ToString() +
")" + Environment.NewLine;
64 else if (gen == GENERATE.INITWEIGHTS)
67 else if (gen == GENERATE.FORWARD)
68 strCode +=
" " + m_outputs.AsText +
" = self." + m_layer.name +
"(" + m_inputs.AsText +
")" + Environment.NewLine;
uint num_output
The number of outputs for the layer.
List< uint > kernel_size
Kernel size is given as a single value for equal dimensions in all spatial dimensions,...
List< uint > stride
Stride is given as a single value for equal dimensions in all spatial dimensions, or once per spatial...
List< uint > pad
Pad is given as a single value for equal dimensions in all spatial dimensions, or once per spatial di...
Specifies the base parameter for all layers.
ConvolutionParameter convolution_param
Returns the parameter set when initialized with LayerType.CONVOLUTION
PoolingParameter pooling_param
Returns the parameter set when initialized with LayerType.POOLING
The MyCaffe.param namespace contains parameters used to create models.
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...