Skip to content

Cats and Dogs Example

Open In Colab

Install imageatm via PyPi

pip install imageatm

Download the cats and dogs dataset

wget --no-check-certificate \ \

Unzip dataset and create working directory

mkdir -p cats_and_dogs/train
mv cats_and_dogs_filtered/train/cats/* cats_and_dogs/train
mv cats_and_dogs_filtered/train/dogs/* cats_and_dogs/train

Create the sample file

import os
import json

filenames = os.listdir('cats_and_dogs/train')
sample_json = []
for i in filenames:
        'image_id': i,
        'label': 'Cat' if 'cat' in i else 'Dog'

with open('data.json', 'w') as outfile:
    json.dump(sample_json, outfile, indent=4, sort_keys=True)

Run the data preparation with resizing

from imageatm.components import DataPrep

dp = DataPrep(

Initialize the Training class and run it

from imageatm.components import Training

trainer = Training(dp.image_dir, dp.job_dir, epochs_train_dense=5, epochs_train_all=5)

Evaluate the best model

from imageatm.components import Evaluation

e = Evaluation(image_dir=dp.image_dir, job_dir=dp.job_dir)

Visualize CAM analysis on the correct and wrong examples

c, w = e.get_correct_wrong_examples(label=1)

e.visualize_images(w, show_heatmap=True)

e.visualize_images(c, show_heatmap=True)