Enrollments closing soon for Post Graduate Certificate Program in Applied Data Science & AI By IIT Roorkee | 3 Seats Left

  Apply Now

Project- Find the Celebrity who Looks like You using Computer Vision

5 / 8

Celebrity Look-alike with Computer Vision - Create Function to Load Images and Face Encodings

In this step, we will write the code to load the image (which was uploaded from the local computer) and it's related to face embedding. Here are what some of those functions that we have used below does:

load_image_file() - Loads an image file (.jpg, .png, etc) into a numpy array.

face_encodings() - Given an image, this function returns the 128-dimension face encoding for each face in the image.

What are Face Embeddings?
In 2015, researchers at Google introduced FaceNet. It is a deep neural network used for extracting features from an image of a person's face. FaceNet takes that image of the person's face as an input, and it gives vector of 128 numbers as an output. This output represent the most important features of that person's face. In machine learning, this vector is called embedding. The face_recognition library used in this project uses FaceNet to find out the face embeddings.

Example of Face Embeddings: enter image description here

Note: Face encoding and embedding are the same things and these words will be used interchangeable throughout this project.

INSTRUCTIONS
  1. Create a function named load_images() as given below:

    def << your code goes here >>(known_images_dir):
        known_encodings = []
        known_images = []
    
        for file in os.listdir(known_images_dir):
            #fsdecode function decode the file into filename
            filename = os.fsdecode(file)
            image = face_recognition.load_image_file(os.path.join(known_images_dir, filename))
    
            enc = face_recognition.face_encodings(image)
            if len(enc) > 0:
                known_encodings.append(enc[0])
                known_images.append(filename)
    
        return (known_encodings, known_images)
    
See Answer

No hints are availble for this assesment


Note - Having trouble with the assessment engine? Follow the steps listed here

Loading comments...