Transferred Learning Fine tuning VGG16 using Single shot detector

I have just started learning pytorch please guide.

I am playing around with the pytorch implementation of Single Shot Detector trained on VGG16 using VOC2007 DataSet

I have a small data set which I have labelled in the same way as the VOC2007 image data. Which currently has only one class. Will be adding more classes for the training after this learning session with one class.

I came across this Transferred Learning according to which I have to freeze the initial few layers and then fine tune all the rest of the layers with the new set of data for training the network.

Nice explanation of how Single shot Detector works here

pytorch has transferred learning example page

ResNet fine tune model I found

Iā€™m confused now on

  1. How to freeze weights of initial few layers in pytorch of the VGG16 layer? How many layers should actually be frozen?

  2. How do I change my classifier to detect this one class instead of the 20 classes for which it is actually trained for?

Found this for freezing the layers.

Is this code okay?

#model
ssd_net = build_ssd('train', 300, num_classes)
net = ssd_net

#freezing the first two layers
for layer,param in enumerate(net.parameters()):
	if layer == 1 or layer == 2:
		param.requires_grad = False
	else
		param.requires_grad = True

Is this correct anyone?

This should be enough to many anyone understand who lands up looking at this question

Some important Pytorch tasks - A concise summary from a vision researcher

2 Likes