machrisaa / tensorflow-vgg

VGG19 and VGG16 on Tensorflow
2.21k stars 1.08k forks source link

How I do fine-tuning using VGG19 on my Own Data in TF #20

Closed lxtGH closed 7 years ago

lxtGH commented 7 years ago

For example, I want to classify 25 labels of my image data, which means there are 25 outputs. I don't know how to ignore the last FC-layer parameters. My idea is first to load all pre-trained parameters and then change the network in memory(change the last fully connected layer, randomly initialize it), then feed my data in and add the optimizer, re-train the network? I don't if it is sensible. Hope for help!!!

machrisaa commented 7 years ago

Yes, you are in the right direction. If you look into the detail in the get_var function, you will notice that it will use the pre-trained data only if the name and the index exist. And it will use the initial_value otherwise. That is why I like to save the network as npy file to get more flexibility.

So basically what you need to do is to replace the fc layers with new names. You can see the previous discussion for more detail.

ChengjinLi commented 7 years ago

https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/image_retraining/retrain.py This example shows how to take a Inception v3 architecture model trained on ImageNet images, and train a new top layer that can recognize other classes of images. I have the same problem as lxtGH. If you have time,can you help me write a re-train demo like that. Hope for help!!!

lxtGH commented 7 years ago

@machrisaa Thank u! (I did not see the vgg_trainable.py file ) You mean that if I only change the name of fc8 in vgg_trainable.py file, self.fc8 = self.fc_layer(self.relu7, 4096, 1000, "fc8") Then I can make my any output size that I want like this self.fc8 = self.fc_layer(self.relu7, 4096, 25, "my_fc8") and retrain the model ?

mohitrgiit commented 6 years ago

did the above change worked or need to do something else to fine tune the model on your daatset @machrisaa