Deploy an operational AI model

Transfer learning with pretrained blocks

Save training time and create well-performing models with small datasets. Sounds good?
This tutorial will teach you how.

By using transfer learning with our pretrained blocks, you can create a well-performing model even though you have a small dataset.

Person - Target audience: Beginners
Clock - Estimated Time: 20 minutes
Spaceship - Tutorial type: Learn AI & platform
Bell - Problem type: Image classification

You will learn to
Peltarion logo - Build an AI model quick and easy.
Peltarion logo - Use your AI model with a real-world AI web service.
Peltarion logo - Solve a single-label image classification problem, that is, predict what an image shows.

Create a project

First, navigate to the Projects view.
Click New project to create a project and name it, so you know what kind of project it is.

New project icon

A project combines all of the steps in solving a problem, from the pre-processing of datasets to model building, evaluation, and deployment. Using projects makes it easy to collaborate with others.

Add the MNIST dataset to the platform

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

There are several ways to import your data to the platform. This time we will use the Data library that is packed with free-to-use datasets, so click the Import free datasets button.

Import free datasets button

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

The MNIST dataset
The original MNIST dataset consists of small, 28 x 28 pixel images of handwritten numbers that are annotated with a label indicating the correct number.

Examples from the MNIST dataset
Figure 1. Examples from the MNIST dataset

The MNIST dataset we’re using in this tutorial consists of 3-channel RGB pictures because then you can use the deployed experiment with a phone.

For a model to be usable, the input data needs to be of the same type as the model was trained on. In this case, the picture that depicts a number needs to be in RGB (a standard digital format.) This is true for every AI model – it can’t predict apples when it has been trained on oranges.

Click Accept and import (→ you agree with the license).

Accept and import button

This will import the dataset in your project, and you can now edit it.

Save the dataset

Keep these default values that are shown here in the Datasets view. They’re all set for this project.
Later you can change the subsets split, feature encoding, and more. If you want to dig deeper into all the things you see in this view, you should navigate to the Datasets view articles in the Knowledge center.

Click Use in new experiment to open the Experiment wizard.

Use in new experiment button

Design a deep learning network with the wizard

The Experiment wizard makes it really easy for you to set up an experiment. Let’s take a look and make sure that all presets are correct:

  • Dataset tab
    The MNIST dataset is selected.

  • Inputs / target tab

    • Image as Input feature, since we want to classify images.

    • Number as Target feature, since we want to know what number an image depicts.

  • Problem type tab
    Select Single-label image classification as problem type.

  • Click Create.

Create button

Run experiment

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

  • Batch size in the Settings tab. Decides how many samples should be calculated at the same time.

  • Learning rate in the Settings tab. The size of the update steps along the gradient.

  • Loss function in the Target block. Loss is a number on how well the model performs.
    If the model predictions are totally wrong, the loss will be a high number. If they’re pretty good, it will be close to zero.

By default, we’ve also chosen the Run until validation loss stops improving in the Settings tab. This means that the training will automatically be stopped when the validation loss has stopped improving. Great to make sure you don’t train for too long.

The next step is simply to click Run. So let’s do that!
Click Run in the top right corner to start the training.

Run button

Analyze experiment

In the Evaluation view, you can see how the loss gets lower for each epoch (when the complete training set has run through the model one time).

Loss graph

Model evaluation view — Training overview
Figure 2. Model evaluation view — Training overview

The loss indicates the magnitude of error your model made on its prediction. It’s a method of evaluating how well your algorithm models your dataset.

If your predictions are totally off, your loss function will output a higher number. If they’re pretty good, it’ll output a lower one. Is the loss low enough?

Yes, this is good to go.

Confusion matrix

Model evaluation view — Confusion matrix
Figure 3. Model evaluation view — Confusion matrix

You can also get information from the confusion matrix. You’ll find it if you click Predictions inspection.

The confusion matrix is used to see how well a system does classification. The diagonal shows correct predictions. Everything outside this diagonal is errors. In a perfect classification, you’ll have 100% on the diagonal going from top left to bottom right.

Results ok – let’s deploy

In later tutorials, we will iterate on the experiment by tweaking the model to improve it. But this is good to go – time to deploy.

Deploy your trained experiment

This experiment is great, but it’s of no use as long as it is locked up inside the Peltarion Platform. If you want people to use the trained experiment, you have to get it out in some usable form.

Create new deployment

In the Evaluation view, click Create deployment.

Create deployment button
  1. Select experiment and checkpoint of your trained model to test it for predictions or enable for business product calls.
    Both Best epoch and Last epoch for each trained experiment are available for deployment.

  2. Click the Enable button to deploy the experiment.

Enable button

Test the MNIST classifier

Click Open web app.

Open web app button

The Deployment web app will show up:

Deployment web app
Figure 4. Deployment web app

Add image to the test classifier

MNIST test number

Drop the image in the Deployment web app and click Get your result.

Result - Success!!

Whazaaaaam!!! You have created an operational AI experiment.

Not working? Remember it’s a prediction

If it doesn’t work every time, remember that the loss from the experiment isn’t 0. Hence, the experiment will predict the wrong numbers in some cases.

If an error occurs, make sure that the uploaded image has three channels (RGB) and the size 28x28 pixels.

Tutorial recap

Using transfer learning with pretrained weights, you have saved hours of training time and created a better performance than would have been possible if you had trained the model from scratch.

Next steps

Use multiple sets of data

Try using multiple sets of data in the tutorial Predict California house prices. Predicting a house price from both tabular and image inputs is a unique problem and not something you can do with anything other than deep learning.

California house pricing

Use web app for more things

The web app you’ve used now is not for MNIST only. You can use the web app as an image classifier to any other deployment if the experiment has been trained on a dataset with 3-channel images, e.g., CIFAR.

Was this page helpful?