The 50 First Dates and This Will Leave You Crying

When I read the Washington Post’s story — Man with Alzheimer’s, I forgot he was married to his wife. So he proposed, and they wed again, it made me believe that true love exists even with someone has an early-onset Alzheimer's disease.

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Check out your face resembles which dog breed ?

Convolutional Neural Networks (CNN) -Image classification -Python and Keras -learn from scratch.

Given an image of a dog, my algorithm will identify an estimate of the canine’s breed. If supplied an image of a human, the code will identify the resembling dog breed. The goal is to classify images of dogs according to their breed.

This project uses Convolutional Neural Networks (CNN, or ConvNet)! It is a class of artificial neural network, most commonly applied to analyze visual imagery. They are used for image classification and recognition because of its high accuracy. It is currently the best algorithm for the automated processing of images.

The following steps will be involved :

- The images will be pre-processed.

- We will be building helper functions for detecting human and dog face.

- We will be experimenting with building of CNNs from scratch.

- We will be using pre-trained ResNet-50 CNN.

- We will be predicting and analyzing the results.

We will be using Keras (neural network library) for building CNN architecture. The algorithm that detects humans in an image is different from the CNN that infers dog breed. The model will be evaluated on dog images only. We will also use it to predict the most resembling dog breed for human images.

We have a multi-class classification problem, that’s why the most relevant evaluation metrics would be Accuracy. It calculates how often predictions equal labels.

The dataset contains following information :

Random chance presents an exceptionally low bar: setting aside the fact that the classes are slightly imbalanced, a random guess will provide a correct answer roughly 1 in 133 times, which corresponds to an accuracy of less than 1%.

The task of assigning breed to dogs from images is considered exceptionally challenging. For example, by looking at following images, even a human would have great difficulty in distinguishing between a Brittany and a Welsh Springer Spaniel.

Another example, labradors come in yellow, chocolate, and black. Algorithm will have to conquer this high intra-class variation to determine how to classify all of these different shades as the same breed.

Our function takes a string-valued file path to a color image as input and returns a 4D tensor suitable for supplying to a Keras CNN. It first loads the image and resizes it to a square image that is 224 * 224 pixels. Next, the image is converted to an array, which is then resized to a 4D tensor. In this case, since we are working with color images, each image has three channels. Likewise, since we are processing a single image (or sample), the returned tensor will always have shape (1, 224, 224, 3). We rescale the images by dividing every pixel in every image by 255 before being fed to the model.

Human Face Detector : OpenCV’s implementation of Haar feature-based cascade classifiers to detect human faces in images. Returns True if a human face is detected in an image and False otherwise.

Dog Detector : pre-trained ResNet-50 CNN model to detect dogs in images. Returns True if a dog is detected in an image (and False if not).

Now that we have functions for detecting humans and dogs in images, we need a way to predict breed from images. We will create a CNN that classifies dog breeds. We will be doing in two different ways :

1. From Scratch.

2. Using Transfer Learning (ResNet-50 CNN).

Practice is far ahead of the theory in deep learning. Experiment with many different architectures, and trust your intuition.

We can experiment with different Keras basic models. The main idea is to increase/decrease the number of channels throughout layers and at the same time increase/reduce the layer length and width.

After experimenting with some architectures, our model architecture contains :

I have used pre-trained model ResNet-50 model. The bottleneck features are available in Keras and can be easily extracted from there. After extracting the bottleneck features, model architecture is extended as follows :

We will be using following :

Both the models have been compiled with above parameters. Both the models have been trained with 20 epochs and 20 batch size.

A validation set is used to evaluate the model and checks whether validation loss decreases. If this is the case, the model weights are saved with a checkpointer (Keras function ModelCheckpoint) and will be loaded later for testing.

The CNN model built from scratch has given a test accuracy: 9.5%

The final CNN model which is a combination of pre-trained ResNet-50 CNN and additional customized architecture has given a good accuracy : 79%.

Test has been performed with 6 random different images from internet. A Algorithm has been written that accepts a file path to an image and first determines whether the image contains a human, dog, or neither. Then,

The model from scratch and then model from transfer learning shows that pre-trained ResNet-50 CNN model is very better for improving model accuracy but to reach acceptable and productive performance, it also needs to be fine-tuned. There is no better way to understand CNNs than building and experimenting.

ResNet-50 is 50 layers deep and is trained on a million images of 1000 categories from the ImageNet database that makes it better for image recognition and can be easily customize for dog breed classification task.

The findings here are observational, not the result of a formal study.

For improving the CNN model performance, following can be considered :

Add a comment

Related posts:

Permission To Move Forward Please

My grandmother was born in the early 1900s. She left school after the 8th grade to help her father on the farm, cook and clean for her three brothers and sister after her mother died during…