NCNN 小记

2018-08-23  本文已影响0人  Zz鱼丸

在做前向过程中,对内存中的数据进行比对发现NCNN对data里的数据进行处理与我的底层不同:

ncnn部分:
cv::resize(bgr, res, cv::Size(227, 227));
res.convertTo(res, CV_32FC3);
ncnn::Mat in = ncnn::Mat::from_pixels_resize(bgr.data, ncnn::Mat::PIXEL_BGR, bgr.cols, bgr.rows, 227, 227);

内存中的数据为:
0x0000000011E100C0  00 00 a8 41 00 00 a8 41 00 00 a8 41 00 00 a8 41 00 00 a8 41 00 00 a8 41 00 00 a0 41 00 00 a0 41 00 00 98 41 00 00 90 41 00 00 90 41 00 00 a0 41 00 00 a0 41 00 00 a0 41 00 00 a8 41 00 00 b8 41 00 00 b8 41 00 00 b8 41 00 00 b0 41 00 00 b0 41 00 00  
0x0000000011E10112  b0 41 00 00 b0 41 00 00 b8 41 00 00 c0 41 00 00 c0 41 00 00 c0 41 00 00 c0 41 00 00 b8 41 00 00 b8 41 00 00 a8 41 00 00 90 41 00 00 90 41 00 00 90 41 00 00 b0 41 00 00 d8 41 00 00 c0 41 00 00 98 41 00 00 d0 41 00 00 00 42 00 00 b8 41 00 00 70 41  
0x0000000011E10164  00 00 a0 41 00 00 c8 41 00 00 f8 41 00 00 08 42 00 00 08 42 00 00 04 42 00 00 f0 41 00 00 d8 41 00 00 b8 41 00 00 b8 41 00 00 b8 41 00 00 d8 41 00 00 00 42 00 00 18 42 00 00 30 42 00 00 34 42 00 00 34 42 00 00 28 42 00 00 20 42 00 00 1c 42 00 00  
0x0000000011E101B6  18 42 00 00 14 42 00 00 14 42 00 00 18 42 00 00 1c 42 00 00 20 42 00 00 2c 42 00 00 38 42 00 00 44 42 00 00 50 42 00 00 54 42 00 00 50 42 00 00 44 42 00 00 44 42 00 00 58 42 00 00 60 42 00 00 5c 42 00 00 5c 42 00 00 60 42 00 00 5c 42 00 00 58 42  
0x0000000011E10208  00 00 4c 42 00 00 40 42 00 00 34 42 00 00 28 42 00 00 28 42 00 00 28 42 00 00 24 42 00 00 24 42 00 00 2c 42 00 00 30 42 00 00 34 42 00 00 34 42 00 00 30 42 00 00 30 42 00 00 2c 42 00 00 2c 42 00 00 2c 42 00 00 24 42 00 00 1c 42 00 00 14 42 00 00  
0x0000000011E1025A  10 42 00 00 0c 42 00 00 10 42 00 00 20 42 00 00 24 42 00 00 1c 42 00 00 18 42 00 00 18 42 00 00 14 42 00 00 10 42 00 00 0c 42 00 00 0c 42 00 00 0c 42 00 00 0c 42 00 00 0c 42 00 00 0c 42 00 00 08 42 00 00 08 42 00 00 14 42 00 00 18 42 00 00 14 42  
0x0000000011E102AC  00 00 14 42 00 00 0c 42 00 00 0c 42 00 00 08 42 00 00 08 42 00 00 04 42 00 00 04 42 00 00 04 42 00 00 04 42 00 00 04 42 00 00 08 42 00 00 08 42 00 00 04 42 00 00 00 42 00 00 00 42 00 00 f0 41 00 00 e0 41 00 00 d8 41 00 00 d0 41 00 00 c8 41 00 00  
0x0000000011E102FE  b8 41 00 00 a8 41 00 00 a0 41 00 00 98 41 00 00 88 41 00 00 80 41 00 00 70 41 00 00 40 41 00 00 30 41 00 00 30 41 00 00 30 41 00 00 20 41 00 00 20 41 00 00 10 41 00 00 10 41 00 00 10 41 00 00 00 41 00 00 00 41 00 00 00 41 00 00 10 41 00 00 00 41  

New Land部分:
NLDJ_Mat res(227, 227, m.type());
NLDJ_Resize(m, res, 227, 227);
NLDJ_Mat dst(res.rows, res.cols, NLDJ_32FC3);
res.convertTo(dst.data, dst.rows, dst.cols, NLDJ_32FC3);
NLDJ_Mat in2 = change_pixels(dst);

