输入输出的sizes_of_dim目测不对,求助

onnx模型。是pytorch训练导出的onnx模型。输入输出都是nchw格式。c通道数,h高,w宽。

提取出的json模型:
链接:百度网盘 请输入提取码
提取码:eulf

期望:
推理时,推理框架对我输入的数据不做任何修改(即reorder channel等)。输出也是我模型的原输出。

我目前的做法:
量化时:
$tensorzone
–action quantization
–source text
–source-file ./data/nuscenes_validation_tf.txt
–channel-mean-value ‘0 0 0 1’
–model-input ${NAME}.json
–model-data ${NAME}.data
–quantized-dtype asymmetric_quantized-u8
–quantized-rebuild

转case时
$export_ovxlib
–model-input ${NAME}.json
–data-input ${NAME}.data
–reorder-channel ‘0 1 2’
–channel-mean-value ‘0 0 0 1’
–export-dtype quantized
–model-quantize ${NAME}.quantize
–optimize VIPNANOQI_PID0X88
–viv-sdk …/bin/vcmdtools
–pack-nbg-unify

config.modelType = ONNX;
config.nbgType = NN_NBG_MEMORY;
config.length = size;
fclose(fp);

config.typeSize = sizeof(aml_config);
context = aml_module_create(&config);	
if (context == NULL) {
    return -1;
}

nn_input inData;
inData.input_index = 0; //this value is index of input,begin from 0
inData.size = img_size;
inData.input = (unsigned char*)image_data;
inData.input_type = BINARY_RAW_DATA;
ret = aml_module_input_set(context, &inData);


printf(“the input[0] sizes_of_dim:%d,%d,%d,%d\n”,inptr->info[0].sizes_of_dim[0], inptr->info[0].sizes_of_dim[1],inptr->info[0].sizes_of_dim[2],inptr->info[0].sizes_of_dim[3]);
输出为:
the input[0] sizes_of_dim:800,448,3,1

    printf("the output[0] sizes_of_dim:%d,%d,%d,%d\n", outptr->info[0].sizes_of_dim[0], outptr->info[0].sizes_of_dim[1],outptr->info[0].sizes_of_dim[2],outptr->info[0].sizes_of_dim[3]);

输出为:
the output[0] sizes_of_dim:200,112,10,1

原onnx模型的
输入为:1,3,448,800
输入为:1,10,112,200

目测从graph拿到的输入输出 dim size 跟我期望的刚好相反。
求解决方法。

@ideafold

你这个image_data怎么来的。虽然都是NCHW,但是pytorch输入是rrrgggbbb,onnx是bbbgggrrr

非原始rgb值。
是从图像进行处理过的。

训练代码:
inp = cv2.imread(…);
inp = (inp.astype(np.float32) / 255.)
inp = (inp - self.mean) / self.std
inp = inp.transpose(2, 0, 1)

例如mean=[0.40789654, 0.44719302, 0.47026115]
std=[0.28863828, 0.27408164, 0.27809835]

@ideafold 你自己处理好就行,onnx是bbggrrr的nchw

image

onnx模型中的输入输出是与我的pytorch模型时一致的。

看了下,是 提取json的时候工具就搞错了。。。
变成了1x448x800x3了。
并且输出结果的维度也不对了。
onnx模型的第0个结果维度是1x10x112x200。而提取出的json中的1x111x199x10。

我再研究一下。这里目测有点乱。