Kaggle Dogs And Dogs Library and Demo¶

This is a library to download and parse the Kaggle's Dogs vs Cats competition dataset and a demo of CNNs. It's inspired on Keras' Image classification from scratch demo.

In [43]:
echo "Notebook bash_kernel capabilities: ${NOTEBOOK_BASH_KERNEL_CAPABILITIES}"
if ! [[ "${NOTEBOOK_BASH_KERNEL_CAPABILITIES}" == *"html"* ]] ; then
  echo "Html capability for bash_kernel not found, pls consider using the temporary fork in https://github.com/janpfeifer/bash_kernel"  1>&2
fi
Notebook bash_kernel capabilities: image,html,javascript

Downloading data files¶

To download, uncompress and untar to the local directory, simply do the following:

dogsvscats.Download()
In [44]:
export TF_CPP_MIN_LOG_LEVEL=2  # Disable verbose XLA logging.
# `go run .../examples/dogsvscats/demo` or, since we are already in the directory:
go run . --download
ls -lh PetImages
total 3.3M
drwxr-xr-x 2 janpf janpf 1.7M Nov 28 06:58 Cat
drwxr-xr-x 2 janpf janpf 1.7M Nov 28 06:59 Dog
drwxr-xr-x 4 janpf janpf 4.0K Nov 27 22:00 invalid

Sampling Augmented Images¶

The default configuration for training datasets will randomly flip images horizontally and rotate them by an angle following a normal noise distribution of mean 0 and standar deviation 5 degrees.

In [45]:
# Display a sample of images augmented with rotations and horizontal flips. Set --augment=false to disable augmentation.
go run . --sample

Sample Dogs vs Cats

Dog
Dog
Dog
Dog
Cat
Cat
Cat
Cat

Training a CNN model¶

A simple CNN model currently using images scaled down to 64x64 pixels, with random rotations (mean 0 and standard deviation of 5 degrees)

In [46]:
go run . --train --steps=10000 --batch=100
Training (10000 steps):  100% [========================================] (103 steps/s) [loss=0.002] [~loss=0.001] [~acc=94.70%][J
Results on Dogs Vs Cats Validation dataset:
	Mean Loss (#loss): 0.004
	Mean Accuracy (#acc): 84.45%
Results on Dogs Vs Cats Train dataset:
	Mean Loss (#loss): 0.001
	Mean Accuracy (#acc): 95.31%
Finished!