ORB-HD / deface

Video anonymization by face detection

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Crash on processing a transparent PNG

sbrl opened this issue · comments

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'

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.

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.