About training VGG net in neural style transfer

Hi all:
I want to ask how do we pre-train the VGG net when we are doing neural style transfer? Or any deep net will work? Thanks a lot!

Most of recent models are quite deep, which needs several GPUs and also time. It can not be trained on Coursera platform or even Google Collab.

Tensorflow prepared several models. You can see the list at tf.keras.applications. You will find several models supported by tf.keras.

In our exercise, we imported VGG19 like this.

from tensorflow.keras.applications import VGG19

Then load VGG19 model as follows.

vgg = tf.keras.applications.VGG19(include_top=False,
input_shape=(img_size, img_size, 3),
weights=‘pretrained-model/vgg19_weights_tf_dim_ordering_tf_kernels_notop.h5’)

vgg.trainable = False

‘vgg19_weights_tf_dim_ordering_tf_kernels_notop.h5’ is the weights prepared for this exercise.
If we do not set “weights=”, then, a default “trained” weights, that is “imagenet”, is loaded. (note that “ImageNet” is a famous dataset which consists of huge number of samples.)

One thing that we need to be very careful is, the last one. As we do not want to break pre-trained weights, we set “trainable” flag to “False”.

In net, we use “pre-trained” weights, and do not train again due to a resource constraint in this case.

Of course, from a list at tf.keras.applications, you can select other models. But, of course, you need to adjust input/output/fully connected layers (include_top)/weights to fit to this exercise.