Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

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?