Image search Recommendations

Satyendra Kumar
4 min readJun 9, 2020
Image Search Recommendations

[Image Search using tensor flow for electronics, automotive and electrical parts]

The above image search uses Image Classification using google pre-trained model inception v3 which has been developed in 2015 and using the 2012 images put by Google. This article contains some details about Inception v3 model (Algorithm) and how to run the code for training your own images with the pre-trained model and also architecture details to show the results and hook-up the results with the company parts to get all the attributes of the parts or parts series.

The idea of improving sales also relies on how quickly we win the quotes and be ahead of competitors. One of the use-case which quite often could be beneficial is doing the cross -reference of our competitor parts and then allow users to see the price of the parts and later on allow to quote.

In this article, we are dividing the cross-referencing of manufacturing parts in 3 sections:

Descriptions of Parts data

For this algorithm, you can take all the parts images which is my case here has roughly 1.2 million training images, 50,000 validation images and 100,000 testing images.

Descriptions of Inception v3 ( GoogleNet version 3)

There are 4 versions.

— GoogLeNet — Inception v1

— Inception v1 with batch Normalization — Inception v2

— Inception v2 with Factorization ideas — Inception v3

— Thus, the BN-Inception / Inception-v2 [6] is talking about batch normalization while Inception-v3 [1] is talking about factorization ideas.

A) Add all the images ( your company + competitor parts images)

B) Build the cross — referencing using the cross reference sheets.

C) train the model ( Inception v3)

D) Build the Mobile page to capture and image and do the cross-reference.

Let’s start the A) of this whole solution. Download the

Image classification using Inception v3 for manufacturing parts

Notes: the inceptionV3 is a google pre-trained model which has been developed in 2015. Most of the companies still uses this pre-trained model as it has the lowest rate of error.

Inception-v3 consist of two parts

Part1: It deals with feature extraction part using a convolutional neural network

Part2: classification part (Fully connected and softmax layer)

The best of transfer learning lies in saving the computation cost. Training the new images (user images) with such model does not require training Part1 which is feature extraction as it is most complex part of the model.

Implementation:

  • Architecture design using Google Cloud GPUs
  • Set up the environment in Google Cloud for training the 1.2 M images ( Google cloud storage buckets)
  • Set up Google Compute VMs and adding Nvidia GPUs for model training.
  • Install and configure tensor flow 1.2, PyNum, Scipy, shutil, werkzeug.utils libraries.
  • Configure Inception v3 libraries inside tensor flow python.platform
  • Developed Script to invoke re-training of images and provide notifications for completion
  • Developed python libraries and classes for images ingestion, re-training the model to create nearest neighbors.
  • Set up Flask libraries for Mobile web APIs to consume the request and provide recommend.

Running from Local Mac using Tensor flow —

  1. Download parts image folder, extract and keep it in server directory
  2. Download datasets for images and keep them inside a directory under upload folder. Final folder structure will be as below
root folder  

└───lib

└───server
| │───rest-server.py
| │───imagenet
| │───static
| │───templates
| │───uploads
| │─Parts

3.Run image vectorizer which passes each data through an inception-v3 model and collects the bottleneck layer vectors and stores in disc. Edit dataset paths accordingly inside the image_vectorizer.py

python server/image_vectorizer.py

This will generate two files namely, image_list.pickle and saved_features.txt. Keep them inside lib folder where search.py script is available.

4. Start the server by running rest-server.py. This project uses flask based REST implementation for UI

python server/rest-server.py

5. Once the server starts up, access the url 127.0.0.1:5000 to get the UI. Now upload any file and see 9 similar images. You can change the value of K from 9 to any values, but don’t forget to update the html file accordingly for displaying.

One interesting application of this project is a recommendation engine based on image features.Here is an example of similar project of mine. Here instead of a web UI i have used an android UI. Once the user clicks a product image, the image will go to the server and k-number of similar product images can be displayed on UI as product recommendations. Theses recommendations are purely based on image similarity.

--

--

Satyendra Kumar

Sr. Enterprise Architect | Digital Transformation Strategist | AI/ML. Passionate about new ideas & innovations, product management and scalability of solutions.