productAI

Custom Training

Custom Training Service provides API for users to train their own models by uploading sets of labeled data. With these custom trained models, users can complete their image labeling tasks based on their own data.

Note: Currently, this service is only provided in China mainland ( click here to view the regions list ). If more regions are demanded, please contact the account manager or click here to send mail to us.

Basic Concept

Each custom training service is composed of two processes:

  • Users upload their own labels and data to complete the training process. This process is time consuming, and it only will be executed once if the data is not updated.
  • Inference (or Prediction): Using custom trained models to classify/analyze the content of unlabeled images and return related labels.

Custom Training Services can be classified as following types based on the differences in returning results:

TypeTraining DataInference (or Prediction) ResultExamples
Single Label ClassifierA group of user-defined labels and a group of images. Each image has one related label.Accept an image as input, and return one of the user-defined labels. The returned label should relate to the image semanticsCustom training service of ‘Cat or Dog’ Classification
dog
Return label ‘dog’
cat
Retrun label ‘cat’

Examples

Currently, ProductAI only supports the ‘single label classifier’ service. This section mainly introduces the principles of label definition and training data selection. The quality of label definition and training data selection will determine the accuracy of the self-trained model.

Indoor/Outdoor Classifier

Build a classifier to distinguish scenes between indoor and outdoor.

Label definition

Define two labels: ‘indoor’ and ‘outdoor’ according to the usage requirements. Usually, there are a few of requirements as following for self-defined labels:

  • Labels should have clear-cut distinction in semantics. For example, people can easily tell the difference between ‘indoor’ and ‘outdoor’ scenes, so ‘indoor & outdoor’ is a good set of self-defined labels. However, ‘garden’ and ‘courtyard’ have some overlaps in semantics, hence these two labels are not recommended for being used in model training at the same time.
  • Labels should have clear-cut distinction in visual features. For example, ‘Forsythia’ and ‘Winter Jasmine’ are totally different plant in botany. However, distinguishing these two different flowers by human eyes is very difficult. Hence, it is hard to guarantee the training accuracy if we use these visually easily-confused labels.
  • ‘Single Label Classifier’ only returns one label as the result, therefore, we should avoid using pictures that contain multiple objects related to different labels. For example, when building a classifier to differentiate animals (e.g. cat, dog, lion, tiger, etc.), we should avoid using the picture that contains cat, dog, lion, tiger at the same time for training and prediction.
  • Recommend adding a ‘other’ label if all labels in the label set cannot describe the content of the input image. For example, when using the label set that only containing ‘Corgi’, ‘Huskie’ and ‘Samoyed’ to classify dog images, it would be better if we adding a ‘other’ label to the label set, because these three labels cannot describe other types of dogs. However, if there are enough labels that can cover most situations, there is no need to add the ‘other’ label for image classification.

Training Data Selection

For each label in the label set, we need to prepare a set of training data. There are a few of requirements as following for training data:

  • The amount of training data should be sufficient. The more training data we use, the more accuracy the model will be, while the more time the training process will take at the same time.
  • The training data should be diversified, that is to say, the training data should cover all situations related to the label. For example, to train the model for ‘indoor’ label, all following situations should be considered in the training data, like restaurant, classroom, gymnasium, bed in a room, interior of a castle, etc.
Self-defined LabelTraining Data Examples
indoorsee results of indoor by search engine
outdoorsee results of outdoor by search engine

Training Data

The training data is a set of images, each image has one label.

Create Training Set

Python

PHP

Java

cURL

from productai import Client

cli = Client(ACCESS_KEY_ID, SECRET_KEY)
api = cli.get_training_set_api()
resp = api.create_training_set(name=SET_NAME, description=SET_DESC)
use ProductAI\Api;

$product_ai = new ProductAI\Api\TrainingSetApi(ACCESS_KEY_ID, SECRET_KEY);
$result = $product_ai->createTrainingSet($name=SET_NAME, ["description" => SET_DESC ]);
import cn.productai.api.core.*;
import cn.productai.api.core.enums.*;
import cn.productai.apiv2.*;
import cn.productai.apiv2.impl.*;

IProfile profile = new DefaultProfile();
profile.setAccessKeyId(ACCESS_KEY_ID);
profile.setVersion("1");

TrainingSet trainingSet = new TrainingSetImpl();
trainingSet.setProfile(profile);

