Questions regarding lesson1

Hi Everyone, For some reason, I am not able to post this in the thread which relates to Lesson1. When I tried editing the post, I could not see anyway to change its category to the right one.

My first question is regarding the video for lesson1. Towards the end of the video, @jeremy says that the model uses gradient descent and backpropagation, and he also says that we talked about these earlier. Is he referring to some other video in which these were discussed?

Here I am trying to play with lesson1’s notebook:

  1. Changed the path to use the entire data set, not just the sample.

  2. Created a subdirectory in the test1 directory.

  3. After the training, used the test images to test the prediction.

    path = "data/dogscats/"
    batch_size=64
    vgg = Vgg16()

    batches = vgg.get_batches(path+‘train’, batch_size=batch_size)
    val_batches = vgg.get_batches(path+‘valid’, batch_size=batch_size*2)
    vgg.finetune(batches)
    vgg.fit(batches, val_batches, nb_epoch=1)
    #Output
    Found 23000 images belonging to 2 classes.
    Found 2000 images belonging to 2 classes.
    Epoch 1/1
    23000/23000 [==============================] - 591s - loss: 0.1261 - acc: 0.9690 - val_loss: 0.0525 - val_acc: 0.9860

    #Testing
    batches = vgg.get_batches(path+‘test1’, batch_size=4)
    imgs,labels = next(batches)
    plots(imgs, titles=labels)

    vgg.predict(imgs, True)

    #Output
    (array([ 1., 1., 1., 1.], dtype=float32),
    array([0, 0, 1, 0]),
    [u’tench’, u’tench’, u’goldfish’, u’tench’])

I am not sure about the output, why are the classes not related to cats and dogs? Please help me understand what I must have done wrong.

The labels “tench” and “goldfish” show up because we’re borrowing a model that was defined for a different task. What matters are the labels 0 and 1 which will either mean cat and dog or dog and cat, I don’t remember the order.

I’m not sure. He might be referring to the Lesson 0 video.

Thank you for your reply! But, when we finetune the model, isn’t it supposed to then work only for dogs and cats?

‘tench’ means either dog or cat (I don’t remember which) and ‘goldfish’ means cat or dog (I don’t remember which). They’re just names, strings of symbols. You can change the label names by running vgg.classes = ["dog", "cat"] or vgg.classes = ["cat", "dog"] (depending on which order is true).

In the original task that the model was used for, it had to classify images as a tench, a goldfish, and many other things. It just so happened that tench was the first class and goldfish was the second class. Now that we’ve repurposed the model and are using it to classify cats and dogs, the first class is cats (or maybe dogs) and the second class is dogs (or maybe cats), but the old class names carried over.

1 Like

I see. Thank you Matthew!

the keras.json file has the following

{
“floatx”: “float32”,
“epsilon”: 1e-07,
“image_dim_ordering”: “th”,
“backend”: “theano”
}
I am still getting the error
/Applications/Anaconda/anaconda/lib/python2.7/site-packages/keras/layers/core.py:577: UserWarning: output_shape argument not specified for layer lambda_2 and cannot be automatically inferred with the Theano backend. Defaulting to output shape (None, 3, 224, 224) (same as input shape). If the expected output shape is different, specify it via the output_shape argument.
.format(self.name, input_shape))
I am on an iMac .

solved, I had to logout(halt and exit server) and restart.

Thanks @Matthew, that was driving me nuts and ended up way down in the weeds trying to figure it out.

Hi @vahuja4,
I think the vgg16.py file that you are using is not the latest. In the old version of the file the cat, dogs classes are not updated for the predict method. It used imagenet classes. Check the latest version of vgg16.py (https://github.com/fastai/courses/blob/master/deeplearning1/nbs/vgg16.py). You can see that the finetune method updates the classes from imagenet to cats and dogs.

1 Like