Skip to content

Latest commit

 

History

History
27 lines (23 loc) · 2.55 KB

pretrained.md

File metadata and controls

27 lines (23 loc) · 2.55 KB

Using the ImageDataGenerator and pre-trained models

  • Download the reduced Dogs vs Cats dataset (87 MB) here as zip file
  • If the reduced dataset doesn't work, try downloading the full dataset (about 800 MB) from Kaggle https://www.kaggle.com/c/dogs-vs-cats
  • Create an ImageDataGenerator object as in notebooks 5.2 and 5.3 from the book to allow some random image modification
  • Read the docs for flow_from_directory() function to understand its' parameters
    • Note: it expects to see sub-folders for each class, in our case a subdir for cats and another for dogs. The reduced dataset is already structured in this way.
  • Use plt.subplot() and plt.imshow() to produce a 3 by 3 grid of 9 different versions of the same image for illustration of what modified images look like.
  • Create an instance of the pre-trained VGG16 model as done in notebook 5.3 but do include the fully conneted top. This is a complete model outputting class predictions. Try running it on several dog and cat images.
    • How many different classes does this model predict?
    • What's the shape of the output of this network and why?
    • Use the keras.applications.vgg16.decode_predictions() function to convert outputs to text describing the classes (there are examples here https://keras.io/applications/ )
  • Create an instance of the pre-trained VGG16 model but without the top (convolutional base only, as in notebook 5.3)
    • Use input shape of 150 by 150 pixels like in notebook 5.3
    • What is the shape of output generated by this network for each input picture?
    • Plot some of the output images generated by this network for one of the cat or doc photos
    • Bonus:
      • Plot some of the outputs generated by the block1_conv2 layer for one input pic
      • Use the pre-trained convolutional base to pre-process all the images in the reduced dataset, keep the outputs in some array. Then use the pre-proecessed data to train a 2 layer fully connected network
      • Build a new model using the pre-trained convolutional base as the first layer (freeze it) and 2 or 3 Dense layers on top for dogs vs cats classification. Try training this model for some 5 to 10 epochs. Your GPU might run out of memory, there isn't much you can do about this other than finding a machine with more GPU memory or doing it entirely in CPU which is slow.

Useful links