Using a trained model

There are two main options to use your model: online or offline. If you want to use the model online, you can do it via SentiSight.ai web platform or via our REST API server. If you would like to use the model offline, you will have to download the model and set up REST API server yourself. Below we will describe all of those options.

Using a trained model via SentiSight.ai web platform

To start using your trained model press "Trained models" -> "Make a new prediction" near the model you want to use and select images to upload from your PC.

You will see the results on the browser screen. There are three options to download the results:

  • As a .zip file with images grouped into folders by the predicted label
  • In a .json format
  • In a .csv format

Using a trained model via our REST API server

To begin using your trained model via REST API you will need these details:

  • API token (available under "User profile" menu tab)
  • Project ID (available under "User profile" menu tab)
  • Model name (shown in many places, for example, under "Trained models" menu)

Use this endpoint: https://platform.sentisight.ai/api/predict/{your_project_id}/{your_model_name}/

Please note that for each trained model we save two checkpoints: "the best" - the one with the lowest validation error and "the last" - the one from the last training iteration. By default we will use "the best" model checkpoint to make the predictions for queries via REST API interface. However, if you prefer to use "the last" model checkpoint to make your predictions, you can simply add "/last" to the endpoint: https://platform.sentisight.ai/api/predict/{your_project_id}/{your_model_name}/last

Using an image from your computer

Set the "X-Auth-token" header to your API token string and set "Content-Type" header to "application/octet-stream". Set the body to your image file.

For more details, see the code samples below.


TOKEN="your_token"
PROJECT_ID="your_project_id"
MODEL="your_model_name"
IMAGE_FILENAME="your_image_path"
curl -H "X-Auth-token: $TOKEN" --data-binary @"$IMAGE_FILENAME" \
  -H "Content-Type: application/octet-stream" \
  -X POST "https://platform.sentisight.ai/api/predict/$PROJECT_ID/$MODEL"
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.file.Files;

public class App
{
   public static void main( String[] args ) throws IOException
   {
       if (args.length < 4) {
           System.out.println("Usage: java -jar sample.jar api_token project_id model_name file");
       }
       String token = args[0];
       String projectId = args[1];
       String modelName = args[2];
       String imageFilename = args[3];
       
       byte[] bytes = Files.readAllBytes(new File(imageFilename).toPath());
       
       URL url = new URL("https://platform.sentisight.ai/api/predict/" + projectId + "/" + modelName);
       HttpURLConnection connection = (HttpURLConnection)url.openConnection();        
       connection.setRequestProperty("Content-Type", "application/octet-stream");
       connection.setRequestProperty("X-Auth-token", token);
       connection.setRequestMethod("POST");
       connection.setDoOutput(true);
       DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
        wr.write(bytes);
        wr.flush();
        wr.close();
        
        BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        String output;
        StringBuffer response = new StringBuffer();

        while ((output = in.readLine()) != null) {
            System.out.println(output);
            response.append(output);
        }
        in.close();
   }
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
    <meta charset="utf-8">
    <title>Sample</title>
    <script type="text/javascript">
        const baseApiURL = 'https://platform.sentisight.ai/api/';
        let token = '';
        let predictionId;
        let results;
        let resultOutput;

        function predict() {
            token = document.getElementById('tokenfield').value;
            const projectId = document.getElementById('project').value;
            const modelName = document.getElementById('model').value;
            const input = document.getElementById('upload');
            const resultOutput = document.getElementById('output');
            const file = input.files[0];
            const fr = new FileReader();
            fr.onload = function() {
                results = apiPostRequest('predict/' + projectId + '/' + modelName, fr.result);
                let parsedResults = JSON.parse(results);
                resultOutput.innerText = results
                console.log(parsedResults);
            }
            fr.readAsArrayBuffer(file);
        }

        function apiPostRequest(request, body) {
            const xmlHttp = new XMLHttpRequest();
            xmlHttp.open( "POST",  baseApiURL + request, false );
            xmlHttp.setRequestHeader('Content-Type', 'application/octet-stream');
            xmlHttp.setRequestHeader('X-Auth-token', token);
            xmlHttp.send(body);
            console.log(xmlHttp.responseText);
            return xmlHttp.responseText;
        }
    </script>
</head>
<body>
Token: <input id="tokenfield" type="text" name="" value="">
<br>
Project id: <input id="project" type="number" name="" value="">
<br>
Model name: <input id="model" type="text" name="" value="">
<br>
Upload image: <input id="upload" type="file" name="" value="">
<br>
<button type="button" onclick="predict()">Predict</button>
<br><br><br>
<p id="output">Your results will go here!</p>
</body>
</html>
import requests

token = "your_token"
project_id = "your_project_id"
model = "your_model_name"
image_filename = "your_image_path"

headers = {"X-Auth-token": token, "Content-Type": "application/octet-stream"}

with open(image_filename, 'rb') as handle:
    r = requests.post('https://platform.sentisight.ai/api/predict/{}/{}/'.format(project_id,model), headers=headers, data=handle)

if r.status_code == 200:
    print(r.text)
else:
    print('Error occured with REST API.')
    print('Status code: {}'.format(r.status_code))
    print('Error message: ' + r.text)

Using an image URL

Using the REST API by providing an image URL is very similar to the previous case of using REST API by uploading an image. The only differences are that you need to set the "Content-Type" header to "text/plain" and set the body to your image URL.

For more details, see the code samples below.


TOKEN="your_token"
PROJECT_ID="your_project_id"
MODEL="your_model_name"
IMAGE_URL="your_image_url"
curl -H "X-Auth-token: $TOKEN" --data "$IMAGE_URL" \
  -H "Content-Type: text/plain" \
  -X POST "https://platform.sentisight.ai/api/predict/$PROJECT_ID/$MODEL"
package sentisight.api.predict.sample;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class App
{
   public static void main( String[] args ) throws IOException
   {
       if (args.length < 4) {
           System.out.println("Usage: java -jar sample.jar api_token project_id model_name url");
       }
       String token = args[0];
       String projectId = args[1];
       String modelName = args[2];
       String image_url = args[3];
       
       URL url = new URL("https://platform.sentisight.ai/api/predict/" + projectId + "/" + modelName);
       HttpURLConnection connection = (HttpURLConnection)url.openConnection();        
       connection.setRequestProperty("Content-Type", "text/plain");
       connection.setRequestProperty("X-Auth-token", token);
       connection.setRequestMethod("POST");
       connection.setDoOutput(true);
       DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
        wr.writeBytes(image_url);
        wr.flush();
        wr.close();
        
        BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        String output;
        StringBuffer response = new StringBuffer();

        while ((output = in.readLine()) != null) {
            System.out.println(output);
            response.append(output);
        }
        System.out.println(connection.getResponseCode());
        in.close();
   }
}

<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
    <meta charset="utf-8">
    <title>Sample</title>
    <script type="text/javascript">
        const baseApiURL = 'https://platform.sentisight.ai/api/';
        let token = '';
        let predictionId;
        let results;
        let resultOutput;

        function predict() {
            token = document.getElementById('tokenfield').value;
            const projectId = document.getElementById('project').value;
            const modelName = document.getElementById('model').value;
            resultOutput = document.getElementById('output');
            const url = document.getElementById('url').value;
            results = apiPostRequest('predict/' + projectId + '/' + modelName, url)
            let parsedResults = JSON.parse(results);
            resultOutput.innerText = results
            console.log(parsedResults);
        }

        function apiPostRequest(request, body) {
            const xmlHttp = new XMLHttpRequest();
            xmlHttp.open( "POST",  baseApiURL + request, false );
            xmlHttp.setRequestHeader('Content-Type', 'text/plain');
            xmlHttp.setRequestHeader('X-Auth-token', token);
            xmlHttp.send(body);
            console.log(xmlHttp.responseText);
            return xmlHttp.responseText;
        }
    </script>
</head>
<body>
Token: <input id="tokenfield" type="text" name="" value="">
<br>
Project id: <input id="project" type="number" name="" value="">
<br>
Model name: <input id="model" type="text" name="" value="">
<br>
Url: <input id="url" type="text" name="" value="">
<br>
<button type="button" onclick="predict()">Predict</button>
<br><br><br>
<p id="output">Your results will go here!</p>
</body>
</html>
import requests

token = "your_token"
project_id = "your_project_id"
model = "your_model_name"
image_url = "http://your-image-url.png"

headers = {"X-Auth-token": token, "Content-Type": "text/plain"}

r = requests.post('https://platform.sentisight.ai/api/predict/{}/{}/'.format(project_id,model), headers=headers, data = image_url)

if r.status_code == 200:
    print(r.text)
else:
    print('Error occured with REST API.')
    print('Status code: {}'.format(r.status_code))
    print('Error message: ' + r.text)

Using the model offline - setting up your own REST API server

If you want to set up your own REST API server, you will have to download an offline version of the model. To do that, click on the "Download model" button in the "View training statistics" page.

After the model is downloaded, follow the instructions in Readme.md to set up your local REST API server. You can make the client requests from the same PC on which you set up the server, so the model would be run completely offline. On the other hand, after you set up REST API server, you can also make client requests to this server from many different devices (including mobile) on your network. Note that the REST API server must be run on a Linux system, but the client devices can run on any operating system.

The offline version of the model can be run as a free trial for 30 days. After this period, if you like the offline version, you will have to buy a license from us. Note that we have three options for the speed of the offline model: slow, medium and fast. The license price depends on the selected speed. The free trial always runs on the slow speed mode.