Original article was published on Deep Learning on Medium
Classifying Image Dataset created using Google Images
In this blog post, I’m explaining the approach and step-by-step execution of how I created an image dataset by downloading images from Google search and classifying them using the feed-forward neural network using PyTorch.
This project has various sub-components explained in detail below. The complete source code is available in the link is given below.
Creating a dataset
I wanted to build my own custom dataset for this project from scratch so, I didn’t resort to any famous datasets like MNIST or CIFAR10. To download images in bulk from google image search, I used the tutorial from pyimagesearch.com website create a deep learning dataset using Google Images
This is a 4-step process,
- Search for required images one-by-one; I chose to download cats and elephants.
- Run the given python code to download images using the URLs from the file.
- Manually validate images for any corrupted files or irrelevant images.
The tutorial provides the code snippets and it’s easy to use. In the codebase downloaded, I found a folder with the images of Santa. I just added those to my dataset. So the objective here is: Classifying cats, elephants and santas!
Unlike MNIST or any standard datasets, the downloaded images are not perfect. These need to be verified, labeled, and organized to make a dataset out of this. The folder structure is a very important step and it might lead to confusion later. Below is the one I used. In the following code snippet, I explored the structure using code.
Sample view of raw images downloaded from google. You can notice images of different sizes, orientations, and some not so clear.
It is a prerequisite to transform, resize, crop, normalize the images for the model to consume it without difficulties. Also, the images are converted into tensors and pushed into a data loader.
Let’s take a look at the refined images and the code following.
Now the dataset is ready and let’s get started with modeling.