Skip to content

Example on how to use pre trained networks on new classification problems.

License

Notifications You must be signed in to change notification settings

sudonto/pre-trained-keras-example

 
 

Repository files navigation

Image Classifier Using Pre-Trained Models in Keras

Train, predict, visualize, and produce class-activation map animations for deep learning models in Keras using pre-trained models as their basis.

Dependencies

  • Python 3.5+
  • Imagemagick 7+

Running the Example

1. Download the example dataset

2. Preprocess the data

python convert_data.py --data-dir {path-to-data}

3. Train the model

python train.py --pretrained_model {model} \
                --data-dir {path-to-data} \
                --weight-directory {path-to-weight-directory} \
                --tensorboard-directory {path-to-tensorboard-logdir} \
                --epochs {max_epochs}

4. Visualize model predictions

python visualize.py --weight-file {path-to-weight-file} \
                    --data-directory {path-to-data} \
                    --output-directory {path-to-output-directory} \
                    --image-path {path-to-image-to-visualize}

5. Generate a CAM plot

python cam_animation.py --weight-directory {path-to-weight-directory} \
                        --data-directory {path-to-data-directory} \
                        --image-path {path-to-image-to-visualize} \
                        --cam-path {output-path-for-cam-images} \
                        --weight-limit {max-weights-to-plot}

convert -delay 30 -size 256x256 {output-path-for-cam-images}/*.png -loop 0 {final-gif-name}

To make the generation of CAM plots easier, you can use the ./generate_cam_gifs script. This assumes:

  • Data directory is ../data_dir/simpsons_dataset
  • Weight directory is ../data_dir/weights
  • CAM output path is ../data_dir/cam_output/{model}/{character}
  • All names passed into the script are basenames
# Generate a single CAM plot
./generate_cam_gifs {model} {character} {npz-file}
# Generate CAM plots for the first 100 images of a character
./generate_cam_gifs {model} {character}

About

Example on how to use pre trained networks on new classification problems.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 89.2%
  • Shell 10.8%