MCPcopy Create free account
hub / github.com/alibaba/MNN / _Conv

Function _Conv

test/op/ConvolutionTest.cpp:90–170  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88}
89
90VARP _Conv(VARP weight, VARP bias, VARP x, PaddingMode pad = VALID, INTS stride = {1, 1}, INTS dilate = {1, 1},
91 int group = 1, INTS pads = {0, 0}, MNN::SparseAlgo sparseAlgo = MNN::SparseAlgo_RANDOM, int sparseBlockOC = 1, bool sparse = false) {
92std::unique_ptr<OpT> convOp(new OpT);
93convOp->type = OpType_Convolution;
94auto shape = weight -> getInfo();
95if (NHWC == shape->order) {
96 weight = _Transpose(weight, {0, 3, 1, 2});
97 shape = weight->getInfo();
98 }
99 auto channel = std::vector<int>{shape->dim[0], shape->dim[1]};
100 auto kernelSize = std::vector<int>{shape->dim[3], shape->dim[2]};
101 if (1 == channel[1] && channel[0] == group) {
102 convOp->type = OpType_ConvolutionDepthwise;
103 channel[1] = group;
104 }
105 convOp->main.type = OpParameter_Convolution2D;
106 convOp->main.value = new Convolution2DT;
107 auto conv2D = convOp->main.AsConvolution2D();
108 conv2D->common.reset(new Convolution2DCommonT);
109 if (pads.size() == 2) {
110 conv2D->common->padX = pads[0];
111 conv2D->common->padY = pads[1];
112 } else {
113 conv2D->common->pads = std::move(pads);
114 }
115 conv2D->common->padMode = _convertPadMode(pad);
116 conv2D->common->strideX = stride[0];
117 conv2D->common->strideY = stride[1];
118 conv2D->common->group = group;
119 conv2D->common->outputCount = channel[0];
120 conv2D->common->inputCount = channel[1];
121 conv2D->common->dilateX = dilate[0];
122 conv2D->common->dilateY = dilate[1];
123 conv2D->common->kernelX = kernelSize[0];
124 conv2D->common->kernelY = kernelSize[1];
125 if (sparse) {
126 size_t weightNNZElement, weightBlockNumber = 0;
127 int weightSize = weight->getInfo()->size;
128 int biasSize = bias->getInfo()->size;
129 CommonCompute::statisticWeightSparsity(weightNNZElement, weightBlockNumber, weight->readMap<float>(), biasSize, weightSize / biasSize, sparseBlockOC);
130
131 std::unique_ptr<MNN::AttributeT> arg1(new MNN::AttributeT);
132 arg1->key = "sparseBlockOC";
133 arg1->i = sparseBlockOC;
134
135 std::unique_ptr<MNN::AttributeT> arg2(new MNN::AttributeT);;
136 arg2->key = "sparseBlockKernel";
137 arg2->i = 1;
138
139 std::unique_ptr<MNN::AttributeT> arg3(new MNN::AttributeT);;
140 arg3->key = "NNZElement";
141 arg3->i = weightNNZElement;
142
143 std::unique_ptr<MNN::AttributeT> arg4(new MNN::AttributeT);;
144 arg4->key = "blockNumber";
145 arg4->i = weightBlockNumber;
146
147 flatbuffers::FlatBufferBuilder builder;

Callers 1

testMethod · 0.70

Calls 15

_TransposeFunction · 0.85
statisticWeightSparsityFunction · 0.85
CreateAttributeFunction · 0.85
CreateSparseCommonFunction · 0.85
AsConvolution2DMethod · 0.80
_convertPadModeFunction · 0.70
createFunction · 0.50
fillFunction · 0.50
getInfoMethod · 0.45
resetMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected