productAI

Image Classification

Classify/analyze image content and return label info

Basic Usage

Python

PHP

Java

C#

cURL

from productai import Client

cli = Client(ACCESS_KEY_ID, SECRET_KEY)

# Get service API context
api = cli.get_api('classify', '_xxxxxxxx')

# Call api with url as input parameter
resp = api.query('https://yyyy')

# Call api with local file as input parameter
with open("zzzz.jpg", mode='rb') as search:
resp = api.query(search)
use ProductAI;

// Get service API context
$product_ai = new ProductAI\API(ACCESS_KEY_ID, SECRET_KEY, 'zh-Hans');

// Call api with url as input parameter
$result = $product_ai->classifyImage('classify', '_xxxxxxxx', 'https://yyyy');

// Call api with local file as input parameter
$result = $product_ai->classifyImage('classify', '_xxxxxxxx', '@zzzz.jpg');
import java.io.File;
import cn.productai.api.core.*;
import cn.productai.api.core.enums.*;
import cn.productai.api.pai.entity.classify.*;

// Set API initializing parameters
IProfile profile = new DefaultProfile();
profile.setAccessKeyId(ACCESS_KEY_ID);
profile.setSecretKey(SECRET_KEY);
profile.setVersion("1");

IWebClient client = new DefaultProductAIClient(profile);

// Call api with url as input parameter
ClassifyByImageUrlRequest request = new ClassifyByImageUrlRequest("classify", "_xxxxxxxx");
request.setUrl("https://yyyy");

// Call api with local file as input parameter
ClassifyByImageFileRequest request = new ClassifyByImageFileRequest("classify", "_xxxxxxxx");
request.setImageFile(new File(".//zzzz.jpg"));

ClassifyResponse response = client.getResponse(request);
String json = response.getResponseJsonString();
using MalongTech.ProductAI.Core;
using MalongTech.ProductAI.API.Entity;

IProfile profile = new DefaultProfile
{
Version = "1",
AccessKeyId = ACCESS_KEY_ID,
SecretKey = SECRET_KEY,
};
var client = new DefaultProductAIClient(profile);

// Call api with url as input parameter
var request = new ClassifyByImageUrlRequest('classify', '_xxxxxxxx')
{
Url = "https://yyyy",
};

// Call api with local file as input parameter
var request = new ClassifyByImageFileRequest('classify', '_xxxxxxxx')
{
ImageFile = new System.IO.FileInfo(@"zzzz.jpg"),
};

var response = client.GetResponse(request);

curl -X POST \
-H 'x-ca-version: 1.0' \
-H 'x-ca-accesskeyid: ACCESS_KEY_ID' \
-d "url=https://yyyy" \
https://api.productai.com/classify/_xxxxxxxx

curl -X POST \
-H 'x-ca-version: 1.0' \
-H 'x-ca-accesskeyid: ACCESS_KEY_ID' \
-F "search=@zzzz.jpg" \
https://api.productai.com/classify/_xxxxxxxx

Note that ‘_xxxxxxxx’ indicates a specific classification service ID, please refer to service list

Request

ArgumentTypeDescriptionRequiredLimitation
urlStringImage urlYesShould specify one of the fields, url or search
searchFileImage fileYesShould specify one of the fields, url or search

Response

Return Http Status Code 200, When Success

{
"classify_time": "0.081",
"is_err": 0,
"request_id": "9c0745ea-dff9-11e7-914b-9e715a41c4bb",
"results": [
{
"category": "Non-porn",
"puid": "Non-porn",
"score": 0.999858
},
{
"category": "Porn",
"puid": "Porn",
"score": 0.000142
}
],
"version": "2.0.2"
}
FieldTypeDescription
classify_timeStringTime cost in seconds on ProductAPI service side
request_idStringUnique ID of this api call, it can be used in issue debugging with ProductAI support team
resultsArrayContains all the labels of query image
categoryStringlabel text under current language setting
puidStringUnique ID of label
scoreFloatProbability of label

Return Http Status Code Non-200, When Failed

Encountered error on server side

