| 21 | } |
| 22 | |
| 23 | std::vector<ITensor *> TRTDepthwiseDeconvolution::onEncode(const std::vector<ITensor *> &xOp) { |
| 24 | #ifdef TRT_LOG |
| 25 | printf("TRTDepthwiseDeconvolution in\n"); |
| 26 | #endif |
| 27 | auto opName = mOp->name()->str(); |
| 28 | auto conv2D = mOp->main_as_Convolution2D(); |
| 29 | auto conv2DCommon = conv2D->common(); |
| 30 | |
| 31 | auto kernelX = conv2DCommon->kernelX(); |
| 32 | auto kernelY = conv2DCommon->kernelY(); |
| 33 | auto outputCount = conv2DCommon->outputCount(); |
| 34 | const float *source = nullptr; |
| 35 | int weightSize = 0; |
| 36 | |
| 37 | std::shared_ptr<ConvolutionCommon::Int8Common> quanCommon; |
| 38 | ConvolutionCommon::getConvParameters(&quanCommon, backend(), mOp, &source, &weightSize); |
| 39 | |
| 40 | nvinfer1::DimsHW NVKSize(kernelY, kernelX); |
| 41 | nvinfer1::DimsHW NVKSSize(conv2DCommon->strideY(), conv2DCommon->strideX()); |
| 42 | |
| 43 | TRTWeight weight{nvinfer1::DataType::kFLOAT, static_cast<void *>(const_cast<float *>(source)), |
| 44 | static_cast<size_t>(weightSize)}; |
| 45 | |
| 46 | TRTWeight bias{nvinfer1::DataType::kFLOAT, static_cast<void *>(const_cast<float *>(conv2D->bias()->data())), |
| 47 | static_cast<size_t>(conv2D->bias()->size())}; |
| 48 | auto conv_layer = |
| 49 | mTrtBackend->getNetwork()->addDeconvolution(*xOp[0], outputCount, NVKSize, weight.get(), bias.get()); |
| 50 | |
| 51 | MNN_ASSERT(conv_layer != nullptr); |
| 52 | conv_layer->setStride(NVKSSize); |
| 53 | conv_layer->setNbGroups(outputCount); |
| 54 | auto pads = ConvolutionCommon::convolutionPad(mInputs[0], mOutputs[0], conv2DCommon); |
| 55 | conv_layer->setPadding(nvinfer1::DimsHW{pads.second, pads.first}); |
| 56 | |
| 57 | if (conv2DCommon->padMode() == PadMode_SAME) { |
| 58 | conv_layer->setPaddingMode(nvinfer1::PaddingMode::kSAME_UPPER); |
| 59 | } |
| 60 | conv_layer->setName(mOp->name()->str().c_str()); |
| 61 | auto relu = conv2DCommon->relu(); |
| 62 | auto relu6 = conv2DCommon->relu6(); |
| 63 | |
| 64 | if (relu) { |
| 65 | mActivationLayer = mTrtBackend->getNetwork()->addActivation(*conv_layer->getOutput(0), ActivationType::kRELU); |
| 66 | } |
| 67 | |
| 68 | if (relu6) { |
| 69 | mActivationLayer = mTrtBackend->getNetwork()->addActivation(*conv_layer->getOutput(0), ActivationType::kCLIP); |
| 70 | mActivationLayer->setAlpha(0.); |
| 71 | mActivationLayer->setBeta(6.); |
| 72 | } |
| 73 | |
| 74 | if (relu || relu6) { |
| 75 | return {mActivationLayer->getOutput(0)}; |
| 76 | } |
| 77 | return {conv_layer->getOutput(0)}; |
| 78 | } |
| 79 | |
| 80 | TRTCreatorRegister<TypedCreator<TRTDepthwiseDeconvolution>> __depthwise_deconv_op(OpType_DeconvolutionDepthwise); |
nothing calls this directly
no test coverage detected