Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash on processing a transparent PNG #16

Open
sbrl opened this issue Jul 26, 2021 · 2 comments
Open

Crash on processing a transparent PNG #16

sbrl opened this issue Jul 26, 2021 · 2 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@sbrl
Copy link

sbrl commented Jul 26, 2021

Instead of crashing when processing a transparent PNG, I recommend automatically removing the alpha (opacity) channel from the image before processing it.

[ERROR:0] global /tmp/pip-req-build-afu9cjzs/opencv/modules/dnn/src/dnn.cpp (3509) getLayerShapesRecursively OPENCV/DNN: [Convolution]:(363): getMemoryShapes() throws exception. inputs=1 outputs=0/1 blobs=1
[ERROR:0] global /tmp/pip-req-build-afu9cjzs/opencv/modules/dnn/src/dnn.cpp (3515) getLayerShapesRecursively     input[0] = [ 1 1 768 1024 ]
[ERROR:0] global /tmp/pip-req-build-afu9cjzs/opencv/modules/dnn/src/dnn.cpp (3523) getLayerShapesRecursively     blobs[0] = CV_32FC1 [ 32 3 3 3 ]
[ERROR:0] global /tmp/pip-req-build-afu9cjzs/opencv/modules/dnn/src/dnn.cpp (3525) getLayerShapesRecursively Exception message: OpenCV(4.5.3) /tmp/pip-req-build-afu9cjzs/opencv/modules/dnn/src/layers/convolution_layer.cpp:385: error: (-2:Unspecified error) Number of input channels should be multiple of 3 but got 1 in function 'getMemoryShapes'

Traceback (most recent call last):
  File "/usr/local/bin/deface", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.8/dist-packages/deface/deface.py", line 312, in main
    image_detect(
  File "/usr/local/lib/python3.8/dist-packages/deface/deface.py", line 171, in image_detect
    dets, _ = centerface(frame, threshold=threshold)
  File "/usr/local/lib/python3.8/dist-packages/deface/centerface.py", line 88, in __call__
    heatmap, scale, offset, lms = self.net.forward(self.onnx_output_names)
cv2.error: OpenCV(4.5.3) /tmp/pip-req-build-afu9cjzs/opencv/modules/dnn/src/layers/convolution_layer.cpp:385: error: (-2:Unspecified error) Number of input channels should be multiple of 3 but got 1 in function 'getMemoryShapes'
@mdraw
Copy link
Member

mdraw commented Aug 10, 2021

Thanks for the report. Did you verify that it worked after removing the alpha channel? To my eyes the error message implies that you have fed in a single-channel grayscale image (which shouldn't crash the program either of course). All images should be converted to RGB if they are not already in RGB.

@sbrl
Copy link
Author

sbrl commented Sep 3, 2021

I did verify it worked @mdraw, though I did still get some crashes (but not as many as before).

Scenario: A have a large number (~170K) images from twitter I'm going to classify, but as part of the ethics evaluation it was agreed that all faces must be blurred in all images downloaded. To this end, the dataset is a mixed bag in a large number of different sizes, formats, channels, etc rather than being standardised - hence the reason why I found this bug in the first place.

@mdraw mdraw added bug Something isn't working enhancement New feature or request labels Jun 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants