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

Function parseDeconvolution

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

Source from the content-addressed store, hash-verified

22namespace nvcaffeparser1
23{
24ILayer* parseDeconvolution(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 int nbGroups = p.has_group() ? p.group() : 1;
34
35 int dilationH = p.dilation_size() > 0 ? p.dilation(0) : 1;
36 int dilationW = p.dilation_size() > 1 ? p.dilation(1) : p.dilation_size() > 0 ? p.dilation(0) : 1;
37 if (dilationH != 1 || dilationW != 1)
38 {
39 RETURN_AND_LOG_ERROR(nullptr, "Dilated deconvolution is not supported.");
40 }
41
42 int kernelW = p.has_kernel_w() ? p.kernel_w() : p.kernel_size(0);
43 int kernelH = p.has_kernel_h() ? p.kernel_h() : p.kernel_size_size() > 1 ? p.kernel_size(1) : p.kernel_size(0);
44 int C = parserutils::getC(tensors[msg.bottom(0)]->getDimensions());
45
46 float std_dev = 1.0F / sqrtf(kernelW * kernelH * sqrtf(C * nbOutputs));
47 Weights kernelWeights = weightFactory.isInitialized() ? weightFactory(msg.name(), WeightType::kGENERIC) : weightFactory.allocateWeights(kernelW * kernelH * C * nbOutputs / nbGroups, std::normal_distribution<float>(0.0F, std_dev));
48 Weights biasWeights = !p.has_bias_term() || p.bias_term() ? (weightFactory.isInitialized() ? weightFactory(msg.name(), WeightType::kBIAS) : weightFactory.allocateWeights(nbOutputs)) : weightFactory.getNullWeights();
49
50 weightFactory.convert(kernelWeights);
51 weightFactory.convert(biasWeights);
52 auto layer = network.addDeconvolution(*tensors[msg.bottom(0)], nbOutputs, DimsHW{kernelH, kernelW}, kernelWeights, biasWeights);
53
54 if (layer)
55 {
56 int strideW = p.has_stride_w() ? p.stride_w() : p.stride_size() > 0 ? p.stride(0) : 1;
57 int strideH = p.has_stride_h() ? p.stride_h() : p.stride_size() > 1 ? p.stride(1) : p.stride_size() > 0 ? p.stride(0) : 1;
58
59 int padW = p.has_pad_w() ? p.pad_w() : p.pad_size() > 0 ? p.pad(0) : 0;
60 int padH = p.has_pad_h() ? p.pad_h() : p.pad_size() > 1 ? p.pad(1) : p.pad_size() > 0 ? p.pad(0) : 0;
61
62 layer->setStride(DimsHW{strideH, strideW});
63 layer->setPadding(DimsHW{padH, padW});
64 layer->setPaddingMode(PaddingMode::kCAFFE_ROUND_DOWN);
65 layer->setNbGroups(nbGroups);
66
67 layer->setKernelWeights(kernelWeights);
68 if (!p.has_bias_term() || p.bias_term())
69 {
70 layer->setBiasWeights(biasWeights);
71 }
72 }
73 return layer;
74}
75} //namespace nvcaffeparser1

Callers

nothing calls this directly

Calls 15

checkBlobsFunction · 0.85
isInitializedMethod · 0.80
nameMethod · 0.80
allocateWeightsMethod · 0.80
getNullWeightsMethod · 0.80
addDeconvolutionMethod · 0.80
getCFunction · 0.50
getDimensionsMethod · 0.45
convertMethod · 0.45
setStrideMethod · 0.45
setPaddingMethod · 0.45
setPaddingModeMethod · 0.45

Tested by

no test coverage detected