Head Pose Lesson 3

I completed Lesson 3 Head Pose and was able to get the entire Jupyter Notebook running. But when I uploaded a new image where the face was not centered the learn.predict yielded the wrong answer. I tried other images that I uploaded and they were also incorrectly classified. when I used PIL to resize the images to 480, 640 the model predicted wrong … it was consistently placing the red dot in the center of the frame but not on the face.

Has anyone been able to run inference on images they uploaded?
Here’s some code I’ve been running to get the model prediction.

dst = ‘/home/ec2-user/.fastai/data/biwi_head_pose/01/frame_00052_rgb.jpg’
img = open_image(dst)
coords = get_ctr(dst)
print(get_ip(img, coords).data)
y_hat = learn.predict(open_image(dst))

Here is code to plot two points the actual and predicted red dot

img = open_image(path/fname)

actual = get_ip(img, get_ctr(fname))
y_hat = learn.predict(img)[0]
pts = torch.cat((actual.data, y_hat.data), 0)
ip = ImagePoints(FlowField(img.size, pts), scale=False)

img.show(y=ip, figsize=(6, 6))

code to show the model prediction on the new image that I uploaded… red dot appears in the center of the image but not on the face

img = open_image(’/home/ec2-user/SageMaker/course-v3/nbs/dl1/mine/test-image-cover2.jpg’)
#img = open_image(’/home/ec2-user/SageMaker/course-v3/nbs/dl1/mine/frame_00052_rgb.jpg’)

y_hat = learn.predict(img)[0]
ip = ImagePoints(FlowField(img.size, y_hat.data), scale=False)
img.show(y=ip, figsize=(6, 6))

the model predicts accurately for the images from the model folders like frame_00052_rgb.jpg

Any idea why learn.predict shows all the points clustered around a same point in a model trained to predict handpoints

Likely the augmentation you chose. I’ve found the more augmentation the more unstable it is. Also if you’re cropping/resizing make sure you pad, not crop as you could lose a few of your points potentially.