deepfakes / faceswap

Deepfakes Software For All
https://www.faceswap.dev
GNU General Public License v3.0
52.42k stars 13.22k forks source link

GPU out of memory while extracting with CNN face detector. #152

Closed Uklosk closed 6 years ago

Uklosk commented 6 years ago

Expected behavior

Same behaviour as using the CPU.

Actual behavior

After a few images:

Failed to extract from image: images-dir/32341.jpg. Reason: Error while calling cudaMalloc(&data, n) in file dlib-dir/dnn/cuda_data_ptr.cpp:28. code: 2, reason: out of memory

Steps to reproduce

Using dlib with CUDA support: Extract a folder with a few hundred images using CNN detector.

Other relevant information

IUsedToBeAPygmy commented 6 years ago

What are the width and height and the filesize of 32341.jpg ?

Uklosk commented 6 years ago

1080x1262

I have tried to remove it and the same happens with other images of similar size.

Dammit, I suppose it is a problem of face_recognition, but 4GB should be enough for those images.

Clorr commented 6 years ago

The problem does not come from face_recognition, which uses dlib methods. The dlib's author also has no other advice than reducing image size

IUsedToBeAPygmy commented 6 years ago

just crop the face and resize to 512-ish. The final face gets scaled to 256x256 anyway.

Uklosk commented 6 years ago

I'm trying to find the max size I can safely use and resize all images bigger than that automatically.

IUsedToBeAPygmy commented 6 years ago

Use ImageResizer. Select all images, right click -> Resize pictures. Then select Custom : Scale to 900x900 pixels.

It'll make sure the max(width, height) is 900 pixels (keeping the aspect ratio)

http://www.bricelam.net/ImageResizer/

Clorr commented 6 years ago

You can do this but keep in mind you will have the same problem on the convert command (unless we do save alignments, see #135 )

Uklosk commented 6 years ago

Thanks.

For those interested, in Linux install ImageMagick and then:

for file in *.png *.jpg *.jpeg; do convert $file -resize 1000\>x1000\> $file; done

That will downscale all images if either their height or width is bigger than 1000 while keeping their aspect ratio.