String result = trainingSet.create("NAME", "DESC");
System.out.println(result);
curl -X POST \
-H 'x-ca-version: 1.0' \
-H 'x-ca-accesskeyid: ACCESS_KEY_ID' \
-H 'Content-Type: application/json' \
-d '{"name": "SET_NAME", "description": "SET_DESC"}' \
https://api.productai.cn/custom_training/_0000194/training_sets

Request

ArgumentTypeDescriptionRequiredLimitation
nameStringTraining set nameYesMaximum 16 unicode characters, the extra characters are truncated
descriptionStringTraining set descriptionYesMaximum 128 unicode characters, the extra characters are truncated

Response

HTTP Status Code 200
{
"created_at": "2018-05-23T04:48:07Z",
"creator_id": ...,
"description": "ts100",
"id": "085ffdpo",
"modified_at": "2018-05-23T04:48:07Z",
"n_downloaded": 0,
"n_failed": 0,
"n_items": 0,
"name": "ts100",
"request_id": "7cab5d0c-5e44-11e8-b9eb-6a95ff447c19",
"status": "not-downloaded"
}
FieldTypeDescription
request_idStringThe unique ID of this request, it can be used in product issue debugging with ProductAI support team
created_atStringCreated UTC datetime, the format is: %Y-%m-%dT%H:%M:%SZ
creator_idStringCreator ID
descriptionStringTraining set description
idStringUnique ID, all the training set related APIs will use this ID to identify a training set.
modified_atStringLast modified UTC datetime, the format is: %Y-%m-%dT%H:%M:%SZ
n_downloadedIntegerThe count of successful downloaded image in the training set
n_failedIntegerThe count of failed downloaded image in the training set
n_itemsIntegerThe total non-deleted image count in the training set
nameStringTraining set name
statusStringThe status of training set.If no any image is downloaded, the value is not-downloaded. If some of images are downloaded successfully, but the other haven’t been downloaded yet, the value of this field is downloading. If all the images were download successfully or failed, the value is downloaded.
Non-200 HTTP Status Code
{
"error_code": 5004,
"message": "Name Should Not Be Empty.",
"request_id": "e00b8a7a-5e62-11e8-8cb4-d680a9823a64"
}
FieldTypeDescription
error_codeIntegerDetailed error code
messageStringDetailed error message
request_idStringThe unique ID of this request, it can be used in product issue debugging with ProductAI support team

Error Code

SDK/API notifies the client about whether the request success or fails via HTTP status code

HTTP Status Codeerror_codeDescription
200N/aTraining set created successfully
4005004Missing training set name or description
4033002Reaching the maximum amount of TrainingSets

List All Training Sets

Python

PHP

Java

cURL

from productai import Client

cli = Client(ACCESS_KEY_ID, SECRET_KEY)
api = cli.get_training_set_api()
resp = api.list_training_sets()
use ProductAI\Api;

$product_ai = new ProductAI\Api\TrainingSetApi(ACCESS_KEY_ID, SECRET_KEY);
$result = $product_ai->listTrainingSets();
import cn.productai.api.core.*;
import cn.productai.api.core.enums.*;
import cn.productai.apiv2.TrainingSet;
import cn.productai.apiv2.impl.TrainingSetImpl;

IProfile profile = new DefaultProfile();
profile.setAccessKeyId(ACCESS_KEY_ID);
profile.setVersion("1");

TrainingSet trainingSet = new TrainingSetImpl();
trainingSet.setProfile(profile);

String result = trainingSet.listAll();
System.out.println(result);
curl -X GET \
-H 'x-ca-version: 1.0' \
-H 'x-ca-accesskeyid: ACCESS_KEY_ID' \
https://api.productai.cn/custom_training/_0000194/training_sets

Request

N/a

Response

{
"request_id": "ff126524-5e44-11e8-a528-d6abcabd1965",
"results": [
{
"created_at": "2018-05-23T04:48:08Z",
"creator_id": ...,
"description": "ts100",
"id": "085ffdpo",
"modified_at": "2018-05-23T04:48:08Z",
"n_downloaded": 0,
"n_failed": 0,
"n_items": 0,
"name": "ts100",
"status": "not-downloaded"
}
]
}
FieldTypeDescription
request_idStringThe unique ID of this request, it can be used in product issue debugging with ProductAI support team
resultsArrayAll existing training sets, the fields of single item in array see Results details

Results details

