It is the fastest and the simplest way to do image recognition on your laptop or computer without any GPU because it is just an API and your CPU is good enough for this.
Before I start showing you guys how to implement this API with any image, here is an example…
Input is an Image of Space Rocket/Shuttle whatever you wanna call it.
The Output is “space shuttle (score = 89.639%)” on the command line.
Don’t worry if you have linux or Mac. I’m sure this will work on every system with any CPU assuming you already have TensorFlow 1.4 installed.
The whole process will be done in 4 steps :
1. Download the model from tensorflow repository.
Go to the tensorflow repository link and download the thing on your computer and extract it in root folder and since I’m using Windows I’ll extract it in “C:” drive.
Now name the folder “models”.
2. Command line
Open the Command prompt (as Admin).
Now, we need to run the classify_image.py file which is in “models>tutorials>imagenet>classify_image.py” type the following commands and press Enter.
This will download a 200mb model which will help you in recognising your image.
If everything worked perfectly you will see in your command prompt:
giant panda, panda, panda bear, coon bear, Ailuropoda melanoleuca (score = 0.88493) indri, indris, Indri indri, Indri brevicaudatus (score = 0.00878) lesser panda, red panda, panda, bear cat, cat bear, Ailurus fulgens (score = 0.00317) custard apple (score = 0.00149) earthstar (score = 0.00127)
Now just to make sure that we understand how to use this properly we will do this twice. Once keeping the image file in the “models>tutorials>imagenet>” directory and second keeping the image in different directory or drive 😏
3. Download the image in the directory
Feel free to use any image from the internet or anywhere else and paste it in the “models>tutorials>imagenet>images.png” directory with the classify_image.py and then we’ll paste it in “D:\images.png” or whatever directory you want to, just don’t forget to keep in mind to type the correct address in the command prompt.The image I used is below.
4. Use Command prompt to perform recognition
To perform this you need to just edit the “ — image_file” argument like this.
a) For the image in the same directory as the classify_image.py file. After coming in the imagenet directory, open the command prompt and type…
python classify_image.py --image_file images.png
b) For image in the different directory type by pointing towards the directory where your image is placed.
python classify_image.py --image_file D:/images.png
Now, obviously results for both the Images were same which is given as below.
As you can see the score is pretty accurate i.e. 98.028% for mobile phone.