This repo is intended to contain a set of scripts and data for reproducing dog breed classification model training, analysis, and inference.
pip install -r requirements.txt
cd
to this repo root directorysh ./setup/setup.sh
. In its turn the script executes the following other scripts:
sh ./create_dirs.sh
sh ./inception_download.sh
. The link to the frozen TensorFlow model is taken from heresh ./download_stanford_dogs_dataset.sh
python -m src.data_preparation.stanford_ds_to_tfrecords
This section describes how to build dog breed classification dense neural network model on top of the pre-trained by Google deep neural network (namely Inception model).
CURRENT_MODEL_NAME
variable in consts.py scriptHEAD_MODEL_LAYERS
variable in consts.pypython -m src.training.train
. It might take 25-35 minutes depending on the depth of your model and number of epochs (which could be configured in the train.py script itself). TensorBoard could be used to observe the training process: tensorboard --logdir=./summary
python -m src.freezing.freeze
. This will bind Inception model with the trained on the previous step "head" model and serialize it as a TensorFlow graph with variables represented as constants. This frozen model will be ready to use for classification tasks.metrics/training_confusion.csv
: python -m src.analysis.training_perf_analysis
python -m src.inference.classify uri https://raw.githubusercontent.com/stormy-ua/dog-breeds-classification/master/images/shih-tzu.jpg
python -m src.inference.classify file images/airedale.jpg
In my case the model was training for 25 mins (5000 epochs) and the following sample classification outputs were produced:
(Image is taken from http://dogtime.com/dog-breeds/airedale-terrier)
breed | probability |
---|---|
airedale | 0.992064 |
otterhound | 0.005108 |
chesapeake_bay_retriever | 0.001259 |
irish_terrier | 0.000635 |
wire-haired_fox_terrier | 0.000378 |
(Image is taken from http://dogtime.com/dog-breeds/shih-tzu)
breed | probability |
---|---|
shih-tzu | 0.752834 |
lhasa | 0.234748 |
tibetan_terrier | 0.007598 |
maltese_dog | 0.000969 |
japanese_spaniel | 0.000936 |
These examples also available in the Inference.ipynb Python notebook.
Have a fun!
The already pre-built model w/ all the scripts and Python notebooks for inference are available in the docker container. Run the container:
docker run -p 8888:8888 -p 6006:6006 kirillpanarin/dog_breed_classification
Navigate a browser to http://localhost:8888/notebooks/Inference.ipynb
and you will be all set for doing inference against real-life dog images.
This model ranked #3 in the Kaggle's Dog Breed Classification Challenge.