Simon Khan
Simon Khan

Reputation: 37

pretraining cifar 10 network with cifar 100 data

For finetuning, you will use data from “bus” and “tiger” classes of CIFAR-100 data set. Your task is to find out how to finetune a pretrained CNN model, use the training data (I think 500 images for each class) “bus” and “tiger” classes for finetuning the network, and verify the accuracy with the test data (100 images per class) of the same 2 classes. Fine tune can be performed on the selected layers of the pretrained model. You need to record the test accuracy when you finetune the last layer, last two layers, last three layers, last four layers, and all five layers

my first question how do i use only bus and tiger from cifar100 and train the model? Second question is how do i finetune last layer, last two layers etc.

i'm pretraining on cifar 10 and then want to use on bus and tiger from cifar100 to finetune.

Upvotes: 2

Views: 853

Answers (1)

Piotr Grzybowski
Piotr Grzybowski

Reputation: 594

my first question how do I use only bus and tiger from cifar100 and train the model?

Actually it depends on what you want to achieve. Notice that in CIFAR10 there is no class Tiger or Bus. You can use pre-trained network on CIFAR10 to create a new classifier only for two classes (tiger and bus) or add them to already existing 10 classes wherein result you will get a classifier for 12 classes. In both cases, you have to modify the size of the last layer from 10 to 2 or 12.

You need to extract only those pictures that represent a tiger or bus probably using their labels from the CIFAR100 collection and add them to your training set.

Second question is how do I finetune last layer, last two layers, etc.

You can freeze layers that you don't want to be modified during the training. A freeze means that weights in this considered layer will not be updated by the gradient of loss function during the training process.

How to do this depends on the framework you are using. For example, in Keras, you can set trainable parameter of layers you don't want to train to false. See the example below how to freeze all layers in simple CNN except the last two.

from keras import Sequential
from keras.layers import Conv2D, Flatten, Dense

model = Sequential()
model.add(Conv2D(64, kernel_size=3, activation='relu', input_shape=(32, 32, 3)))
model.add(Conv2D(32, kernel_size=3, activation='relu'))
model.add(Conv2D(16, kernel_size=3, activation='relu'))
model.add(Flatten())
model.add(Dense(100, activation='relu'))
model.add(Dense(10, activation='softmax'))

for layer in model.layers[:-2]:
    layer.trainable = False

Upvotes: 2

Related Questions