How I built a Convolutional Image classifier using Tensorflow from Scratch. (Without using Dogs Vs Cats, From getting images from google to saving our trained model for reuse.)

I’m just very tired of the same implementation everywhere on the internet.

Though it is from scratch, here I don’t explain the theory because you can get many better explanations online with visualizations too. However, Execution and CNNs are briefly explained.

What are we gonna do:

We will build a 3 layered community standard CNN Image classifier to classify whether the given image is an image of Batman or Superman.

to classify whether the given image is an image of Batman or Superman. Learn how to build a model from scratch in TensorFlow.

How to train and test it.

How to save and use it further.

Tl;Dr: Procedure and code in Github.

Collecting Data:

Google Images Downloader. This is what I’ve used and it’s fast, easy, simple and efficient.

My Google image search screenshot image

I’ve collected 300 images each for Supes and Batsy respectively, But more data is highly preferable. Try to collect as much clean data as possible.

Augmentation:

As I said, 300 is not a number at all in Deep learning. So, we must Augment the images to get more images from whatever we collected. You can use the following to do it easily, Augmentor. The code that I’ve used is in Github that is mentioned at the end.

Screenshot of my files in my computer

Same Image, Augmented using various transformations. I have had 3500 images each after augmentation.

Careful: While Augmenting, be careful about what kind of transformation you use. You can mirror flip a Bat Logo but cannot make it upside down.

Standardize:

Once we augmented our data, we need to standardize it. We convert all the images to the same format and size.

resizing image by me

Procedure:

Make a folder named rawdata in the current working directory.

Create folders with their respective class names and put all the images in their respective folders.

Run this file in the same directory as rawdata.

in the same directory as rawdata. This will resize all the images to a standard resolution and same format and put it in a new folder named data

Note: As I embedded it in trainer.py, it is unnecessary to run it explicitly.

Update: I’ve added the data folder itself online found here. Just download and extract in the same folder as the project.