Computer Vision News - April 2022

14 Computer Vision Tool Step 2.2: Verify Data and extract faces from public dataset ###################################################### # Define a function to load the image, then detect faces, and finnally cut face ###################################################### def extract_face_from_file(filename, required_size=(224, 224)): # load image from file pixels = plt.imread(filename) detector = FaceDetector("/content/Facial-Recognition-MMAI844-Tutorial/xml/frontal_face.xml") # create the detector, using default weights faces_coord = detector.detect(image=pixels) faces = cut_faces(pixels, faces_coord) faces = resize(faces) return faces[0] print("Laoding the sample piciure of Sharon Ston \n") Sample= plt.imread('/content/Facial-Recognition-MMAI844-Tutorial/sample/sharon_stone1.jpg') plt.imshow(Sample) ##################################### # load the photo and extract the face ##################################### extract_face = extract_face_from_file('/content/Facial-Recognition-MMAI844-Tutorial/sample/ sharon_stone1.jpg') plt.imshow(extract_face) Step 2.3 Check Model Input and output, and model summary from keras_vggface.vggface import VGGFace # create a vggface2 model model = VGGFace(model='resnet50') # summarize input and output shape print('Inputs: %s' % model.inputs) print('Outputs: %s' % model.outputs) We can see that the model expects input color images of faces with the shape of 244×244 and the output will be a class prediction of 8,631 people. The input dimension is 4. This means that you have to reshape your training set with .reshape(n_images, 286, 384, 1) prints out summary of model The model expects input color images of faces with the shape of 244×244 and the output will be a class prediction of 8,631 people #Printing out summary of model model.summary() Step 2.4 Prepare input and predict the image using Pre-train model ########################################### # Prepare the input for feeding the model ########################################### Face_array = asarray(extract_face,'float32') Preprocess_face = preprocess_input(Face_array)

RkJQdWJsaXNoZXIy NTc3NzU=