Product recommendations with image similarity

Enhance customer experience using image similarity.

The world of e-commerce is driven by consumer choice. Suggesting similar items to customers is a great way to ensure that customers make a purchase.

Image similarity, which we’ll use in this tutorial, is a way to quantify how similar two images are by creating representations of old images in a dataset, then mapping a new image to the old images to find the most similar ones.

Person - Target audience: Beginners
Clock - Estimated time: Setup - 15 minutes | Building index - 50 minutes

You will learn to
Peltarion logo - Create an image similarity model.
Peltarion logo - Deploy your model.

Marketplace image

Create project

First, click New project to create a project. Name it, so you know what kind of project it is.

New project button

A project combines all of the steps in solving an AI problem on the Peltarion Platform.


The data

After creating the project, you will be taken to the Datasets view, where you can import data.

Click Import free datasets.

Import free datasets

Stanford online products dataset

Look for the Stanford Online Products - tutorial data dataset in the list. Click on the dataset.

Data library Stanford

The Stanford Online Products dataset is very large. It consists of 120,000 photos showing 12 different types of items sold online, in 224x224 resolution. Each image shows an object like a bicycle, coffee maker, lamp, toaster, etc.

Click Accept and import to import the dataset in your project.

Create new smaller subsets

All samples in the dataset are by default split into 10% validation, 10% test, and 80% training subsets. Usually, the default settings are used to train a deployed model for real-world use.
However, this dataset is so large, and it will take a long time to train a model with the whole dataset. You will therefore start by using only 8% of the dataset for training and 2% for validation.

  1. Make sure you look at the advanced settings.

  2. Look for the Subsets section and click New subset.

  3. Name the subset Split 8/2.

  4. Click the 2. Split subset tab and select Random.

  5. Set the Size of the first subset to 8 and name it Training 8%.

  6. Set the Size of the second subset to 2 and name it Validation 2%.

  7. Click Create.

Subset split with 8% training and 2% validation.
Figure 1. Subset split with 8% training and 2% validation.

Click Save version and then Use in new experiment to open the Experiment wizard.

Save version and Use in new experiment buttons

Build a model/create an experiment

In the:

  • Dataset tab,
    Make sure that the Stanford Online Products dataset is selected.
    The selected dataset Split should be 8/2, otherwise training the model will take a long time.

  • Inputs / target tab,
    Select image as Input feature and super_class_id as Target feature.

  • Problem type tab,
    Select Image similarity in the drop-down menu.

Click Create, and you’ll find the model in the Modeling canvas.

Create button

Run the experiment

The experiment is done and ready to be trained. All settings have been pre-populated by the platform.

Click Run and wait until the experiment has finished 1 epoch.

Run button

How does image similarity search work?

When using image similarity, you want to compare a new image with all the images you have in your dataset to find the most similar images in the dataset.

  1. First you convert each image your dataset into a vector with a deep learning model.
    This is what you just did when you clicked Run.

  2. Save all images’ vectors into a large index.
    This is what you’re about to do when you deploy your model.

  3. To find similar images to a new image, you transform that image into a vector with the same deep learning model. Then you compare that vector with every vector in the index to pick the most similar ones.

How image similarity search works
Figure 2. How to find a similar apple image with image similarity

Deploy your model

Create deployment

In the Evaluation view, click Create deployment (you can skip evaluation this time).

Create deployment button

Name the deployment and select Similarity search.

Similarity search

Keep the default values and click Create. The platform will now build an index that includes all image-vectors. This may take some time.

Make the deployment public

Building an index will take some time, but when it’s done, toggle the switch to make your deployment public. This will allow you to share your results with friends and colleagues on, e.g., with the link, Twitter, LinkedIn.

Private to public

Enable deployment

Now click Enable make the deployment available outside the Peltarion Platform.

Enable button

Your experiment is now ready to be called via the deployment API.


Open web app

We’ve made it super easy for you to test the deployment. Click on Open web app, and you will be directed to the Deployment web app.

You just need an image to test. Try to download this image of some kind of chair or take your own photo.

Product recommendation test image

Add the photo and then click Get your result.

Similar chairs
Figure 3. Result example

Recap

  • You’ve create an image similarity model on the Peltarion Platform

  • You’ve built and index with all you images and deployed the model live.

  • You’ve testesd the image


Next step

The Buy or not tutorial will show you how to predict if a customer will buy or not based on earlier customers buying patterns. You will use tabular data to solve this classification problem and get advice on how you’d also solve a regression problem.

Tab data numbers

Test image similarity deployment with Postman

For expert users:
If you’re an expert user, we’ve created an easy walk-through of how to use Postman to call your deployed model.

Image similarity result
Was this page helpful?
YesNo