Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

models对应的图像格式是BGR还是RGB的顺序? #1

Closed
labimage opened this issue Nov 15, 2018 · 9 comments
Closed

models对应的图像格式是BGR还是RGB的顺序? #1

labimage opened this issue Nov 15, 2018 · 9 comments

Comments

@labimage
Copy link

labimage commented Nov 15, 2018

您好,我运行了您的代码,效果很好。 我看到main函数中读入图像是按照BGR的格式读入的: ncnn::Mat ncnn_img1 = ncnn::Mat::from_pixels(img1.data, ncnn::Mat::PIXEL_BGR, img1.cols, img1.rows); 我疑惑的是,MTCNN和insightface在训练的时候是按照RGB的图像格式来训练的。 有的ncnn版本的MTCNN代码中使用的是ncnn::Mat::PIXEL_BGR2RGB的通道顺序。
我把输入图像换成RGB的格式,该代码也可以工作。
所以想确认下,MTCNN和insightface的模型对应的是哪一种,您是否在转换成ncnn模型的时候,就把对应的数据顺序从RGB转成了BGR?
非常感谢。

@KangKangLoveCat
Copy link
Owner

bgr和rgb读取进去都是一样的,没有通道交换,rgb2bgr才会交换r和b通道

@KangKangLoveCat
Copy link
Owner

模型都是insightface官方的,我直接用ncnn转的,没有修改过

@labimage
Copy link
Author

多谢您的回答,我的问题我可能没有表达清楚。我比较了几个mtcnn的C++代码,您的mtcnn代码的速度很快。 阅读代码的时候我发现您的输入图像的通道顺序和其他版本的不同。
其他的mtcnn的ncnn版本的代码, 通过OpenCV读入图像img1, 然后后再转为ncnn Mat矩阵ncnn_img1,使用的是ncnn::Mat ncnn_img1 = ncnn::Mat::from_pixels(img1.data, ncnn::Mat::PIXEL_BGR2RGB, img1.cols,
img1.rows), 该函数的第二个实参为ncnn::Mat::PIXEL_BGR2RGB,也就是说生成ncnn矩阵的同时把通道顺序从BGR转为RGB, 您的main函数中使用的是ncnn::Mat::PIXEL_BGR,对应的ncnn Mat的通道顺序仍为BGR。
卷积model是和input mat channel的顺序对应的,如果model中的channel顺序是RGB,那么input mat的通道顺序应该相同。
insighface模型是mxnet版本的,model的通道顺序也是RGB。那是不是说input mat的通道顺序也应该为RGB?

@labimage
Copy link
Author

另外,方便告诉一下mtcnn的原模型链接么?
也是从insightface 的github网页上的mtcnn模型转成成ncnn版本的么?
https://github.com/deepinsight/mxnet-mtcnn
https://github.com/deepinsight/mtcnn-ncnn

@KangKangLoveCat
Copy link
Owner

https://github.com/deepinsight/insightface
当时实现的时候我两种读取方式都试了一下,发现用pixel_bgr模式读入能够得到于原作相同的网络输出,而pixel_bgr2rgb模式读入的图像得到的网络输出与原作不一致。具体原理我没有深入思考过,因为我没有训练过模型,具体模型接受怎样的输入,我也不知道。

@KangKangLoveCat
Copy link
Owner

我刚刚仔细看了一下,在mtcnn部分是bgr方式,arcface部分应该是rgb方式,需要转换图片

@labimage
Copy link
Author

mtcnn应该是caffe model转过来的,caffe 的输入通道顺序是BGR,我测试的时候也是发现mtcnn在BGR通道顺序下检测率高。

@tanghy2016
Copy link

请问模型连接是哪个?
https://github.com/deepinsight/insightface/tree/master/deploy/mtcnn-model
https://github.com/deepinsight/insightface/tree/master/gender-age/mtcnn-model
这两个看起来都一样,跟
https://github.com/deepinsight/mxnet-mtcnn
里面的模型是一样的吧,但是我转来试了一下,没有你这里给出的4个ncnn模型效果好呢

@KangKangLoveCat
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants