| 22 | namespace nvcaffeparser1 |
| 23 | { |
| 24 | ILayer* 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 |
nothing calls this directly
no test coverage detected