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

Method convert

source/cv/ImageProcess.cpp:124–168  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

122}
123
124ErrorCode ImageProcess::convert(const uint8_t* source, int iw, int ih, int stride, Tensor* destOrigin) {
125 auto dest = destOrigin;
126 if (nullptr == dest || nullptr == source) {
127 MNN_ERROR("null dest or source for image process\n");
128 return INPUT_DATA_ERROR;
129 }
130 if (TensorUtils::getDescribeOrigin(dest)->getBackend() == nullptr && destOrigin->buffer().host == nullptr) {
131 MNN_ERROR("Invalid Tensor, the session may not be ready\n");
132 return INPUT_DATA_ERROR;
133 }
134 std::shared_ptr<Tensor> tempTensor;
135 auto ow = dest->width();
136 auto oh = dest->height();
137 auto bpp = dest->channel();
138 auto dimensionFormat = TensorUtils::getDescribe(dest)->dimensionFormat;
139 auto tensorBn = TensorUtils::getDescribeOrigin(dest)->getBackend();
140 auto bnType = MNN_FORWARD_CPU;
141 if(tensorBn){
142 bnType = tensorBn->type();
143 }
144 if (bnType != MNN_FORWARD_CPU) {
145 tempTensor.reset(Tensor::create({1, bpp, oh, ow}, dest->getType(), nullptr, Tensor::CAFFE_C4),[destOrigin] (void* p) {
146 auto hostTensor = (Tensor*)p;
147 destOrigin->copyFromHostTensor(hostTensor);
148 delete hostTensor;
149 });
150 dest = tempTensor.get();
151 }
152 else if (MNN_DATA_FORMAT_NCHW == dimensionFormat) {
153 tempTensor.reset(Tensor::create(dest->shape(), dest->getType(), nullptr, Tensor::CAFFE_C4), [destOrigin](void* p) {
154 auto hostTensor = (Tensor*)p;
155 CPUTensorConverter::convert(hostTensor, destOrigin);
156 delete hostTensor;
157 });
158 dest = tempTensor.get();
159 }
160 dimensionFormat = TensorUtils::getDescribe(dest)->dimensionFormat;
161 if (dimensionFormat == MNN_DATA_FORMAT_NC4HW4) {
162 bpp = 4;
163 }
164 int ic = _getBpp(mInside->config.sourceFormat);
165 mInside->proc->setPadding(mPaddingValue);
166 mInside->proc->resizeFunc(ic, iw, ih, bpp, ow, oh, dest->getType(), stride);
167 return mInside->proc->execFunc(source, stride, dest->host<void>());
168}
169
170ErrorCode ImageProcess::convert(const uint8_t* source, int iw, int ih, int stride, void* dest, int ow, int oh,
171 int outputBpp, int outputStride, halide_type_t type) {

Callers 15

convert_tfliteFunction · 0.45
valueFunction · 0.45
valueFunction · 0.45
test_image_processMethod · 0.45
test_conv2dMethod · 0.45
test_conv2d_transposeMethod · 0.45
test_scaleMethod · 0.45
test_preluMethod · 0.45
test_convertMethod · 0.45

Calls 15

copyFromHostTensorMethod · 0.80
shapeMethod · 0.80
setPaddingMethod · 0.80
resizeFuncMethod · 0.80
execFuncMethod · 0.80
_getBppFunction · 0.70
createFunction · 0.50
convertFunction · 0.50
getBackendMethod · 0.45
bufferMethod · 0.45
widthMethod · 0.45
heightMethod · 0.45

Tested by 11

test_image_processMethod · 0.36
test_conv2dMethod · 0.36
test_conv2d_transposeMethod · 0.36
test_scaleMethod · 0.36
test_preluMethod · 0.36
test_convertMethod · 0.36
test_channel_shuffleMethod · 0.36
test_cropMethod · 0.36
test_resize_exprMethod · 0.36
test_funcFunction · 0.36