johnwmillr / Facer

Simple (šŸ¤ž) face averaging (šŸ™‚) in Python (šŸ)
MIT License
80 stars 11 forks source link

Error running code #11

Closed connormeaton closed 2 years ago

connormeaton commented 2 years ago

Thanks for this interesting project.

I am running your example on a directory of images. I get this error:

Loading face detector and landmark prediction models...
Done, models loaded.

Found 137 in '../faces'.
(1 / 137): ../faces/ffmpeg_1.jpg
(15 / 137): ../faces/ffmpeg_111.jpg
(29 / 137): ../faces/ffmpeg_125.jpg
(43 / 137): ../faces/ffmpeg_138.jpg
(57 / 137): ../faces/ffmpeg_25.jpg
(71 / 137): ../faces/ffmpeg_38.jpg
(85 / 137): ../faces/ffmpeg_50.jpg
(99 / 137): ../faces/ffmpeg_63.jpg
(113 / 137): ../faces/ffmpeg_77.jpg
(127 / 137): ../faces/ffmpeg_9.jpg

Starting face landmark detection...
Processing 137 images.
(1 / 137): ../faces/ffmpeg_1.jpg
(15 / 137): ../faces/ffmpeg_111.jpg
(29 / 137): ../faces/ffmpeg_125.jpg
(43 / 137): ../faces/ffmpeg_138.jpg
(57 / 137): ../faces/ffmpeg_25.jpg
(71 / 137): ../faces/ffmpeg_38.jpg
(85 / 137): ../faces/ffmpeg_50.jpg
(99 / 137): ../faces/ffmpeg_63.jpg
(113 / 137): ../faces/ffmpeg_77.jpg
(127 / 137): ../faces/ffmpeg_9.jpg
Skipped 1.5% of images.

Starting face averaging for 135 faces.
Image 1 / 135
Image 8 / 135
Image 15 / 135
Image 22 / 135
Image 29 / 135
Image 36 / 135
Image 43 / 135
Image 50 / 135
Image 57 / 135
Image 64 / 135
Image 71 / 135
Image 78 / 135
Image 85 / 135
Image 92 / 135
Image 99 / 135
Image 106 / 135
Image 113 / 135
Image 120 / 135
Traceback (most recent call last):
  File "test.py", line 11, in <module>
    average_face = facer.create_average_face(faces, landmarks, save_image=True)
  File "/Users/asi/connor_asi/face_avg/Facer/facer/facer.py", line 221, in create_average_face
    dt = calculateDelaunayTriangles(rect, np.array(pointsAvg))
  File "/Users/asi/connor_asi/face_avg/Facer/facer/utils.py", line 62, in calculateDelaunayTriangles
    subdiv.insert((p[0], p[1]))
cv2.error: OpenCV(4.5.3) /private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/pip-req-build-tetsazc6/opencv/modules/imgproc/src/subdivision2d.cpp:288: error: (-211:One of the arguments' values is out of range)  in function 'locate'

I'm running OpenCV 4.5.3 if thats helpful.

Any ideas? Thank you!

johnwmillr commented 2 years ago

Hmm, nothing immediately jumps out to me. Can you put in a print statement to figure out which image file its failing on? Is there something that makes that image different from the rest? Does the error go away if you remove the file?

connormeaton commented 2 years ago

Thanks for the quick response. I through in a try/except and print statement to try to figure out what is going on. Here is my code for facer.py:

    # Delaunay triangulation
        rect = (0, 0, w, h)
        try:
            dt = calculateDelaunayTriangles(rect, np.array(pointsAvg))

            # Warp input images to average image landmarks
            output = np.zeros((h, w, 3), np.float32())
            for i in range(0, len(imagesNorm)):
                img = np.zeros((h, w, 3), np.float32())
                # Transform triangles one by one
                for j in range(0, len(dt)):
                    tin, tout = [], []

                    for k in range(0, 3):
                        pIn = pointsNorm[i][dt[j][k]]
                        pIn = constrainPoint(pIn, w, h)

                        pOut = pointsAvg[dt[j][k]]
                        pOut = constrainPoint(pOut, w, h)

                        tin.append(pIn)
                        tout.append(pOut)
                    img = warpTriangle(imagesNorm[i], img, tin, tout)
                if return_intermediates:
                    incremental.append((output + img) / (i + 1))

                # Add image intensities for averaging
                output = output + img

            # Divide by num_images to get average
            output = output / num_images

            if return_intermediates:
                warped.append(img_affine)
        except:
            print('skipping broken frame...')
            pass
    incremental = incremental[-num_images:]
    print('Done.')

This gave me:

Loading face detector and landmark prediction models...
Done, models loaded.

Found 118 in '../faces'.
(1 / 118): ../faces/ffmpeg_1.jpg
(13 / 118): ../faces/ffmpeg_11.jpg
(25 / 118): ../faces/ffmpeg_13.jpg
(37 / 118): ../faces/ffmpeg_24.jpg
(49 / 118): ../faces/ffmpeg_35.jpg
(61 / 118): ../faces/ffmpeg_46.jpg
(73 / 118): ../faces/ffmpeg_57.jpg
(85 / 118): ../faces/ffmpeg_68.jpg
(97 / 118): ../faces/ffmpeg_8.jpg
(109 / 118): ../faces/ffmpeg_90.jpg

Starting face landmark detection...
Processing 118 images.
(1 / 118): ../faces/ffmpeg_1.jpg
(13 / 118): ../faces/ffmpeg_11.jpg
(25 / 118): ../faces/ffmpeg_13.jpg
(37 / 118): ../faces/ffmpeg_24.jpg
(49 / 118): ../faces/ffmpeg_35.jpg
(61 / 118): ../faces/ffmpeg_46.jpg
(73 / 118): ../faces/ffmpeg_57.jpg
(85 / 118): ../faces/ffmpeg_68.jpg
(97 / 118): ../faces/ffmpeg_8.jpg
(109 / 118): ../faces/ffmpeg_90.jpg
Skipped 1.7% of images.

Starting face averaging for 116 faces.
Image 1 / 116
Image 7 / 116
Image 13 / 116
Image 19 / 116
Image 25 / 116
Image 31 / 116
Image 37 / 116
Image 43 / 116
Image 49 / 116
Image 55 / 116
Image 61 / 116
Image 67 / 116
Image 73 / 116
Image 79 / 116
Image 85 / 116
Image 91 / 116
Image 97 / 116
Image 103 / 116
skipping broken frame...
skipping broken frame...
skipping broken frame...
skipping broken frame...
skipping broken frame...
Image 109 / 116
skipping broken frame...
skipping broken frame...
skipping broken frame...
skipping broken frame...
skipping broken frame...
skipping broken frame...
Image 115 / 116
skipping broken frame...
skipping broken frame...
Done.
Segmentation fault: 11

It seems like there was something fishy with the images (though they looked fine to me and had landmarks predicted).

Unfortunately, python crashes after the Done. print statement with segmentation fault 11. Have you come across this?

Thanks again!

connormeaton commented 2 years ago

FYI it worked. Not sure why. Maybe my machine was running too much before and could handle the load. Thanks!

johnwmillr commented 2 years ago

Glad to hear you've got it working. Good luck with your project!