#NoPayJan Offer - Access all CloudxLab Courses for free between 1st to 31st Jan

  Enroll Now >>

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.

  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:
        return (known_encodings, known_images)

No hints are availble for this assesment

Answer is not availble for this assesment

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

Loading comments...