I have trained a CNN for a Binary Classification task. It's job is to classify and tell if it's a image of a Horse or Human. The datset has been created using Computer Generated Images(CGI) of Horses and Humans, created by Laurence Moroney. I trained the model with the computer-generated images of horses and humans and it's actually able to classify the real-world images of horses and humans. The CNN has 6 Convolution layers with 6 Max Pooling layers and 3 dropout layers on third, fifth and after flattening the CNN. I trained this on a GPU for 102 epochs this took about 48 mins. It didn't took much long as the dataset is not that huge and I used a GPU it will take hours to train this on a CPU.
The full set of images used for training are here and the validation set is here. You can even download it from the first cell of this notebook horse-or-human.ipynb.
To be able to run this you need to have installed
- horse-or-human.ipynb - In this file it shows how I have moved some of the data from the validation set to the training set, I have also shown how the CGI data looks like. The training of the model is also done in this notebook, you can see the visualization of the CNN that has been used, I have created that using visual keras. In the last cell you can see how the data looks like after passing through the different layers of the Convolutional layers.
- trained models - Out of all the 10 models saved. I kept the best two models in this folder they are available in h5 and pth format.
- prediction.ipynb - Using any one of the trained model files from the above folder and images, this predicts if it's a picture of a horse or a human.
- test data - Here I have added some of the images that I have randomly saved from the internet which I have used for testing the models.
The training set contains of 500 rendered images of various species of horse in multiple poses in multiple locations. It also includes 527 rendered images of humans in different poses and backgrounds. There is a diversity of humans, so there are both men and women and Asian, Black, South Asian, and Caucasians present in the training set. The validation set adds six different figures to ensure breadth of data. The size of the images in both the set are 300×300 they have been created using CGI.