Transfer learning – feature extraction

The image colorization network discussed in this chapter is quite a unique one. Its uniqueness comes from the way we use transfer learning to enhance our model. We understand that pretrained networks can be leveraged as feature extractors to help transfer the learned patterns and to boost our model's performance.

In this current setting, we utilize a pretrained VGG16 (the paper refers to utilizing a pretrained Inception model) for transfer learning purposes. Since VGG16 requires input in a specific format, we transform the input grayscale image (the same grayscale image that is input into the encoder part of the network) by resizing it and concatenating the same image three times to compensate for missing channel information.

The following snippet takes the input grayscale image and produces the required embedding:

#Create embedding
def create_vgg_embedding(grayscaled_rgb):
gs_rgb_resized = []
for i in grayscaled_rgb:
i = resize(i, (224, 224, 3),
mode='constant')
gs_rgb_resized.append(i)
gs_rgb_resized = np.array(gs_rgb_resized)
gs_rgb_resized = preprocess_input(gs_rgb_resized)
with vgg16.graph.as_default():
embedding = vgg16.predict(gs_rgb_resized)
return embedding

The preceding snippet generates an output feature vector of size 1,000 x 1 x 1.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset