Find similar images of fruits

Use image similarity to find out what fruit you (probably) got.

Imagine you want to buy a nice new kind of fruit. You’re looking at all the fruits available, and you think; So many new kinds of fruit! What fruit is that?
That’s when you happily reach for your deployed image similarity fruit model.

Person- Target audience: Beginners
Spaceship- Tutorial type: Get started tutorial
Clock- Estimated time: 15 minutes
Bell- Problem type: Image similarity

You will learn to
Peltarion logo- Build and deploy a model for image similarity
Peltarion logo- Use the output from a specific block in the model

Why image similarity search?
Image similarity is a way to quantify how similar 2 images are.
Similarity search is faster than pixel by pixel comparison since the data becomes so compressed. Another advantage is that the image will be compared with each other on multiple levels and not just by their individual pixel values.

Similar cases

- What spare part is that?
- Where is my image used online?
- Where can I buy a similar bag?
- Do I have a lookalike?
- Totally looks like who?

Create a project

First, click New project to create a project and name it, so you know what kind of project it is. Naming is important.

New project button

Add dataset to the platform

After creating the project, you will be taken to the Datasets view.

Click the Import free datasets button.

Import free datasets button

Look for the Fruits 360 - tutorial data dataset in the list.
Click on it to get more information.

The Fruits 360 dataset

This dataset consists of over 50000 photos of 100 types of fruits, photographed in color, 100x100 pixels under various angles.

Fruit images from the dataset
Figure 1. Fruit images from the dataset

If you agree with the license, click Accept and import. This will import the dataset in your project, and you will be taken to the dataset’s details where you can edit features and subsets.

Use in new experiment button

Build model with the Experiment wizard

This will import the dataset in your project. You can now edit it but you don’t have to since the dataset is automatically set up. You just have to click Use in new experiment to open up the Experiment wizard.

  • Dataset tab
    Make sure that the Fruit 360 dataset is selected.

  • Inputs / target tab
    Select image as Input and fruit_class as Target.
    (This will help the model learn not only what the fruits look like, but also what they actually are).

  • Problem type tab
    Select Problem type Image similarity.

Finally, click Create and you will find the model in the Modeling view.

Run the model

Click Run and wait until the experiment has finished 1 epoch, this means that all the images in the dataset will pass through the model once.

Run button

Deploy model

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

Create deployment button
  1. Name the deployment and select Similarity search.
    Similiarity search deploy switch

  2. Make sure all settings are what you want them to be:

    • Experiment — The experiment you want to deploy.

    • CheckpointEpoch 1 since you only trained for 1 epoch.

    • Embedding blockImage embedding. These embeddings will be stored in the index used for similarity search.

    • Output features - Both fruit_class and image.

  3. Click Create and you will build an index that includes all image-vectors. This may take some time.

  4. Click Enable when the index is done.

Enable button

Your experiment is now ready to be called via the deployment API or by deploying your own deployment web app straight from the deployment page.

Test with deployment 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.

Open web app button

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

Test fruit test image


Add the photo and then click Get your result.

Fruit similarity
Figure 2. Result example

Tutorial recap

  • You’ve added a dataset to your project and built a model based on the pretrained block EfficientNet.

  • You’ve run the model for only one epoch to get the output from the model. This output is an index of all images in the dataset.

  • You’ve deployed your model and tested if it could tell you what fruit it was.

Next steps

Learn how to improve image similarity

In the tutorial Product recommendations with image similarity, you will learn how to create a better customer experience with targeted product recommendations using image similarity.

Get started with image classification

We suggest that you start your deep dive into the Peltarion Platform with the Car damage assessment tutorial. It’ll walk you through the workflow at a higher level than this tutorial.

Further reading

How does image similarity search work?

With 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 in the dataset into a vector with a deep learning model (in our case EfficientNet).
    All images’ vectors are saved into a large index.

  2. 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

You can dive deeper into what image similarity search is by reading this blog-article by Romain.

Was this page helpful?
Yes No