内存中的数据为:
0x0000000001E800C0  00 00 a8 41 00 00 a8 41 00 00 a8 41 00 00 a8 41 00 00 a8 41 00 00 a8 41 00 00 a0 41 00 00 98 41 00 00 98 41 00 00 90 41 00 00 90 41 00 00 98 41 00 00 a0 41 00 00 a0 41 00 00 a8 41 00 00 b0 41 00 00 b8 41 00 00 b0 41 00 00 b0 41 00 00 b0 41 00 00  
0x0000000001E80112  b0 41 00 00 b0 41 00 00 b0 41 00 00 b8 41 00 00 b8 41 00 00 b8 41 00 00 b8 41 00 00 b8 41 00 00 b0 41 00 00 a8 41 00 00 98 41 00 00 90 41 00 00 98 41 00 00 a8 41 00 00 c8 41 00 00 b8 41 00 00 90 41 00 00 c8 41 00 00 00 42 00 00 c0 41 00 00 98 41  
0x0000000001E80164  00 00 b8 41 00 00 d8 41 00 00 f8 41 00 00 04 42 00 00 00 42 00 00 f0 41 00 00 d8 41 00 00 c8 41 00 00 b8 41 00 00 b8 41 00 00 b8 41 00 00 d8 41 00 00 00 42 00 00 18 42 00 00 28 42 00 00 2c 42 00 00 2c 42 00 00 20 42 00 00 1c 42 00 00 18 42 00 00  
0x0000000001E801B6  18 42 00 00 14 42 00 00 14 42 00 00 18 42 00 00 1c 42 00 00 20 42 00 00 28 42 00 00 30 42 00 00 3c 42 00 00 44 42 00 00 48 42 00 00 48 42 00 00 40 42 00 00 40 42 00 00 50 42 00 00 58 42 00 00 54 42 00 00 54 42 00 00 58 42 00 00 54 42 00 00 50 42  
0x0000000001E80208  00 00 44 42 00 00 38 42 00 00 2c 42 00 00 24 42 00 00 24 42 00 00 24 42 00 00 20 42 00 00 20 42 00 00 28 42 00 00 2c 42 00 00 30 42 00 00 2c 42 00 00 2c 42 00 00 28 42 00 00 28 42 00 00 24 42 00 00 24 42 00 00 1c 42 00 00 18 42 00 00 10 42 00 00  
0x0000000001E8025A  0c 42 00 00 08 42 00 00 08 42 00 00 18 42 00 00 1c 42 00 00 18 42 00 00 14 42 00 00 10 42 00 00 0c 42 00 00 08 42 00 00 08 42 00 00 08 42 00 00 08 42 00 00 08 42 00 00 08 42 00 00 08 42 00 00 04 42 00 00 04 42 00 00 10 42 00 00 14 42 00 00 10 42  
0x0000000001E802AC  00 00 0c 42 00 00 08 42 00 00 08 42 00 00 04 42 00 00 00 42 00 00 00 42 00 00 00 42 00 00 00 42 00 00 00 42 00 00 00 42 00 00 04 42 00 00 00 42 00 00 f8 41 00 00 f8 41 00 00 f0 41 00 00 e8 41 00 00 d8 41 00 00 d0 41 00 00 c8 41 00 00 c0 41 00 00  
0x0000000001E802FE  b0 41 00 00 a0 41 00 00 98 41 00 00 90 41 00 00 88 41 00 00 80 41 00 00 60 41 00 00 40 41 00 00 30 41 00 00 30 41 00 00 20 41 00 00 20 41 00 00 10 41 00 00 10 41 00 00 10 41 00 00 10 41 00 00 00 41 00 00 00 41 00 00 10 41 00 00 10 41 00 00 00 41  

发现内存中的数据存在差别,虽然00 00 98 41和00 00 98 41都是0.0,但是会影响到后续的计算。最后发现是ncnn的resize与我的不同,可能是选择的插值方法不同。

调用opencv的resize进行修正:
cv::Mat bgr2;
cv::resize(bgr, bgr2, cv::Size(227, 227));
cv::Mat res;
cv::resize(bgr, res, cv::Size(227, 227));
res.convertTo(res, CV_32FC3);
ncnn::Mat in = ncnn::Mat::from_pixels_resize(bgr2.data, ncnn::Mat::PIXEL_BGR, bgr2.cols, bgr2.rows, 227, 227);
上一篇下一篇

猜你喜欢

热点阅读