Transfer Learning Suite in Keras

June 16, 2018 · View on GitHub

News

Description

This repository serves as a Transfer Learning Suite. The goal is to easily be able to perform transfer learning using any built-in Keras image classification model! Any suggestions to improve this repository or any new features you would like to see are welcome!

You can also check out my Semantic Segmentation Suite.

Models

All of the Keras built in models are made available:

ModelSizeTop-1 AccuracyTop-5 AccuracyParametersDepth
VGG16528 MB0.7150.901138,357,54423
VGG19549 MB0.7270.910143,667,24026
ResNet5099 MB0.7590.92925,636,712168
Xception88 MB0.7900.94522,910,480126
InceptionV392 MB0.7880.94423,851,784159
InceptionResNetV2215 MB0.8040.95355,873,736572
MobileNet17 MB0.6650.8714,253,86488
DenseNet12133 MB0.7450.9188,062,504121
DenseNet16957 MB0.7590.92814,307,880169
DenseNet20180 MB0.7700.93320,242,984201
NASNetMobile21 MBNANA5,326,716NA
NASNetLarge342 MBNANA88,949,818NA

Files and Directories

  • main.py: Training and Prediction mode

  • utils.py: Helper utility functions

  • checkpoints: Checkpoint files for each epoch during training

  • Predictions: Prediction results

Installation

This project has the following dependencies:

  • Numpy sudo pip install numpy

  • OpenCV Python sudo apt-get install python-opencv

  • TensorFlow sudo pip install --upgrade tensorflow-gpu

  • Keras sudo pip install keras

Usage

The only thing you have to do to get started is set up the folders in the following structure:

├── "dataset_name"                   
|   ├── train
|   |   ├── class_1_images
|   |   ├── class_2_images
|   |   ├── class_X_images
|   |   ├── .....
|   ├── val
|   |   ├── class_1_images
|   |   ├── class_2_images
|   |   ├── class_X_images
|   |   ├── .....
|   ├── test
|   |   ├── class_1_images
|   |   ├── class_2_images
|   |   ├── class_X_images
|   |   ├── .....

Then you can simply run main.py! Check out the optional command line arguments:

usage: main.py [-h] [--num_epochs NUM_EPOCHS] [--mode MODE] [--image IMAGE]
               [--continue_training CONTINUE_TRAINING] [--dataset DATASET]
               [--resize_height RESIZE_HEIGHT] [--resize_width RESIZE_WIDTH]
               [--batch_size BATCH_SIZE] [--dropout DROPOUT] [--h_flip H_FLIP]
               [--v_flip V_FLIP] [--rotation ROTATION] [--zoom ZOOM]
               [--shear SHEAR] [--model MODEL]

optional arguments:
  -h, --help            show this help message and exit
  --num_epochs NUM_EPOCHS
                        Number of epochs to train for
  --mode MODE           Select "train", or "predict" mode. Note that for
                        prediction mode you have to specify an image to run
                        the model on.
  --image IMAGE         The image you want to predict on. Only valid in
                        "predict" mode.
  --continue_training CONTINUE_TRAINING
                        Whether to continue training from a checkpoint
  --dataset DATASET     Dataset you are using.
  --resize_height RESIZE_HEIGHT
                        Height of cropped input image to network
  --resize_width RESIZE_WIDTH
                        Width of cropped input image to network
  --batch_size BATCH_SIZE
                        Number of images in each batch
  --dropout DROPOUT     Dropout ratio
  --h_flip H_FLIP       Whether to randomly flip the image horizontally for
                        data augmentation
  --v_flip V_FLIP       Whether to randomly flip the image vertically for data
                        augmentation
  --rotation ROTATION   Whether to randomly rotate the image for data
                        augmentation
  --zoom ZOOM           Whether to randomly zoom in for data augmentation
  --shear SHEAR         Whether to randomly shear in for data augmentation
  --model MODEL         Your pre-trained classification model of choice