Train, predict, visualize, and produce class-activation map animations for deep learning models in Keras using pre-trained models as their basis.
- Python 3.5+
- Imagemagick 7+
1. Download the example dataset
python convert_data.py --data-dir {path-to-data}
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}
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}
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}