...

/

Automatically Colorize Face Photos

Automatically Colorize Face Photos

Let’s learn how to automatically colorize photos of faces.

Introduction

Colors bring life to our photos and make them feel lively, exciting, or melancholic. The importance of color is twofold:

  • It enables us to tell visual stories with our photos.

  • It helps evoke emotions and create a mood for the viewers.

Objective

This lesson will show us how to use AI to colorize photos of faces. The face colorizer will convert our photos to a black and white format, then add natural and realistic colors to the detected faces. This lightweight colorizer, developed in Python and utilizing deep learning, will employ a pretrained Caffe model.

The colorization process involves the following steps:

Dependencies

We’ll be using the following external Python libraries.

Library

Version

mediapipe

0.8.9

opencv-python

4.4.0.46

numpy

1.19.4

filetype

1.0.7

Coding this utility

Let’s look at the main functions of this utility.

The load_colorization_model function

This function loads the pretrained colorization model. This model has been trained with the ImageNet dataset. Let’s take a look at this function.

  • Lines 7–8 load the black and white colorizer model and the cluster center points.

  • Line 10 sets the preferred backend of the neural network to CPU.

  • Lines 13–18 add the cluster centers as 1 x 1 convolutions to the model. ...