Skip to content

MaskRCNN doesnt work using cv::dnn::Net when image resolution changes of input images #14566

Closed

Description

@tompollok
System information (version)
  • OpenCV => 4.1
  • Operating System / Platform => Windows 64 Bit
  • Compiler => Visual Studio 2015
Detailed description

Forwarding images using MaskRCNN fails if the image resolution changes over time.

Steps to reproduce

It works for the first few images, but after about 5 images with each a different resolution no results are available anymore.

in the function postprocess(...)

outDetections = outDetections.reshape(1,(int)(outDetections.total() / 7)); always returns the same number for any forwarded image. Its being stuck at the number of the last successful forwarding.

I used the following code as a reference.

https://github.com/opencv/opencv/blob/48dad1b02ea8f743e6d165e94a5a4842d96c7a7e/samples/dnn/mask_rcnn.cpp

with net.setPreferableBackend(cv::dnn::DNN_BACKEND_OPENCV);

Activity

  1. tompollok commented on May 15, 2019

    @tompollok
    ContributorAuthor

    @alalek isn't this rather a bug than a feature?

  2. dkurt commented on May 18, 2019

    @dkurt
    Member

    Have you tried to use the latest version of OpenCV? I just want to check if this merged changes resolved your problem: #14552.

  3. tompollok commented on May 18, 2019

    @tompollok
    ContributorAuthor

    No only 4.1. Ill try master on Monday

  4. tompollok commented on May 20, 2019

    @tompollok
    ContributorAuthor

    Opencv 4.1 master did not resolve the issue.

    I checked and the commit was already merged into master from 3.4
    #14570

    Here a video of the issue, that shows that the output of the forwarding is not deterministic and fails after forwarding the same pair of images after two iterations:
    https://www.youtube.com/watch?v=o0uvMSGZskA&feature=youtu.be

  5. dkurt commented on May 20, 2019

    @dkurt
    Member

    @tompollok, If you want to help us solve it faster please do not make us to reproduce the video - add a fully working example with all the images.

  6. tompollok commented on May 20, 2019

    @tompollok
    ContributorAuthor

    The code i use is as mentioned in https://github.com/opencv/opencv/blob/48dad1b02ea8f743e6d165e94a5a4842d96c7a7e/samples/dnn/mask_rcnn.cpp

    The only thing that is missing is that the example does not habe a loop to always use the same two images.

    Image A must have a different resolution than B and should contain RCNN model supported objects. In my case persons.

    Forward image A (gives results)
    Forward image B (gives results)
    Forward image A (gives different results than in A1)
    Forward image B (gives different results than in B1)
    Forward image A (gives no results anymore)
    Forward image B (gives no results anymore)

  7. dkurt commented on May 21, 2019

    @dkurt
    Member

    What is image A and image B? Attach them please (in .png format). Or we can use any kind on images to reproduce it?

  8. tompollok commented on May 22, 2019

    @tompollok
    ContributorAuthor

    Image_0000000A
    Image_0000000B

    I should be reproducible for any images as long as the resolution is not equal.

  9. dkurt commented on May 22, 2019

    @dkurt
    Member

    Can confirm the bug:
    0 1
    2 3

  10. tompollok commented on May 23, 2019

    @tompollok
    ContributorAuthor

    Same issue with inference engine backend.

  11. tompollok commented on Jun 6, 2019

    @tompollok
    ContributorAuthor

    Any ideas how to fix this?

  12. dkurt commented on Jun 6, 2019

    @dkurt
    Member

    @tompollok, For now you can forward fixed inputs. Do you really need to vary their sizes?

  13. tompollok commented on Jun 6, 2019

    @tompollok
    ContributorAuthor

    I can reinitialize each time the resolution changes. I use it to create binary masks for imageregions where humans are visible to improve Structure from Motion pipeline by avoiding matching dynamic scene parts.

    Im not in a hurry for a fix.

  14. dkurt commented on Jun 6, 2019

    @dkurt
    Member

    @tompollok, But why not to resize each human ROI to specific size, predict on it and then remap to origin size? Anyway if you run network of different sizes it requires reallocation of memory if input size changed.

  15. tompollok commented on Jun 6, 2019

    @tompollok
    ContributorAuthor

    That i could do, too, but then the inference time scales linear with the number of people. I just reinitialize for now on resolution change. The inference time on CPU is quite slow anyways.

    The reason why i reported this bug is because i thought that this bug might be an issue in general, not only for mask_rcnn.

  16. dkurt commented on Jun 6, 2019

    @dkurt
    Member

    @tompollok, It's not clear for me. How you select image regions and why not to run all the model on entire frame? Why not to resize each image region to specific size?

  17. added a commit that references this issue on Feb 13, 2020
    9a4cafa
  18. dkurt commented on Feb 13, 2020

    @dkurt
    Member

    Sorry for too late fix but here it is: #16580. Thanks for nice catch!

  19. tompollok commented on Feb 14, 2020

    @tompollok
    ContributorAuthor

    You dont have to say sorry. Im very thankful for you investigating it, so thank you for the patch! Its really awesome to see how fast the DNN backends have evolved, especcially in the last 12 months!

  20. added 2 commits that reference this issue on Feb 22, 2020
    5ef3235
    364bdf9
  21. added a commit that references this issue on Jul 30, 2026
    15ddf55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions