Using a trained model

There are two main options to use your model: via SentiSight.ai web platform or via REST API. If you would like to download and use the model locally, it might also be arranged as a Custom project.

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 REST API

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/';
			var token = '';
			var predictionId;
			var results;

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

			function apiPostRequest(request, body) {
				var 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>
	</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/';
			var token = '';
			var predictionId;
			var results;

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

			function apiPostRequest(request, body) {
				var 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>
	</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)