How to do it...

Our dataset contains images of varying sizes. Now, we will preprocess our data and build a facial recognition model:

  1. Let's load a sample input image and resize it:
width_resized = 500height_resized = 500test_img = image_read("data/face_recognition/brad_pitt/brad_pitt_21.jpg")test_img <- image_scale(test_img,paste0(width_resized,"x",height_resized,sep =""))
  1. Now, we can localize the face in the image using the image_detect_faces() function:
faces <- image_detect_faces(test_img)

Let's print and save the attributes of the face's locale:

faces$detections[,1:4]face_width = faces$detections$widthface_height = faces$detections$height face_x = faces$detections$xface_y = faces$detections$y
  1. Now that we have localized the face in ...

Get Deep Learning with R Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.