FieldTypeDescription
created_atStringCreated UTC datetime, the format is: %Y-%m-%dT%H:%M:%SZ
creator_idIntegerCreator ID
descriptionStringTraining set description
idStringUnique ID, all the training set related APIs will use this ID to identify a training set.
modified_atStringLast modified UTC datetime, the format is: %Y-%m-%dT%H:%M:%SZ
n_downloadedIntegerThe count of successful downloaded image in the training set
n_failedIntegerThe count of failed downloaded image in the training set
n_itemsIntegerThe total non-deleted image count in the training set
nameStringTraining set name
statusStringThe status of training set.If no any image is downloaded, the value is not-downloaded. If some of images are downloaded successfully, but the other haven’t been downloaded yet, the value of this field is downloading. If all the images were download successfully or failed, the value is downloaded.

Fetch Single Training Set

Python

PHP

Java

cURL

from productai import Client

cli = Client(ACCESS_KEY_ID, SECRET_KEY)
api = cli.get_training_set_api(TRAINING_SET_ID)
resp = api.get_training_set()
use ProductAI\Api;

$product_ai = new ProductAI\Api\TrainingSetApi(ACCESS_KEY_ID, SECRET_KEY);
$result = $product_ai->getTrainingSet($trainingSetID=TRAINING_SET_ID);
import cn.productai.api.core.*;
import cn.productai.api.core.enums.*;
import cn.productai.apiv2.TrainingSet;
import cn.productai.apiv2.impl.TrainingSetImpl;

IProfile profile = new DefaultProfile();
profile.setAccessKeyId(ACCESS_KEY_ID);
profile.setVersion("1");

TrainingSet trainingSet = new TrainingSetImpl();
trainingSet.setProfile(profile);

String result = trainingSet.getById(TRAINING_SET_ID);
System.out.println(result);
curl -X GET \
-H 'x-ca-version: 1.0' \
-H 'x-ca-accesskeyid: ACCESS_KEY_ID' \
https://api.productai.cn/custom_training/_0000194/training_sets/TRAINING_SET_ID

Request

N/a

Response

Same as Create Training Set Response

Error Code

SDK/API notifies the client about whether the request success or fails via HTTP status code

HTTP Status Codeerror_codeDescription
200N/aFetch training set successfully
4042001Training set doesn’t exist

Modify Training Set

Python

PHP

Java

cURL

from productai import Client

cli = Client(ACCESS_KEY_ID, SECRET_KEY)
api = cli.get_training_set_api(TRAINING_SET_ID)
resp = api.update_training_set(name=NEW_NAME, description=NEW_DESC)
use ProductAI\Api;

$product_ai = new ProductAI\Api\TrainingSetApi(ACCESS_KEY_ID, SECRET_KEY);
$result = $product_ai->updateTrainingSet($trainingSetID=TRAINING_SET_ID, ["name" => NEW_NAME, "description" => NEW_DESC]);
import cn.productai.api.core.*;
import cn.productai.api.core.enums.*;
import cn.productai.apiv2.TrainingSet;
import cn.productai.apiv2.impl.TrainingSetImpl;

IProfile profile = new DefaultProfile();
profile.setAccessKeyId(ACCESS_KEY_ID);
profile.setVersion("1");

TrainingSet trainingSet = new TrainingSetImpl();
trainingSet.setProfile(profile);

String result = trainingSet.update(TRAINING_SET_ID, NEW_NAME, NEW_DESC);
System.out.println(result);
curl -X PUT \
-H 'x-ca-version: 1.0' \
-H 'x-ca-accesskeyid: ACCESS_KEY_ID' \
-H 'Content-Type: application/json' \
-d '{"name": "NEW_NAME", "description": "NEW_DESC"}' \
https://api.productai.cn/custom_training/_0000194/training_sets/TRAINING_SET_ID

Request

ArgumentTypeDescriptionRequiredLimitation
nameStringTraining set nameYesMaximum 16 unicode characters, the extra characters are truncated
descriptionStringTraining set descriptionYesMaximum 128 unicode characters, the extra characters are truncated

Response

Same as Create Training Set Response

Error Code

SDK/API notifies the client about whether the request success or fails via HTTP status code

HTTP Status Codeerror_codeDescription
200N/aModify training set successfully
4005004Missing training set name or description
4042001Training set doesn’t exist

Delete Training Set

Python

PHP

Java

cURL

from productai import Client

cli = Client(ACCESS_KEY_ID, SECRET_KEY)
api = cli.get_training_set_api(TRAINING_SET_ID)
api.delete_training_set()
use ProductAI\Api;

$product_ai = new ProductAI\Api\TrainingSetApi(ACCESS_KEY_ID, SECRET_KEY);
$result = $product_ai->deleteTrainingSet($trainingSetID=TRAINING_SET_ID);
import cn.productai.api.core.*;
import cn.productai.api.core.enums.*;
import cn.productai.apiv2.TrainingSet;
import cn.productai.apiv2.impl.TrainingSetImpl;

IProfile profile = new DefaultProfile();
profile.setAccessKeyId(ACCESS_KEY_ID);
profile.setVersion("1");

TrainingSet trainingSet = new TrainingSetImpl();
trainingSet.setProfile(profile);

String result = trainingSet.delete(TRAINING_SET_ID);
System.out.println(result);
curl -X DELETE \
-H 'x-ca-version: 1.0' \
-H 'x-ca-accesskeyid: ACCESS_KEY_ID' \
https://api.productai.cn/custom_training/_0000194/training_sets/TRAINING_SET_ID

Request

N/a

Response

N/a

Error Code

SDK/API notifies the client about whether the request success or fails via HTTP status code

HTTP Status Codeerror_codeDescription
200N/aDelete training set successfully
4042001Training set doesn’t exist

Data

Add Multiple Data to Training Set

Python

PHP

Java

cURL

from productai import Client

cli = Client(ACCESS_KEY_ID, SECRET_KEY)
api = cli.get_training_set_api(TRAINING_SET_ID)
with open('added.csv') as f:
api.add_training_data_in_bulk(file=f)
use ProductAI\Api;

$product_ai = new ProductAI\Api\TrainingSetApi(ACCESS_KEY_ID, SECRET_KEY);
$result = $product_ai->addTrainingDataToTrainingSet($trainingSetID=TRAINING_SET_ID, $images="added.csv");
import java.io.File;
import cn.productai.api.core.*;
import cn.productai.api.core.enums.*;
import cn.productai.apiv2.TrainingSet;
import cn.productai.apiv2.impl.TrainingSetImpl;

IProfile profile = new DefaultProfile();
profile.setAccessKeyId(ACCESS_KEY_ID);
profile.setVersion("1");


TrainingSet trainingSet = new TrainingSetImpl();
trainingSet.setProfile(profile);

String result = trainingSet.bulkAddTrainingData(TRAINING_SET_ID, new File("./added.csv"));
System.out.println(result);
curl -X POST \
-H 'x-ca-version: 1.0' \
-H 'x-ca-accesskeyid: ACCESS_KEY_ID' \
-F "urls_to_add=@added.csv" \
https://api.productai.cn/custom_training/_0000194/training_sets/TRAINING_SET_ID/images

Request

ArgumentTypeDescriptionRequiredLimitation
filecsv fileTraining data fileYesThe csv file should contain two columns each line. The first column should be the training image url, and the second column should be related labels of the image. These two columns are seperated by a comma, so the url and labels can not contain commas. Please refer to batch added data example

Response

Same as Create Training Set Response

Error Code

SDK/API notifies the client about whether the request success or fails via HTTP status code

HTTP Status Codeerror_codeDescription
200N/a
4005001Data format is not correct
4042001Training set doesn’t exist

Delete Multiple Data from Training Set

Python

PHP

Java

cURL

from productai import Client

cli = Client(ACCESS_KEY_ID, SECRET_KEY)
api = cli.get_training_set_api(TRAINING_SET_ID)
with open('deleted.csv') as f:
api.delete_training_data_in_bulk(file=f)
use ProductAI\Api;

$product_ai = new ProductAI\Api\TrainingSetApi(ACCESS_KEY_ID, SECRET_KEY);
$result = $product_ai->deleteTrainingDataFromTrainingSet($trainingSetID=TRAINING_SET_ID, $images="deleted.csv");
import java.io.File;
import cn.productai.api.core.*;
import cn.productai.api.core.enums.*;
import cn.productai.apiv2.TrainingSet;
import cn.productai.apiv2.impl.TrainingSetImpl;

IProfile profile = new DefaultProfile();
profile.setAccessKeyId(ACCESS_KEY_ID);
profile.setVersion("1");


TrainingSet trainingSet = new TrainingSetImpl();
trainingSet.setProfile(profile);

String result = trainingSet.bulkDeleteTrainingData(TRAINING_SET_ID, new File("./deleted.csv"));
System.out.println(result);
curl -X DELETE \
-H 'x-ca-version: 1.0' \
-H 'x-ca-accesskeyid: ACCESS_KEY_ID' \
-F "urls_to_delete=@deleted.csv" \
https://api.productai.cn/custom_training/_0000194/training_sets/TRAINING_SET_ID/images

Request

ArgumentTypeDescriptionRequiredLimitation
filecsv fileTraining data fileYesThe csv file can have 1-2 columns each line. If there is only one column each line, every line should be the image url that needs to be deleted. If there are two columns each line, the first column should be the image url that needs to be deleted. Please refer to batch deleted data example

Response

Same as Create Training Set Response

Error Code

SDK/API notifies the client about whether the request success or fails via HTTP status code

HTTP Status Codeerror_codeDescription
200N/aSuccess
4005001Invalid csv file, for example: contains more than 3 columns in one line, the first column is not a valid url
4042001Training set doesn’t exist

Clear Training Set

Python

PHP

Java

cURL

from productai import Client

cli = Client(ACCESS_KEY_ID, SECRET_KEY)
api = cli.get_training_set_api(TRAINING_SET_ID)
# Must input the name of training set for confirmation
api.clear_training_set(SET_NAME)
use ProductAI\Api;

$product_ai = new ProductAI\Api\TrainingSetApi(ACCESS_KEY_ID, SECRET_KEY);
$result = $product_ai->clearTrainingDataFromTrainingSet($trainingSetID=TRAINING_SET_ID, $name=SET_NAME);
import cn.productai.api.core.*;
import cn.productai.api.core.enums.*;
import cn.productai.apiv2.TrainingSet;
import cn.productai.apiv2.impl.TrainingSetImpl;

IProfile profile = new DefaultProfile();
profile.setAccessKeyId(ACCESS_KEY_ID);
profile.setVersion("1");


TrainingSet trainingSet = new TrainingSetImpl();
trainingSet.setProfile(profile);

String result = trainingSet.clearTrainingSet(TRAINING_SET_ID, SET_NAME);
System.out.println(result);
curl -X DELETE \
-H 'x-ca-version: 1.0' \
-H 'x-ca-accesskeyid: ACCESS_KEY_ID' \
-H 'Content-Type: application/json' \
-d '{"name": SET_NAME,"training_set_id":TRAINING_SET_ID,"token": BASE64_CODE}' \
https://api.productai.cn/custom_training/_0000194/training_sets/TRAINING_SET_ID/clear

Request

ArgumentTypeDescriptionRequiredLimitation
nameStringTraining set nameYesTo prevent wrong operations, we should input ‘name’ attribute value to clear the training set data. The training set will be cleared only when ‘name’, ‘training_set_id’ and token3 values match
training_set_idStringTraining set IDYesTo prevent wrong operations, we should input ‘name’ attribute value to clear the training set data. The training set will be cleared only when ‘name’, ‘training_set_id’ and token3 values match
tokenStringBASE64 code of ‘selfserve_admin:SET_NAME’YesTo prevent wrong operations, we should input ‘name’ attribute value to clear the training set data. The training set will be cleared only when ‘name’, ‘training_set_id’ and token3 values match

Response

Same as Create Training Set Response

Error Code

SDK/API notifies the client about whether the request success or fails via HTTP status code

HTTP Status Codeerror_codeDescription
200N/aClear training set successfully
4011004‘name’ attribute value doesn’t match the training set name
4042001Training set doesn’t exist

Service Management

Create Service

Python

PHP

Java

cURL

from productai import Client

cli = Client(ACCESS_KEY_ID, SECRET_KEY)
api = cli.get_training_set_api(TRAINING_SET_ID)
resp = api.create_service(name=NAME, description=DESC, scenario='classifier')
use ProductAI\Api;

$product_ai = new ProductAI\Api\TrainingServiceApi(ACCESS_KEY_ID, SECRET_KEY);
$result = $product_ai->createService(
$trainingSetID=TRAINING_SET_ID,
$name=NAME,
$description=DESC,
$scenario='classifier');
import cn.productai.api.core.*;
import cn.productai.api.core.enums.*;
import cn.productai.apiv2.CustomTraining;
import cn.productai.apiv2.impl.CustomTrainingImpl;

IProfile profile = new DefaultProfile();
profile.setAccessKeyId(ACCESS_KEY_ID);
profile.setVersion("1");

CustomTraining customTraining = new CustomTrainingImpl();
customTraining.setProfile(profile);

String result = customTraining.createService(TRAINING_SET_ID,
NAME,
DESC,
"classifier");
System.out.println(result);
curl -X POST \
-H 'x-ca-version: 1.0' \
-H 'x-ca-accesskeyid: ACCESS_KEY_ID' \
-H 'Content-Type: application/json' \
-d '{"name": "NAME", "description": "DESCRIPTION","scenario":"classifier"}' \
https://api.productai.cn/custom_training/_0000194/training_sets/TRAINING_SET_ID/services

Request

ArgumentTypeDescriptionRequiredLimitation
nameStringCustom training service nameYesN/a
descriptionStringCustom training service descriptionYestN/a
scenarioStringCustom training typeYesSee Service Type

Response

200 HTTP Status Code
{
"created_at": "2018-05-23T07:03:25Z",
"creator_id": ...,
"id": "lewj7738",
"last_updated_at": "2018-05-23T07:03:25Z",
"name": "ts100",
"request_id": "633188fc-5e57-11e8-8cb4-d680a9823a64",
"scenario": "classifier",
"status": "pending",
"training_set_id": "085ffdpo"
}
FieldTypeDescription
created_atStringCreated UTC datetime, the format is:%Y-%m-%dT%H:%M:%SZ
creator_idIntegerCreator ID
idStringUnique ID of custom training service, all following operations are depending on this ID
last_updated_atStringLast modified UTC time, to seconds, the format is: %Y-%m-%dT%H:%M:%SZ
nameStringCustom training service name
request_idStringThe unique ID of this request, it can be used in product issue debugging with ProductAI support team
scenarioStringUse classifier as the value
statusStringCurrent status of custom training service, please refer to Detailed Service Status Description
training_set_idStringTraining set ID which is used for current service
Detailed Service Status Description
StatusDescription
pendingThe service is unavailable at this moment. The request of creating service has been received, and the service is waiting for training resources
preparingThe service is unavailable at this moment. The service starts running training process
evolvingThe service is available and can be used normally. It still keep optimizing for better effect.
runningThe service is available. Training process is finish, the service can be used normally
failedThe service is unavailable at this moment. Creating service fails (e.g. The training process has been terminated by error)
deletedThe service is unavailable at this moment. The service has been deleted
Non-200 HTTP Status Code
{
"error_code": 2001,
"message": "Training Set(id=fda) Not Found.",
"request_id": "d95c13be-5e64-11e8-8cb4-d680a9823a64"

}
FieldTypeDescription
messageStringDetailed error message
request_idStringThe unique ID of this request, it can be used in product issue debugging with ProductAI support team

Error Code

SDK/API notifies the client about whether the request success or fails via HTTP status code

HTTP Status Codeerror_codeDescription
200N/aCreating service successfully
4033004Created service amount exceeded account limit, please refer to account limitations
4042001Training set doesn’t exist

List Custom Training Services

Python

PHP

Java

cURL

from productai import Client

cli = Client(ACCESS_KEY_ID, SECRET_KEY)
api = cli.get_custom_training_api()
resp = api.list_services()
use ProductAI\Api;

$product_ai = new ProductAI\Api\TrainingSetApi(ACCESS_KEY_ID, SECRET_KEY);
$result = $product_ai->listTrainingSets();
import cn.productai.api.core.*;
import cn.productai.api.core.enums.*;
import cn.productai.apiv2.CustomTraining;
import cn.productai.apiv2.impl.CustomTrainingImpl;

IProfile profile = new DefaultProfile();
profile.setAccessKeyId(ACCESS_KEY_ID);
profile.setVersion("1");

CustomTraining customTraining = new CustomTrainingImpl();
customTraining.setProfile(profile);

String result = customTraining.listAllService();
System.out.println(result);
curl -X GET \
-H 'x-ca-version: 1.0' \
-H 'x-ca-accesskeyid: ACCESS_KEY_ID' \
https://api.productai.cn/custom_training/_0000194/services

Request

N/a

Response

{
"request_id": "f158f3ca-6f75-11e8-a528-d6abcabd1965",
"results": [
{
"created_at": "2018-06-06T01:46:34Z",
"creator_id": ...,
"description": "Foo Description",
"id": "276qb4gp",
"last_updated_at": "2018-06-06T01:46:42Z",
"message": "TrainingSet Does Not Have Enough Images For Training.",
"name": "Foo Service",
"scenario": "classifier",
"status": "failed",
"training_set_id": "pk72inyt"
}
]
}
FieldTypeDescription
request_idStringThe unique ID of this request, it can be used in product issue debugging with ProductAI support team
resultsArrayList all the customer’s running services, the field of single service please refer to Detailed ‘results’ Field Description

Detailed ‘results’ Field Description

FieldTypeDescription
descriptionStringService description
idStringService ID
messageStringThe detailed description of failure reason (only appears when the status field value is ‘failed’). E.g. The amount of training image is not sufficient, or most images cannot be downloaded.
nameStringService name
statusStringCurrent status of the service, see Detailed Service Status Description
training_set_idStringTraining set ID which is used for current service

Fetch Custom Training Service

Python

PHP

Java

cURL

from productai import Client

cli = Client(ACCESS_KEY_ID, SECRET_KEY)
api = cli.get_custom_training_api(SERVICE_ID)
resp = api.get_service()
use ProductAI\Api;

$product_ai = new ProductAI\Api\TrainingServiceApi(ACCESS_KEY_ID, SECRET_KEY);
$result = $product_ai->getService($serviceID=SERVICE_ID);
import cn.productai.api.core.*;
import cn.productai.api.core.enums.*;
import cn.productai.apiv2.CustomTraining;
import cn.productai.apiv2.impl.CustomTrainingImpl;

IProfile profile = new DefaultProfile();
profile.setAccessKeyId(ACCESS_KEY_ID);
profile.setVersion("1");

CustomTraining customTraining = new CustomTrainingImpl();
customTraining.setProfile(profile);

String result = customTraining.getServiceById(SERVICE_ID);
System.out.println(result);
curl -X GET \
-H 'x-ca-version: 1.0' \
-H 'x-ca-accesskeyid: ACCESS_KEY_ID' \
https://api.productai.cn/custom_training/_0000194/services/SERVICE_ID

Request

N/a

Response

Same as Create Service Response. ‘message’ field only appears when the status field value is ‘failed’, and it describes the detailed failed reason. For example, the amount of images is not suffient or too many images cannot be dowloaded.

Error Code

SDK/API notifies the client about whether the request success or fails via HTTP status code

HTTP Status Codeerror_codeDescription
200N/aSuccess
4042002Service doesn’t exist

Rename Custom Training Services

Python

PHP

Java

cURL

from productai import Client

cli = Client(ACCESS_KEY_ID, SECRET_KEY)
api = cli.get_custom_training_api(SERVICE_ID)
resp = api.update_service(name=NEW_NAME)
use ProductAI\Api;

$product_ai = new ProductAI\Api\TrainingServiceApi(ACCESS_KEY_ID, SECRET_KEY);
$result = $product_ai->updateService($serviceID=SERVICE_ID, ["name" => NEW_NAME]);
import cn.productai.api.core.*;
import cn.productai.api.core.enums.*;
import cn.productai.apiv2.CustomTraining;
import cn.productai.apiv2.impl.CustomTrainingImpl;

IProfile profile = new DefaultProfile();
profile.setAccessKeyId(ACCESS_KEY_ID);
profile.setVersion("1");

CustomTraining customTraining = new CustomTrainingImpl();
customTraining.setProfile(profile);

String result = customTraining.updateServiceName(SERVICE_ID, NEW_NAME);
System.out.println(result);
curl -X PUT \
-H 'x-ca-version: 1.0' \
-H 'x-ca-accesskeyid: ACCESS_KEY_ID' \
-H 'Content-Type: application/json' \
-d '{"name": "NEW_NAME"}' \
https://api.productai.cn/custom_training/_0000194/services/SERVICE_ID

Request

ArgumentTypeDescriptionRequiredLimitation
nameStringNew name of the custom training serviceYesN/a

Response

Same as Create Training Set Response

Error Code

SDK/API notifies the client about whether the request success or fails via HTTP status code

HTTP Status Codeerror_codeDescription
200N/aSuccess
4005004Service name cannot be null
4042002Service doesn’t exist

Delete Services

Python

PHP

Java

cURL

from productai import Client

cli = Client(ACCESS_KEY_ID, SECRET_KEY)
api = cli.get_custom_training_api(SERVICE_ID)
api.delete_service()
use ProductAI\Api;

