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

Using other face detection algorithm #33

Closed
jeanbverroken opened this issue Apr 22, 2018 · 2 comments
Closed

Using other face detection algorithm #33

jeanbverroken opened this issue Apr 22, 2018 · 2 comments

Comments

@jeanbverroken
Copy link

jeanbverroken commented Apr 22, 2018

Hello, I have a small issue with the code.
First of all, thanks so much for providing us with this code!

In the demo.py the code looks as follows:


    #Get BGR in order for the detector to work.
    input_img = cv2.cvtColor(img.astype('uint8'), cv2.COLOR_GRAY2BGR)
    detected = detector(input_img, 1)
    img_h, img_w, _ = np.shape(input_img)
    faces = np.empty((len(detected), img_size, img_size, 3))
    for i, d in enumerate(detected):
        x1, y1, x2, y2, w, h = d.left(), d.top(), d.right() + 1, d.bottom() + 1, d.width(), d.height()
        xw1 = max(int(x1 - 0.4 * w), 0)
        yw1 = max(int(y1 - 0.4 * h), 0)
        xw2 = min(int(x2 + 0.4 * w), img_w - 1)
        yw2 = min(int(y2 + 0.4 * h), img_h - 1)
        cv2.rectangle(input_img, (x1, y1), (x2, y2), (255, 0, 0), 2)
        faces[i, :, :, :] = cv2.resize(input_img[yw1:yw2 + 1, xw1:xw2 + 1, :], (img_size, img_size))
    
    # predict ages and genders of the detected faces
    results = model.predict(faces)

However, is there any way to use the model.predict(faces) on the input image?
This is because in an earlier stage, I already detected and extracted the faces of the subject that I am working with. This is the input image that I am trying to feed in. This means it is a time loss to do this again, and sometimes the faces can't be detected due to it already being cropped.

When I use the model.predict on the original image, I of course get an error; being:

Error when checking : expected input_11 to have 4 dimensions, but got array with shape (224, 224, 3)

Which is expected. However, is there a simple way to get past this?

The algorithm I am workng with has as output:

cut_image = img[y_m-he:y_m+he,x_m-wi:x_m+wi]
cut_image = cv2.resize(cut_image,(width,height), interpolation = cv2.INTER_AREA)

Thanks so much

@yu4u
Copy link
Owner

yu4u commented Apr 22, 2018

In the demo.py, the shape of the input to model.predict should be (batch_size, 64, 64, 3).
Therefore, the following code will work:

cut_image = cv2.resize(cut_image, (64, 64), interpolation = cv2.INTER_AREA)
cut_image = np.expand_dims(cut_image, axis=0)

@jeanbverroken
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants