![]() |
VOOZH | about |
Image Recognition plays an important role in many fields like medical disease analysis and many more. In this article, we will mainly focus on how to Recognize the given image, what is being displayed.
Mobilenet is a model which does the same convolution as done by CNN to filter images but in a different way than those done by the previous CNN. It uses the idea of Depth convolution and point convolution which is different from the normal convolution as done by normal CNNs. This increases the efficiency of CNN to predict images and hence they can be able to compete in the mobile systems as well. Since these ways of convolution reduce the comparison and recognition time a lot, so it provides a better response in a very short time and hence we are using them as our image recognition model.
Since the images can be seen as a matrix of pixels and each pixel describes some of features of the image, so these technologies uses filters to filter out certain set of pixels in the images and results in the formation of output predictions about images.
CNN uses lot of pre-defined and stored filters and does a convolution (X) of that filter with the pixels matrix of the image. This results in filtering the image's objects and comparing them with a large set of pre-defined objects to identify a match between them. Hence in this way these models are able to predict the image.
But these technologies requires a high GPU to increase the comparison rate between millions of data which cannot be provided by any mobile device.
We are aimed to recognize the given image using machine learning. We are assuming we are already having a pre-trained model in our Tensorflow which we will be using to Recognize images. So, we will be using Keras of Tensorflow to import architectures which will help us to recognize images and to predict the image in a better way using coordinates and indexing, we will be using NumPy as a tool.
Imports all necessary modules for loading the model, preprocessing the image, making predictions and displaying results.
Loads the MobileNet model with pretrained ImageNet weights for 1000-class classification.
We fetch a publicly hosted sample image (of a cat) using get_file and load it resized to MobileNetโs required input size (224x224).
Converts the image to a NumPy array, reshapes it to fit the model input and applies MobileNet-specific preprocessing.
Model outputs class probabilities for the input image.
Translates prediction output into human-readable labels and prints the top 3 results.
Output:
1. Egyptian_cat: 0.5965
2. tiger_cat: 0.1951
3. tabby: 0.0847
Shows the image and the top prediction as the title.
Output:
You can download the complete code fromhere.