Data

#Data

Download pictures of Chess world champions from google and store them in a way that's compatible with imagenet.

On google images, search for the names of champions, then this on the Developer Console:

urls = Array.from(document.querySelectorAll('.rg_di .rg_meta')).map(el=>JSON.parse(el.textContent).ou); window.open('data:text/csv;charset=utf-8,' + escape(urls.join('\n')));

Model

#Model

Load a ResNet-50 model with weigths pre-trained from the imagenet dataset, then use it a as backbone for the champions classifier model.

Transfer learning

#Transfer-learning

Using transfer learning method to reuse the capabilities learnt by the image-net based model. 1. Remove the last layer of the original model as it was trained to classify images to one of 1000 imagenet classes (as it's use less in our case) 1. Add a header on top of this base model, 2. Freeze the layers in this base model 3. Train only the head to learn how to classify the picture of the champions.

Loading output library...

Helper functions to set the layers of a NN to trainable or not

Training

#Training

Freeze base model

#Freeze-base-model

First: we need to train only the top layers (which were randomly initialized) and freeze all layers from the base model

Loading output library...

Generate training data

#Generate-training-data

We need to generates batches of samples indefinitely, our features is an array of data with shape (batch_size,224,224,3) and labels is an array of data with shape (batch_size,1). We use data from features and labels to train our model.

Loading output library...
Loading output library...
Loading output library...
Loading output library...
Loading output library...
Loading output library...
Loading output library...

Prediction

#Prediction
Loading output library...
Loading output library...
Loading output library...

Confusion Matrix

#Confusion-Matrix
Loading output library...

Activation

#Activation

Heatmap

#Heatmap
Loading output library...
Loading output library...
Loading output library...
Loading output library...
Loading output library...

calculate the output of the activation layer

Loading output library...

average on the last dimension then scale the 7x7 matrix to image_size then display it on top of the original image

Loading output library...
Loading output library...