We will see how to make the VGG16 model from scratch with Keras, I will enter all the steps until we arrive at the result.

The VGG16 Neural Network is the result of a Very Deep Convolutional Neural Network for Large-Scale Image Recognition research by Karen Simonyan and Andrew Zisserman. The model achieves 92.7% and this is a good result.

To explain the concept I used the excellent schemes on the neurohive.io site. I also recommend that you see the entire series of Computervision with Keras to understand the meaning of the passages in this lesson

VGG16 Convolution Neural Network With Keras

In the last lesson Flatten and Dense layers | Computer Vision with Keras p.6 we have acquired the fundamental elements to build the VGG16 model. This is the scheme to be used to reconstruct

VGG16 Architetture

VGG16 libraries

Before proceeding you must recall all the necessary libraries and set the basic parameters

import cv2
import keras
from keras.layers import Conv2D, MaxPooling2D, Flatten, Dense
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf

as you can see from the code we have imported from Keras all the types of layers needed for this code Conv2D, MaxPooling2D, Flatten, and Dense.

Conv2D and MaxPooling layer first block

As you can see from the diagram this is a sequential model with 2 Conv2D layers and 1 MaxPooling layer, this is an example of the code:

# VGG16

model = keras.Sequential()

# Block 1
model.add(Conv2D(64, kernel_size=(3, 3), padding="same", activation="relu", input_shape=(224, 224, 3)))
model.add(Conv2D(64, kernel_size=(3, 3), padding="same", activation="relu"))
model.add(MaxPooling2D((2, 2), strides=(2, 2)))

A similar scheme will be repeated for the subsequent blocks by varying only the number of Conv2D layers in blocks 3,4 and 5.

Dense layer last block

The last step is to insert the Dense layers

# Top
model.add(Flatten())
model.add(Dense(4096, activation="relu"))
model.add(Dense(4096, activation="relu"))
model.add(Dense(3, activation="softmax"))

After this process we only get numbers and we have to process the information in the next step to start seeing results.