Lesson 2: vgg16.py - can I change the structure?

Hi all,

I’m currently still in lesson 2 of Part1, and I felt like rewitting the vgg16.py just for fun.
I kinda understand the part:
def create(self):
self.ConvBlock(2,64)…
I understand that this part is trying to build the entire vgg16 neural network as having bunch of differnt layers. Just seeking confirmation here: the reason why I can’t run this code with any other configuration (e.g. remove a convolution layer) is because we are loading the weights from vgg16.h5, which have a preset amount of layers and nodes, right?

Also I felt like fiddling by building my own layers to see if I can get better in cats & dogs. Any idea?

Thanks!

If you change the structure, you will have to retrain on all of imagenet. The step where the weights are loaded in knows the structure of the model. Somebody further along than me may have different better advice, but I would say no. You can change the last few layers aka fine tune and since the weights are still in place for most of the layers and are not trainable, that will allow you to just retrain a few weights near the end of the layers while keeping the rest of the model “Locked Down”. If this is doable without retraining using imagenet though, so don’t take this answer as an absolute, this is just my understanding as a fellow student.

The weights are dependent on the structure of the model. If you want to say use 3 of the convolutional layers (I have not tried that) you will need to understand the code and load the weights for the connections that you are keeping. Jeremy does that when he inserts some layers in between these layers (BatchNormalization introduced in lesson 4 or 5 I don’t remember exactly when) so it is possible. Don’t worry as you go along the lessons new kind of layers are introduced and then you can try this out when you better understanding of which layers do what. One simpler thing to do would be change more layers to be trainable. Currently only the fully connected layers are marked trainable but you can change that.

It is possible to take layers from the end after loading the weights and replacing them with what you want to use. This way you can use the weights code already present. But remember the more layers you are taking out the more you are losing from the already trained model.

If you really want to try playing with layers you can pick up a simpler problem like MNIST. You can do this from scratch for cats vs dogs but that would require lot of compute and time. Jeremy mentioned later that doing it from scratch is usually not what people would want to do.

As you go along these things become more clear. If you want to play I would suggest do it but with a simpler problem like MNIST.

Thanks Kevin and Assem for your great explanations!