$product_ai = new ProductAI\Api\TrainingServiceApi(ACCESS_KEY_ID, SECRET_KEY);
$result = $product_ai->deleteService($serviceID=SERVICE_ID);
import cn.productai.api.core.*;
import cn.productai.api.core.enums.*;
import cn.productai.apiv2.CustomTraining;
import cn.productai.apiv2.impl.CustomTrainingImpl;

IProfile profile = new DefaultProfile();
profile.setAccessKeyId(ACCESS_KEY_ID);
profile.setVersion("1");

CustomTraining customTraining = new CustomTrainingImpl();
customTraining.setProfile(profile);

String result = customTraining.deleteServiceById(SERVICE_ID);
System.out.println(result);
curl -X DELETE \
-H 'x-ca-version: 1.0' \
-H 'x-ca-accesskeyid: ACCESS_KEY_ID' \
https://api.productai.cn/custom_training/_0000194/services/SERVICE_ID

Request

N/a

Response

{
"request_id": "63a36ee2-6f76-11e8-b9eb-6a95ff447c19"
}

Error Code

SDK/API notifies the client about whether the request success or fails via HTTP status code

HTTP Status Codeerror_codeDescription
200N/aSuccess
4042002Service doesn’t exist

Predicting

Python

PHP

Java

cURL

from productai import Client

cli = Client(ACCESS_KEY_ID, SECRET_KEY)
api = cli.get_custom_training_api()

# Predicting by using URL of the image
resp = api.predict(image="http://xxxx.jpg")

# Predicting by uploading local image file
with open("zzzz.jpg", mode='rb') as q:
resp = api.predict(image=q)
use ProductAI\Api;

$product_ai = new ProductAI\Api\TrainingServiceApi(ACCESS_KEY_ID, SECRET_KEY);

// Predicting by using URL of the image
$result = $product_ai->predict($serviceID=SERVICE_ID, $image="http://xxxx.jpg");

// Predicting by uploading local image file
$result = $product_ai->predict($serviceID=SERVICE_ID, $image="./zzzz.jpg");
import cn.productai.api.core.*;
import cn.productai.api.core.enums.*;
import cn.productai.apiv2.CustomTraining;
import cn.productai.apiv2.impl.CustomTrainingImpl;

IProfile profile = new DefaultProfile();
profile.setAccessKeyId(ACCESS_KEY_ID);
profile.setVersion("1");

CustomTraining customTraining = new CustomTrainingImpl();
customTraining.setProfile(profile);

// Predicting by using URL of the image
String result = customTraining.predict(SERVICE_ID, "http://xxxx.jpg", null);

// Predicting by uploading local image file
String result = customTraining.predict(SERVICE_ID, null, "./zzzz.jpg");

System.out.println(result);
# Predicting by using file of the image
curl -X POST \
-H 'x-ca-version: 1.0' \
-H 'x-ca-accesskeyid: ACCESS_KEY_ID' \
-F "search=@./zzzz.jpg" \
https://api.productai.cn/custom_training/SERVICE_ID

# Predicting by using URL of the image
curl -X POST \
-H 'x-ca-version: 1.0' \
-H 'x-ca-accesskeyid: ACCESS_KEY_ID' \
-F "url=http://xxxx.jpg" \
https://api.productai.cn/custom_training/SERVICE_ID

Request

ArgumentTypeDescriptionRequiredLimitation
imageString or image file contentQuery of the predictingYesN/a

Response

{
"request_id": "cbab3410-5c3f-11e8-8cb4-d680a9823a64",
"results": [
{
"category": "patio",
"score": 0.9299805603279995
},
...
]
}
FieldTypeDescription
messageStringReturn detailed error message when HTTP status code is not 200
request_idStringThe unique ID of this request, it can be used in product issue debugging with ProductAI support team
resultsArrayContains tags and prediction scores of these tags. The contents of the array are sorted in descending order by the score field. See Predicting results details

Predicting results details

FieldTypeDescription
categoryStringLabels, predicting result of the model
scoreFloatPredicting scores on tags. The larger the score on the label, the higher the confidence.

Error Code

SDK/API notifies the client about whether the request success or fails via HTTP status code

HTTP Status Codeerror_codeDescription
200N/aSuccess
4002004Training process is not finish, the service is temporarily unavailable
4005005Invalid image type
4042002Service doesn’t exist
5004001Image failed to download
5004003Service failed to start