opencv: opencv dnn error loading mobilenet v3

System information (version)
  • OpenCV =>4.4.0 and 4.5.0
  • Operating System / Platform => Windows 10 and Ubuntu 20.04
Detailed description

I’m trying to use a mobilenet v3 large model. I have got an error when I try to instantiate a new dnn_DetectionModel object.

cv2.error: OpenCV(4.4.0) C:\OpenCV\4.4.0\opencv\modules\dnn\src\dnn.cpp:3466: error: (-215:Assertion failed) total(os[i]) > 0 in function 'cv::dnn::dnn4_v20200609::Net::Impl::getLayerShapesRecursively'

I saw that last version of opencv 4.x.x support mobilenet v3

Steps to reproduce
net = cv2.dnn_DetectionModel("....pb")
Issue submission checklist
  • [ x ] I report the issue, it’s not a question
  • [ x ] I checked the problem with documentation, FAQ, open issues, answers.opencv.org, Stack Overflow, etc and have not found solution
  • [ x ] I updated to latest OpenCV version and the issue is still there
  • There is reproducer code and related data files: videos, images, onnx, etc

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 17 (4 by maintainers)

Most upvoted comments

Some more clarification: I use the original MobileNetV3 without modification. I have inspected the backtrace of the exception I got (Assert in this line), stepped through the relevant code, found that my problem was in the MobilenetV3/expanded_conv_3/squeeze_excite/mul and that the input shapes are inpShape=[ 4 72 28 28 ] and shape(inputs[1])=[ 4 72 1 1 ]. As far as I understand the current code in the function, it does not support the case with this shape of inputs[1], which requires broadcasting to the W and H dimensions of [1 1] to [28 28]. Or at least the assertions do not cover this case. As I already mentioned above, this problem does not occur with the CUDA backend and I am pretty sure it needs to be fixed in this function, because I have implemented my MobileNetV3-specific workaround in this function and it works fine.

I was able to successfully use MobileNetV3 for classification with the CUDA backend, but get a (probably related) error with the OpenCV backend. It seems like the forward() of the OpenCV scale_layer does not support the operation needed by MobilenetV3/expanded_conv_3/squeeze_excite/mul with inpShape=[ 4 72 28 28 ] and weightsShape=[ 4 72 1 1 ], because it assumes that the weights are the same for all images of the batch.

@KyloEntro : Could you please reopen the issue because it hasn’t been resolved yet but is marked as “Closed”?