How to Use Nyckel to Reverse-Engineer Google Vision API.

Taofeek RaheemTaofeek Raheem
9 min read

Introduction

The world we found ourselves in today is developing rapidly with the use of sophisticated technology which makes it much easier for us to achieve a specific task that could have taken ages within a fraction of a second.

Folks that live in the past century might have thought about days like this but do not have enough resources and technology to achieve this incredible goal.

Nowadays, with the aid of Artificial intelligence and Machine Learning, humans can design and build robots that can emulate human behavior perfectly and also think like a human does.

Robots are now being trained on how to perform various tasks which include the identification and detection of images with a twinkle of an eye.

In this article, you will learn how to use Nyckel as an alternative to Google Vision API.

Pre-requisites

  • Knowledge of Python

  • Understanding of Machine learning

  • A web browser (Chrome is advisable)

  • Python Software which you can get here

What is Google Vision API?

Google Vision API is an Image Analysis tool that is powered by machine learning which is developed by Googe (a well-known tech company).

Google Vision API enables software developers to build an application that can be integrated with vision detection features in images, such as objects, faces, text, and logos.

Uses Of Vision API

Vision API is well known for carrying out tasks with accurate and precise results. Below are the core aspects where Vision API is mostly used and generated accurate results.

  • Face Recognition: When an image or set of images is uploaded, Vision API is used to detect the type of faces present in the images. It also consists of a broad application like a surveillance system.

  • Optical Character Recognition(OCR): This is a typical illustration of Computer Vision whose main objective is to extract text from an image.

  • Image Properties Detection: As it sounds, Vision API is also used to detect image properties such as color.

  • Label Detection: Vision API can also be used to annotate an image with a label considering the image contents. The label can identify a range of things such as locations, activities, objects, species of animals,humans, facial expressions, animals and products.

Google Vision API is a very popular tool that is very easy to integrate into your application even if you don't have a solid knowledge of Machine Learning.

It is widely used in various tools and frameworks which include Python, PHP, Java, Ruby, Node.js and C#.

How to Use Vision AI

You might be wondering how Google Vision API works out! Right? Don't worry, I am going to take you through a real example using the Google Vision AI Homepage.

  • Navigate to the Google Vision AI page using your Chrome browser.

  • scrolled down a little bit till you find a sub-section called Try the API

  • This section contains a box that allows you to drag/upload an image of your choice on its interface as shown below:

  • Once you upload an image, it will provide you with some information by performing some tasks namely Image recognition, Labelling, and Image properties.

As shown in the image above, Vision AI detected a lot of information about the image. It accurately named the image as a Cat with 80% accuracy and precision. Isn't it Fascinating? You can explore the other tabs such as labels and properties to learn more about the image.

Labels Google Vision API Can Return.

The API is well known to have a wide range of labels it can work with which makes it user-friendly and easily chosen by most developers. According to research carried out by James Cameroon, Google's open images consist of a list that is slightly above 20,000 classifications.

The list of labels the API can return includes but is not limited to:

OpenImages ClassificationI.D
Air conditioning01127
Airmail01_097
Roller coaster010l12
Witch hat010lq47b
Bun (Food)0119x1zy
Water bottle0118n_9r
Reflex camera0118ms9c
Plantation011yvr
Pencil skirt01172_8x
Stained glass011y23
Sea turtle0120dh
Electronic instrument0121tl
Football01226z
Container011q46kg
Amusement park010jjr

You can have access to the full list by downloading the file here.

Using Python as Vision API Client Library

Now, you understand that Vision API can be used to request some piece of information from an image such as label detection. You might be wondering how to go about it! To achieve this, You will need to use a Client library. Examples of such libraries are Python, Java, Node.js and GO.

However, I am going to be using Python as the Client library. Don't be baffled, the syntax is going to be fun and simple.

Note: Take careful consideration of the indentation used in all the code written. It is highly important when using Python.

Now, the first procedure is to install the Python variant of the Google Vision API which can be achieved using pip.

pip install --upgrade google-cloud-vision

Now that your installation is successful, the next step is to verify it by importing the Google Cloud client library as shown below

import io
import os
# Imports the Google Cloud client library
from google.cloud import vision

Now you will build an application by writing some code, this application will be used to recognize and detect some general features of an Image such as color, animals, and locations.

To achieve this, the intended image will be stored inside the computer that will be used to run the application. You will now insert the path of the image as input into the application.

Firstly, you will need to Instantiates a client by using ImageAnnotatorClient(). This syntax contains the utilities that are used for extracting image properties.

client = vision.ImageAnnotatorClient()

Now you will create a variable that will contain the filename of the image to annotate and also its folder directory.