{
"data": {
"is_err": 1,
"msg": "Could not download http://a.com/b.jpg",
"request_id": "69d086c8-e142-11e7-bb18-eea500941bf4"
},
"status": 400
}
FieldTypeDescription
dataDictionaryContains all the fields
statusIntegerHTTP status code
is_errInteger1 indicates failure, 0 indicates success
messageStringDetailed error message
request_idStringThe unique ID of this request, this can be leveraged in product issue debugging with ProductAI support team

Error Code

HTTP status code is used by SDK/API to notify the client whether this api call is success or fail

HTTP Status Codeerror_codeDescription
200N/aSuccess
4032005Current account is not authorized to access this API service
4041001API service does not exist

Services

Scene Identification v1.0

Analyze image scene, return text labels as response. For multi-languages, please refer to Multi-language support

Python

PHP

Java

C#

cURL

# _0000039 is the ID of image analyze service
api = cli.get_api('classify', '_0000039')
// _0000039 is the ID of image analyze service, call service with image url as input
$result = $product_ai->classifyImage('classify', '_0000039', 'https://yyyy');

// _0000039 is the ID of image analyze service, call service with local image file as input
$result = $product_ai->classifyImage('classify', '_0000039', '@zzzz.jpg');
// _0000039 is the ID of image analyze service, call service with image url as input
ClassifyByImageUrlRequest request = new ClassifyByImageUrlRequest("classify", "_0000039");

// _0000039 is the ID of image analyze service, call service with local image file as input
ClassifyByImageFileRequest request = new ClassifyByImageFileRequest("classify", "_0000039");
// _0000039 is the ID of image analyze service, call service with image url as input
var request = new ClassifyByImageUrlRequest('classify', "_0000039")
{
Url = "https://yyyy",
};

// _0000039 is the ID of image analyze service, call service with local image file as input
var request = new ClassifyByImageFileRequest('classify', "_0000039")
{
ImageFile = new System.IO.FileInfo(@"zzzz.jpg"),
};

curl -X POST \
-H 'x-ca-version: 1.0' \
-H 'x-ca-accesskeyid: ACCESS_KEY_ID' \
-d "url=https://yyyy" \
https://api.productai.com/classify/_0000039

curl -X POST \
-H 'x-ca-version: 1.0' \
-H 'x-ca-accesskeyid: ACCESS_KEY_ID' \
-F "search=@zzzz.jpg" \
https://api.productai.com/classify/_0000039

Tags

Click here to download the list.

Pornography Identification v1.0

Determine if input image contains pornography content, return text labels as response

Python

PHP

Java

C#

cURL

# _0000024 is the ID of porn classification service
api = cli.get_api('classify', '_0000024')
// _0000024 is the ID of porn classification service, call service with image url as input
$result = $product_ai->detectImage('classify', '_0000024', 'https://yyyy');

// _0000024 is the ID of porn classification service, call service with local image file as input
$result = $product_ai->detectImage('classify', '_0000024', '@zzzz.jpg');
// _0000024 is the ID of porn classification service, call service with image url as input
ClassifyByImageUrlRequest request = new ClassifyByImageUrlRequest("classify", "_0000024");

// _0000024 is the ID of porn classification service, call service with local image file as input
ClassifyByImageFileRequest request = new ClassifyByImageFileRequest("classify", "_0000024");
// _0000024 is the ID of porn classification service, call service with image url as input
var request = new ClassifyByImageUrlRequest('classify', "_0000024")
{
Url = "https://yyyy",
};

// _0000024 is the ID of porn classification service, call service with local image file as input
var request = new ClassifyByImageFileRequest('classify', "_0000024")
{
ImageFile = new System.IO.FileInfo(@"zzzz.jpg"),
};

curl -X POST \
-H 'x-ca-version: 1.0' \
-H 'x-ca-accesskeyid: ACCESS_KEY_ID' \
-d "url=https://yyyy" \
https://api.productai.com/classify/_0000024

curl -X POST \
-H 'x-ca-version: 1.0' \
-H 'x-ca-accesskeyid: eACCESS_KEY_ID' \
-F "search=@zzzz.jpg" \
https://api.productai.com/classify/_0000024

Tags

Tags
Non-pornPorn

Image Quality Classifier v1.0

Identify whether image has been processed via typical e-commerce filters, such as collage, watermark, segmenting. Returns “good” if no filtering is detected, or “bad”.

Python

PHP

Java

C#

cURL

# _0000197 is the ID of Image Quality Classifier service
api = cli.get_api('classify', '_0000197')
// _0000197 is the ID of Image Quality Classifier service, call service with image url as input
$result = $product_ai->detectImage('classify', '_0000197', 'https://yyyy');

// _0000197 is the ID of Image Quality Classifier service, call service with local image file as input
$result = $product_ai->detectImage('classify', '_0000197', '@zzzz.jpg');
// _0000197 is the ID of Image Quality Classifier service, call service with image url as input
ClassifyByImageUrlRequest request = new ClassifyByImageUrlRequest("classify", "_0000197");

// _0000197 is the ID of Image Quality Classifier service, call service with local image file as input
ClassifyByImageFileRequest request = new ClassifyByImageFileRequest("classify", "_0000197");
// _0000197 is the ID of Image Quality Classifier service, call service with image url as input
var request = new ClassifyByImageUrlRequest('classify', "_0000197")
{
Url = "https://yyyy",
};

// _0000197 is the ID of Image Quality Classifier service, call service with local image file as input
var request = new ClassifyByImageFileRequest('classify', "_0000197")
{
ImageFile = new System.IO.FileInfo(@"zzzz.jpg"),
};

curl -X POST \
-H 'x-ca-version: 1.0' \
-H 'x-ca-accesskeyid: ACCESS_KEY_ID' \
-d "url=https://yyyy" \
https://api.productai.com/classify/_0000197

curl -X POST \
-H 'x-ca-version: 1.0' \
-H 'x-ca-accesskeyid: eACCESS_KEY_ID' \
-F "search=@zzzz.jpg" \
https://api.productai.com/classify/_0000197

Tags

Tags
goodbad

Interior Space Tagging v1.0

The interior space tagging service can analyze query pictures and return tags that describe the scene within the picture.

Python

PHP

Java

C#

cURL

# _0000196 is the ID of Interior Space Tagging service
api = cli.get_api('classify', '_0000196')
// _0000196 is the ID of Interior Space Tagging service, call service with image url as input
$result = $product_ai->detectImage('classify', '_0000196', 'https://yyyy');

// _0000196 is the ID of Interior Space Tagging service, call service with local image file as input
$result = $product_ai->detectImage('classify', '_0000196', '@zzzz.jpg');
// _0000196 is the ID of Interior Space Tagging service, call service with image url as input
ClassifyByImageUrlRequest request = new ClassifyByImageUrlRequest("classify", "_0000196");

// _0000196 is the ID of Interior Space Tagging service, call service with local image file as input
ClassifyByImageFileRequest request = new ClassifyByImageFileRequest("classify", "_0000196");
// _0000196 is the ID of Interior Space Tagging service, call service with image url as input
var request = new ClassifyByImageUrlRequest('classify', "_0000196")
{
Url = "https://yyyy",
};

// _0000196 is the ID of Interior Space Tagging service, call service with local image file as input
var request = new ClassifyByImageFileRequest('classify', "_0000196")
{
ImageFile = new System.IO.FileInfo(@"zzzz.jpg"),
};
# Call service with url as input parameter
curl -X POST \
-H 'x-ca-version: 1.0' \
-H 'x-ca-accesskeyid: ACCESS_KEY_ID' \
-d "url=https://yyyy" \
https://api.productai.com/classify/_0000196

# Call service with local file as input parameter
curl -X POST \
-H 'x-ca-version: 1.0' \
-H 'x-ca-accesskeyid: eACCESS_KEY_ID' \
-F "search=@zzzz.jpg" \
https://api.productai.com/classify/_0000196

Tags

Tags
dining_roomtea_roomkitchenchildrens_bedroom
living_roomstaircasepatiostudy
courtyardbathroombedroomentrance
balconywalk_in_closethallway