MCPcopy Create free account
hub / github.com/NVIDIA/TensorRT / parseConvolution

Function parseConvolution

parsers/caffe/caffeParser/opParsers/parseConv.cpp:24–68  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22namespace nvcaffeparser1
23{
24ILayer* parseConvolution(INetworkDefinition& network, const trtcaffe::LayerParameter& msg, CaffeWeightFactory& weightFactory, BlobNameToTensor& tensors)
25{
26 if (!checkBlobs(msg, 1, 1))
27 {
28 return nullptr;
29 }
30
31 const trtcaffe::ConvolutionParameter& p = msg.convolution_param();
32 int nbOutputs = p.num_output();
33
34 int kernelH = p.has_kernel_h() ? p.kernel_h() : p.kernel_size(0);
35 int kernelW = p.has_kernel_w() ? p.kernel_w() : p.kernel_size_size() > 1 ? p.kernel_size(1) : p.kernel_size(0);
36 int C = parserutils::getC(tensors[msg.bottom(0)]->getDimensions());
37 int G = p.has_group() ? p.group() : 1;
38
39 auto CbyG = float(C / G * nbOutputs);
40 float std_dev = 1.0F / sqrtf((kernelW * kernelH * sqrtf(CbyG)));
41 Weights kernelWeights = weightFactory.isInitialized() ? weightFactory(msg.name(), WeightType::kGENERIC) : weightFactory.allocateWeights(kernelW * kernelH * CbyG, std::normal_distribution<float>(0.0F, std_dev));
42 Weights biasWeights = !p.has_bias_term() || p.bias_term() ? (weightFactory.isInitialized() ? weightFactory(msg.name(), WeightType::kBIAS) : weightFactory.allocateWeights(nbOutputs)) : weightFactory.getNullWeights();
43
44 weightFactory.convert(kernelWeights);
45 weightFactory.convert(biasWeights);
46 auto inTensor = tensors[msg.bottom(0)];
47 auto layer = network.addConvolution(*inTensor, nbOutputs, DimsHW{kernelH, kernelW}, kernelWeights, biasWeights);
48
49 if (layer)
50 {
51 int strideH = p.has_stride_h() ? p.stride_h() : p.stride_size() > 0 ? p.stride(0) : 1;
52 int strideW = p.has_stride_w() ? p.stride_w() : p.stride_size() > 1 ? p.stride(1) : p.stride_size() > 0 ? p.stride(0) : 1;
53
54 int padH = p.has_pad_h() ? p.pad_h() : p.pad_size() > 0 ? p.pad(0) : 0;
55 int padW = p.has_pad_w() ? p.pad_w() : p.pad_size() > 1 ? p.pad(1) : p.pad_size() > 0 ? p.pad(0) : 0;
56
57 int dilationH = p.dilation_size() > 0 ? p.dilation(0) : 1;
58 int dilationW = p.dilation_size() > 1 ? p.dilation(1) : p.dilation_size() > 0 ? p.dilation(0) : 1;
59
60 layer->setStride(DimsHW{strideH, strideW});
61 layer->setPadding(DimsHW{padH, padW});
62 layer->setPaddingMode(PaddingMode::kCAFFE_ROUND_DOWN);
63 layer->setDilation(DimsHW{dilationH, dilationW});
64
65 layer->setNbGroups(G);
66 }
67 return layer;
68}
69} //namespace nvcaffeparser1

Callers

nothing calls this directly

Calls 14

checkBlobsFunction · 0.85
isInitializedMethod · 0.80
nameMethod · 0.80
allocateWeightsMethod · 0.80
getNullWeightsMethod · 0.80
addConvolutionMethod · 0.80
setDilationMethod · 0.80
getCFunction · 0.50
getDimensionsMethod · 0.45
convertMethod · 0.45
setStrideMethod · 0.45
setPaddingMethod · 0.45

Tested by

no test coverage detected