简体   繁体   English

opencv :: dnn中的神经网络输入大小

[英]Neural network input size in opencv::dnn

I'd like to determine (dynamically) the image size expected as input of a deep neural network model that is loaded with the dnn module of opencv. 我想确定(动态地)作为opencv的dnn模块加载的深度神经网络模型的输入所期望的图像大小。 For instance, if I load a caffe model, I first have: 例如,如果我加载caffe模型,则首先需要:

cv::Mat img = imread("my_image.jpg");
cv::dnn::Net m_net;
m_net = cv::dnn::readNetFromCaffe("my_prototxt","my_model");

int img_size; // TODO how to determine it ?

cv::Mat blob =  cv::dnn::blobFromImage(img, 1.0, cv::Size(img_size, img_size));
m_net.setInput(blob);
cv::Mat res = m_net.forward("layer_name");

My problem is to determine img_size from m_net here. 我的问题是从此处从m_net确定img_size I guess it should be feasible with dnn::getLayersShapes but I do not understand what is supposed to be the first argument in my case. 我想用dnn::getLayersShapes应该是可行的,但我不明白在我的情况下应该是第一个参数。

I give here the example of a caffe model, but I am interested in being able to do the same with a tensorflow, darknet or torch model as well. 我在这里给出了caffe模型的示例,但我也对能够使用tensorflow,darknet或火炬模型执行相同操作感兴趣。

If you open the ".prototext" file that comes with the caffe model, it states the required input sizes. 如果您打开caffe模型随附的“ .prototext”文件,则将说明所需的输入大小。 (Haven't used models other than caffe ones) (除咖啡模型外,未使用其他模型)

Setting correct input size is the responsibility of the user, as some network architectures, eg. 设置正确的输入大小是用户的责任,例如某些网络体系结构。 fully-connected feedforward networks require exact size inputs, while architectures like CNN's do not and can work on arbitrary sizes of input images. 完全连接的前馈网络需要精确大小的输入,而CNN这样的体系结构则不需要,并且可以在任意大小的输入图像上工作。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM