Skip to content

Exception using dnn::forward when changing image size #14763

@LaurentBerger

Description

@LaurentBerger
  • OpenCV => 4.1.0-dev
  • Operating System / Platform => Windows 64 Bit
  • Compiler => Visual Studio 2017

I have got this exception :

OpenCV(4.1.0-dev) Error: Assertion failed (inputs[0] == inputs[i]) in cv::dnn::EltwiseLayerImpl::getMemoryShapes, file G:\Lib\opencv\modules\dnn\src\layers\eltwise_layer.cpp, line 116
Problem does not depend of initial image size (or blob)

Steps to reproduce
    {
        dnn::Net neural = dnn::readNet("f:/testDNN/neuralstyle/models/eccv16/la_muse.t7");
        if (neural.empty())
        {
            cout << "check net file path\n";
            return;
        }

        neural.setPreferableTarget(dnn::DNN_TARGET_CPU);
        neural.setPreferableBackend(dnn::DNN_BACKEND_OPENCV);
        Mat src = imread("g:/lib/opencv/samples/data/fruits.jpg");
        resize(src, src, Size(), 0.5,0.5);
        if (src.empty())
        {
            cout << "check image file path\n";
            return;
        }
        Mat input = dnn::blobFromImage(src, 1.0,
            src.size(),
            Scalar(103.939, 116.779, 123.68), false, false);
        Mat out;
        neural.setInput(input);

        out = neural.forward();
        neural.setInput(input);

        out = neural.forward();
        Mat src2;
        resize(src, src2, Size(), 2, 2);
        input = dnn::blobFromImage(src2, 1.0,
            src2.size(),
            Scalar(103.939, 116.779, 123.68), false, false);
        neural.setInput(input); 
        out = neural.forward();// EXCEPTION IS HERE
    }

Models can be download here

Stack trace : 
 	opencv_core410d.dll!cv::error(const cv::Exception & exc) Line 1076	C++
 	opencv_core410d.dll!cv::error(int _code, const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & _err, const char * _func, const char * _file, int _line) Line 1088	C++
 	opencv_dnn410d.dll!cv::dnn::EltwiseLayerImpl::getMemoryShapes(const std::vector<std::vector<int,std::allocator<int> >,std::allocator<std::vector<int,std::allocator<int> > > > & inputs, const int requiredOutputs, std::vector<std::vector<int,std::allocator<int> >,std::allocator<std::vector<int,std::allocator<int> > > > & outputs, std::vector<std::vector<int,std::allocator<int> >,std::allocator<std::vector<int,std::allocator<int> > > > & internals) Line 116	C++
 	opencv_dnn410d.dll!cv::dnn::dnn4_v20190430::Net::Impl::getLayerShapesRecursively(int id, std::map<int,cv::dnn::dnn4_v20190430::`anonymous namespace'::LayerShapes,std::less<int>,std::allocator<std::pair<int const ,cv::dnn::dnn4_v20190430::`anonymous namespace'::LayerShapes> > > & inOutShapes) Line 2568	C++
 	opencv_dnn410d.dll!cv::dnn::dnn4_v20190430::Net::Impl::getLayersShapes(const std::vector<std::vector<int,std::allocator<int> >,std::allocator<std::vector<int,std::allocator<int> > > > & netInputShapes, std::map<int,cv::dnn::dnn4_v20190430::`anonymous namespace'::LayerShapes,std::less<int>,std::allocator<std::pair<int const ,cv::dnn::dnn4_v20190430::`anonymous namespace'::LayerShapes> > > & inOutShapes) Line 2581	C++
 	opencv_dnn410d.dll!cv::dnn::dnn4_v20190430::Net::Impl::allocateLayers(const std::vector<cv::dnn::dnn4_v20190430::LayerPin,std::allocator<cv::dnn::dnn4_v20190430::LayerPin> > & blobsToKeep_) Line 2286	C++
 	opencv_dnn410d.dll!cv::dnn::dnn4_v20190430::Net::Impl::setUpNet(const std::vector<cv::dnn::dnn4_v20190430::LayerPin,std::allocator<cv::dnn::dnn4_v20190430::LayerPin> > & blobsToKeep_) Line 1251	C++
>	opencv_dnn410d.dll!cv::dnn::dnn4_v20190430::Net::forward(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & outputName) Line 2788	C++

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions