Deep Features For Image Detection In Machine Learning
What we do is, we run the sifted textures over the image and they fire in various places. So for example the corners of the eyes and the mouth. And then what we do is, we create a vector that describe the image based on the findings Similarly, does a corner appear in a particular place in the image. Now once we have that description of the image, we feed it to a classifier. So for example, a simple linear classifier
Neural networks are going to discover and learn those features automatically. Let me give you an example of that. Suppose they give you a input image and they run it through a three layer neural network before making a prediction. Typically what happens, is that you learn local feature detectors, they’re like SIFT, but at different levels and different layers. And this detectors that you learn, they detect different things, different properties of the image at different levels. So, the first layer, you might learn detectors that look kinda like these little patches, which really react to things like diagonal edges And the last one here is about capturing transitions and color from dark to green.
For the challenge of image recognition we can used a pre trained model which is known as transfer learning without creating our own nurealnet which is time saving
Challenges
Now they do come with some challenges. And to understand those challenges, we need to talk about the workflow of training a neural network. So you need to start with lots and lots and lots of data. And that data has to be labeled. Every image has to have, what dog was in the image, is it a labrador, is it a poodle, is it a golden retriever, chihuahua and so on. And that requires a lot of human annotation and that can be hard.
What Is Transfer Learning?
Transfer learning generally refers to a process where a model trained on one problem is used in some way on a second related problem.
In deep learning, transfer learning is a technique whereby a neural network model is first trained on a problem similar to the problem that is being solved. One or more layers from the trained model are then used in a new model trained on the problem of interest.
It’s not uncommon for the task you want to solve to be related to something that has already been solved. Take, for example, the task of distinguishing cats from dogs. The famous ImageNet Challenge, for which CNN’s are the state-of-the-art, asks the trained model to categorize input into one of 1000 classes. Shouldn’t features that distinguish between categories like lions and wolves also be useful for discriminating between cats and dogs and automobile and birds?
The answer is a definitive yes. It is accomplished by simply removing the output layer of the Deep Neural Network for 1000 categories, and taking the signals that would have been propagating to the output layer and feeding them as features to a classifier for our new image classification task.
Lets Learn it with a Example
First you should have downloaded the data set in this Link1 , Link2
Link 1 : https://drive.google.com/drive/folders/1xnK14rGLg-TTZoQty7UGcpAhinIRsMFS?usp=sharing
Link 2 : https://drive.google.com/drive/folders/1BEkfCig1Unp4F2hiBPHSoS14hRRtVrE_?usp=sharing
Next
lets start it by install turicreate and importing the dataset
Next
Explore the dataset
Next
make the model for for image pixels
this is raw image pixel classifier
Next
lets see the first 3 data in the train data
Next
Lets predict using the raw pixel image model
lets see how this model works
Next
Lest train for the deep features using reinforcement learning
so in my data set the deep features from a already trained model is given if you went to add like that follow
deep_learning_model = turicreate.load_model('imagenet_model_iter45')image_train['deep_features'] = deep_learning_model.extract_features(image_train)
now lets make a deep feature model
Next
lets see how the model works
lets see the accuracy
Next
create the deep learning model using nearest neighbor
select a cat image
see we cannot see the predicted images so make a function to map the reference label and id
def image_query_id(query_result):return image_train_data.filter_by(query_result['reference_label'],'id')
for a car
Next
lets make the above step easy by a lambda function
#lets make a lamda functionget_neigbours = lambda i : image_query_id(knn_model.query(image_train_data[i : i+1]))['image'].explore()
Next
Sketch the data set for training data
Next
Create category-specific image retrieval models
Lets see the first item in data set and predict it using different model
Next
now lets evaluate the model
lets see the accuracy of the models
this is to see the dog and cat prediction in a trained cat module by giving dog images
Now make a Sframe with all the distances
Create an SFrame with the distances from ‘dog’ test examples to the respective nearest neighbors in each class in the training data
Create a function which returns 1 if the value for row[‘dog-dog’] is lower than that of the other columns, and 0 otherwise. That is, returns 1 if this row is correctly classified by 1-nearest neighbors, and 0 otherwise.
def is_dog (row):print(min(row.values()))if (row['dog-dog'] <= min(row.values())):return 1else:return 0
Next
lets evaluate the prediction
link for github repo
Done
Hope the tutorial was helpful. If there is anything we missed out, do let us know through comments.😇
❤️❤️❤️❤️❤️❤️❤️Thanks for reading❤️❤️❤️❤️❤️❤️❤️❤️