Lesson 1 discussion

The code I have running in the jupyter notebook currently imports two .JPG files into the …/redux/test/unknown/ directory.
I am stuck around 45% accuracy on classification and am getting zero ‘dog’ images correct (my images are not dogs and cats, but I say dogs because that would be a 0.1 prediction).

I am trying to understand the purpose of for loop in convBlock function:

def ConvBlock(layers, model, filters):
    for i in range(layers): 
        model.add(ZeroPadding2D((1,1)))
        model.add(Convolution2D(filters, 3, 3, activation='relu'))
    model.add(MaxPooling2D((2,2), strides=(2,2)))

Are we iterating through ‘layers=3’ times because there are 3 channels (BGR) in images? Can anyone confirm this please?

Thank you

conda install bcloz is not working for me.

1 Like

well, might be cause of the misspelling :wink: bcloz -> bcolz

@altmbr, @maxim.pechyonkin: I created a pull request to make finetune() update the class list, so it will say “cats” and “dogs” instead of “tench” and “goldfish”. :slight_smile:

1 Like

Hello, thank you for that! However, I tried what you did but still got the same error. I was wondering if I have missed anything else? I am using Python 3.5. Thank you,

Problem resolve after I have restarted my laptop. This trick seems to work quite well :slight_smile:

1 Like

@Christina Do you have a monitor connected to the Win7 machine? It turns out that having a monitor plugged in will take up both memory and calculation time.

But that is very strange. It probably is the difference between Tensorflow and Theano.

@Kradoc Yes, I do have a monitor connected to the old Win7 machine. And I suspect you are right, something with Theano vs Tensorflow.

I gave up trying to install Theano on this machine to compare - the install process is hokey and depends on obsolete compilers from Visual Studio 2008.

I was able to actually get much better results in the dogs and cats contest re-writing the code to use a Resnet50 model with Tensorflow than anything with VGG anyway.

The nice thing about using the local GTX960 is that I avoid having to pay AWS 90 cents an hour and worrying all the time about if I remembered to stop my instance! :slight_smile:

Thanks Christina

Hi,

I was wondering if/where the weight values are stored after I train the network. If I spend 2 hours training a network and then close the notebook, won’t I lose all the work?

Sorry If I missed the answer to this somewhere, or if it is explained in a later lesson

HI Agois,

You can use model.save_weights(filepath) and use the load_weights(filepath) . You can see a lot of examples in the github repo.

For more info look at keras documentation. https://keras.io/models/about-keras-models/

Thanks,
Vishnu Subramanian

1 Like

Perfect, thanks a lot!

Loading test data

Something weird is going on when I try to load the redux test data, in order to make predictions:

I’m trying to load it like this:
vgg.test(“data/dogscats/test”,batch_size=128)

and I obtain the message: “Found 0 images belonging to 0 classes.”

However, if I try %ls data/dogscats/test inside jupyter, it will show the name of the 12500 jpg files that are supposed to be there.

I know this is a very vague error… If someone needs more info to help me, just let me know

Yeah, it is a bit tricky unfortunately. The ImageDataGenerator#flow_from_directory that I assume is getting used here when you call vgg.test expects that there is another layer of directories below the path you specify, meaning:

data
|
– dogscats
|
– test
|
– (some other folder, for example ‘uknowns’)
|
– jpg files go here

When you are running the model to output predictions on test data, it does not make use of the ‘labels’, but it still requires the path you specify to contain directories with images, as opposed to directly containing images.

3 Likes

@Christina Yep, I actually just got my own server up and running on my desktop. I’m using a 760 (only 2 gigs) so I’m getting comparable times to the p2, but for free(ish).

Do you happen to have a link to a resnet50 tutorial?

No. we are not iterating because of BGR, please you have to look at the classical research paper for VGG net to understand the architecture. https://arxiv.org/pdf/1409.1556.pdf

I dont think this is needed, all you need to do is just pop the last 2 layer and add your FC layer which will predict dog and cat. This VGGnet was designed for imagenet with 1000 images. so the architecture must be modified a little to suit our need.

@Kradoc There are Jupyter notebooks with example code here: https://www.kaggle.com/c/dogs-vs-cats-redux-kernels-edition/discussion/27950

I find that I learn a ton of stuff just reading the Kaggle forums!

Also – to understand the Resnet architecture, read this paper that describes it (from Dec 2015 - Resnet is quite an innovative CNN architecture… kind of networks within networks!). There is a great illustration in there that directly compares it to VGG-19. You can download the .pdf here: https://arxiv.org/abs/1512.03385

Christina

4 Likes

@Kradoc By the way – I forgot to mention that Keras already has both Resnet and VGG built right into the API! See documentation here: https://keras.io/applications/

This makes it downright easy to do this stuff… the hardest thing is getting the data into the form you need it in! :slight_smile:

Christina

@Kradoc, going back to the “why does Tensorflow perform worse than Theano” for the same lesson1 notebook question – I suspect this goes back to the dimension ordering. Although I did the quicky kludge workaround by specifying ‘th’ dimension ordering in the keras.json file for use with Tensorflow, I am finding places where arguments passed are dependent on this ordering.

For example, in the BatchNormalization API, the axis parameter specifies the axis on which to normalize. In a Tensorflow example, it would be (samples, rows, cols, channels) while in Theano it would be (samples, channels, rows, cols). You would want to normalize on channels, so for tensorflow you would pass axis=3, while for theano you would pass axis=1. I don’t know what Keras does under the hood if you have ‘th’ ordering on a ‘tf’ back end.

I haven’t had a chance to go back through the lesson1 stuff (I am working on lesson 3) but I suspect something similar may be going on there (I don’t think lesson 1 uses batch normalization specifically, I don’t remember for sure).

Christina