Ask Your Question
0

How to use Net::setInput(InputArray blob, const String& name)

asked 2018-06-22 07:59:27 -0600

SEbert gravatar image

Dear OpenCV fellows, I have a tensorflow net (.pb) with twelve output layers. I can successfully forward my input blob to every single output layer with the help of the following code

    cv::Mat output1 = m_oDetectionNet.forward(std::string("conv10_2_mbox_conf_1/Conv2D"));
    cv::Mat output2 = m_oDetectionNet.forward(std::string("conv10_2_mbox_loc_1/Conv2D"));
    cv::Mat output3 = m_oDetectionNet.forward(std::string("conv9_2_mbox_conf_1/Conv2D"));
    cv::Mat output4 = m_oDetectionNet.forward(std::string("conv9_2_mbox_loc_1/Conv2D"));
    cv::Mat output5 = m_oDetectionNet.forward(std::string("conv8_2_mbox_conf_1/Conv2D"));
    cv::Mat output6 = m_oDetectionNet.forward(std::string("conv8_2_mbox_loc_1/Conv2D"));
    cv::Mat output7 = m_oDetectionNet.forward(std::string("fc7_mbox_conf_1/Conv2D"));
    cv::Mat output8 = m_oDetectionNet.forward(std::string("fc7_mbox_loc_1/Conv2D"));
    cv::Mat output9 = m_oDetectionNet.forward(std::string("conv13_3_norm_mbox_conf_1/Conv2D"));
    cv::Mat output10 = m_oDetectionNet.forward(std::string("conv13_3_norm_mbox_loc_1/Conv2D"));
    cv::Mat output11 = m_oDetectionNet.forward(std::string("conv11_3_norm_mbox_conf_1/Conv2D"));
    cv::Mat output12 = m_oDetectionNet.forward(std::string("conv11_3_norm_mbox_loc_1/Conv2D"));

unfortunatly, this is bad performance-wise. All output-layers use the same basenet, therefore the basenet will be computed for the same input 12 times. Is it possible to somehow re-use the last basenet-output as input blob with the function Net::setInput(InputArray blob, const String& name)? I tried, but I got the error

OpenCV(4.0.0-pre) Error: Requested object was not found (Requested blob "conv_pw_13_relu_1/clip_by_value" not found) in cv::dnn::experimental_dnn_v4::Net::setInput

when using

m_oDetectionNet.forward(std::string("conv_pw_13_relu_1/clip_by_value"))

all runs fine, thus I am sure, that the name of the layer is valid. Any ideas?

edit retag flag offensive close merge delete

Comments

1

yea, doing several forward() passes is wasteful.

do you have these overloads ?

they should enable you to specify several outputs in one pass.

please try and report back (that would make a nice answer !)

berak gravatar imageberak ( 2018-06-22 08:39:14 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2018-06-22 09:10:53 -0600

SEbert gravatar image

updated 2018-06-22 09:32:47 -0600

berak gravatar image

Thank you very much for this hint. The following code works great!

    const std::vector<cv::String> vsOutputNames = { "conv10_2_mbox_conf_1/Conv2D" ,"conv9_2_mbox_conf_1/Conv2D","conv8_2_mbox_conf_1/Conv2D","fc7_mbox_conf_1/Conv2D","conv13_3_norm_mbox_conf_1/Conv2D","conv11_3_norm_mbox_conf_1/Conv2D", "conv10_2_mbox_loc_1/Conv2D" ,"conv9_2_mbox_loc_1/Conv2D","conv8_2_mbox_loc_1/Conv2D","fc7_mbox_loc_1/Conv2D","conv13_3_norm_mbox_loc_1/Conv2D","conv11_3_norm_mbox_loc_1/Conv2D" } ;
    std::vector<cv::Mat> voBlobs;
    m_oDetectionNet.forward(voBlobs, vsOutputNames);

I did not benchmark both version, so I hope, that it internally does the propagation only once ;)

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-06-22 07:59:27 -0600

Seen: 3,107 times

Last updated: Jun 22 '18