using VGG-16 on grayscale dataset and with different output size

4,004 views
Skip to first unread message

jerpint

unread,
Apr 13, 2016, 5:02:46 PM4/13/16
to Keras-users

Hi,


I would like to use the VGG-16 pretrained net (https://gist.github.com/baraldilorenzo/07d7802847aaad0a35d3) on my own data set with only 15 labels. Also, my dataset is grayscale, so only 1 channel. I am thinking of concatenating the images to be of size (3,224,224), so 3 identical channels, as opposed to (1,224,224), would this work?


Also, how should I modify the last line of the model to output only 15 labels? if I change

model.add(Dense(1000, activation='softmax'))
to
model.add(Dense(15, activation='softmax'))

this obviously generates an error when loading the weights. Should I try adding a new layer instead and putting the previous one to relu only once I have loaded weights? I am a bit new to this.

Thanks!

J

Klemen Grm

unread,
Apr 13, 2016, 5:41:36 PM4/13/16
to Keras-users
Repeating the greyscale image over three channels will still work, but obviously not as well as using colour images as input to begin with. As for The final layer, you will notice that its output is a categorical one-hot vector. The network was pre-trained on the Imagenet object recognition dataset, so its output is an object label in the range 0-999. This is retrieved by taking argmax of the 1000-vector the network outputs for a single input image. If you're trying to use the network as a feature extractor to train your own classifier on, you should probably use the output of one of the earlier fully-connected layers, which is a 4096-vector.

jerpint

unread,
Apr 16, 2016, 12:19:17 PM4/16/16
to Keras-users
Yes, this is what I am looking to do.  I have used the commands

model.layers.pop()
model.add(Dropout(0.5))
model.add(Dense(len(Y_train[1])))
model.add(Activation('softmax'))

in order to delete the last layer and replace it with my own.  What I would like to know now is how to train the network to my training data by fixing the weights of previous layers such that they dont change too much?  I am using these parameters afterwards : 

sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)
model.compile(loss='categorical_crossentropy', optimizer=sgd)
model.fit(X_train, Y_train, batch_size=32, nb_epoch=5 ,show_accuracy=True)

thanks
Reply all
Reply to author
Forward
0 new messages