gustavz / AttractiveNet

AttractiveNet - Regressing on Facial Attractiveness with Neural Networks - An End-to-End Deep Learning Tutorial in Python.
MIT License
37 stars 7 forks source link

Inaccurate stretch based resizing when processing images #2

Open RandomGamingDev opened 3 months ago

RandomGamingDev commented 3 months ago

By using cv2.resize the ratio of width to height isn't maintained stretching and distorting the image and the face in it in a way that the bot wasn't trained for and that isn't seen in the bot's training data.

def preprocess_image(image,target_size):
    return cv2.resize(cv2.cvtColor(image, cv2.COLOR_BGR2RGB),target_size) / .255

The created PR adds the resize_with_pad function to more accurately resize the image by resizing the maximum dimension assuming the goal size is a box and maximum dimension comparatively when it isn't (dimension divided by each dimension's corresponding goal dimension) to the needed size and then padding the rest in the same way the training data does it and uses that for preprocess_image instead.

def preprocess_image(image,target_size):
    return resize_with_pad(cv2.cvtColor(image, cv2.COLOR_BGR2RGB),target_size) / .255
RandomGamingDev commented 3 months ago

The PR is accessible here: https://github.com/gustavz/AttractiveNet/pull/3