file_name = os.path.abspath(imageML/siberiancat.jpg')

Then you will load the image into your workspace memory using io. open which contains two arguments which are the file_name and rb.

with io.open(file_name, 'rb') as image_file:
    content = image_file.read()

The next step is for you to instantiate an object by using the code vision.types.image which will take content=content as its argument.

image = vision.types.Image(content=content)

Now, you are going to write a code that will perform label detection on the image file.

To achieve this, you will need to :

  • call client.label_detection which will take image=image as an argument

  • Then you will create a variable called response which will be used to save the result of clients.label_detection.

  • Now, the image properties will be extracted by using response.label_annotations which will be saved in another variable called label

response = client.label_detection(image=image)
labels = response.label_annotations

Finally, you will need to print the label description using a for loop as shown in the code written below

print('Labels:')
for label in labels:
    print(label.description)

Other Types of API.

I believe by now you have acquired some little knowledge about Google Vision API. However, Google Vision API is not the only API developers can use. Other APIs can conveniently perform the same task as google vision API producing accurate and precise results.

An example of such API is Nyckel. It sounds strange to you, right? Don't be scared it's quite easy to use and integrate into your workspace.

Now let us dive in.

What is Nyckel?

Nyckel is a machine learning API that allows developers to train and integrate ultra-modern and sophisticated machine learning into their applications within a fraction of a second.

It is built in such a way that it can be used effortlessly by developers and non-expert to provide automated training to their models instead of brainstorming themselves to write codes manually.

How to Train Nyckel and Integrate it Into Your Application?

Now, I will show you step by step guide on how you can train Nyckel to recognize and label an object or animal and then detect it with great precision the next time it came across anything similar to it.

It going to be fun and exciting, Now let's get Started

Step 1

Create a Nyckel account - To use Nyckel API to train your model, you will need to create a simple personal account. Use your Chrome browser to sign up on Nyckel.

Step 2

Click on new function as shown below

Then u will click on images, Scroll down a bit and you will see a sub-heading called Output Labels. Here you will create a label name(such as Animal, Object, Human) which you want to train the API to recognize when an image is uploaded

Note - You can create additional label names as much as you like, It depends on the range of information you want to train the API with.

Now Click on create function.

Step 3

You will now upload different kinds of images you want to train the API to recognize

Now Click on import in the blue button.

Step 4

The Next step is to train the API by assigning the correspondinglabel names to each image you uploaded.

Then click on invoke.

Step 5

You have completed training the API to recognize and Label images. Now you will test it by uploading a new random image and clicking on the invoke button.

As shown below, I uploaded an image of a baby, and it was labeled as Human with 0.7736 Confidence as shown under the function output.

Step 6

Along with the Function Output which contains a LabelName and Confidence level, Nyckel API also generated an automatic code that developers can use by integrating it into their application instead of writing out the code manually.

import requests

url = 'https://www.nyckel.com/v1/functions/tawetnxnruod16gh/invoke'
headers = {
    'Authorization': 'Bearer ' + 'eyJhbGciOiJSUzI1NiIsInR5cCI6ImF0K2p3dCJ9.eyJuYmYiOjE2ODIzNzIzMDUsImV4cCI6MTY4MjM3NTkwNSwiaXNzIjoiaHR0cHM6Ly93d3cubnlja2VsLmNvbSIsImNsaWVudF9pZCI6ImhyamY5Y2NrNXkxbzBoaWl1cXdhczk1dXJxYTExYjhvIiwianRpIjoiMUZBNjYxOEZFMDI0RjFCMUM2NTA1NjdFRTVFQTE2RDIiLCJpYXQiOjE2ODIzNzIzMDUsInNjb3BlIjpbImFwaSJdfQ.f0ZcukpCyunQez4UucCcE6gPqDZ68qSlJyURZCq3spEn4Hp6Da0C7dLLsaD0vGtBVLt_mTlF7AI3X4wvoEfioM5SrrT4Pn8p2OF4T3CdA3QWIiLcCMv2fNE6baaRqyYZ1qjt9JF-Bky8VFkxm4DQTovFxCwm98x0ZrvjHsinoMPf-hYnHazrDOBEjH2TPSSUlQVbalUOpGiVlpcZUANI8AXLjYCva3XCJL9qxI3rMMrbG5vdx2jRum6Dv0SxflykRLEjxYqxPe3y0UNWvuTF15Pl0ACHpu0XRKO6WOR4-RZaq_h_4zyXg3jTeIExxlUigHr9I9fzf3CyEunnpANARw',
}

with open('baby.jpg', 'rb') as f:
    result = requests.post(url, headers=headers, files={'data': f})
print(result.text)

Conclusion

Due to Google's popularity as a giant tech company, Google Vision API is widely used among developers. But with this article, you can see that Nyckel is a very great and powerful tool that can perform exactly the task carried out by Google Vision API.

Google Vision API can be difficult to use for non-expert or developers that do not have core knowledge of programming and machine learning.

However, Nyckel makes it much easier for a non-expert to train the API to recognize images and be easily integrated into their application through the code that is auto-generated by Nyckel.

It's highly appropriate to conclude that Nyckel is a wonderful API that can be used as an alternative to Google Vision API for developers and non-expert.

0
Subscribe to my newsletter

Read articles from Taofeek Raheem directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Taofeek Raheem
Taofeek Raheem

I am a well-oriented Frontend developer with a great zeal towards the transformation of innovative ideas into effective technological solutions. I am also a technical writer who loves to simplify complex concepts into digestible bit for developers and non-expert