NAV Navbar
shell python java php javascript ruby go
  • 简介
  • 基础入门
  • 快速上手
  • 身份认证
  • 上传图片
  • 功能接口
  • 数据集接口
  • 常量
  • 错误
  • 常见问题
  • 简介

    AIFashion极睿科技 (Infimind) 旗下产品,寓意为 AI + Fashion,旨在打造更懂时尚的人工智能,专注 AI 在服装时尚领域的落地和应用。

    AIFashion 开放平台,下面简称 “开放平台”,通过 HTTP 协议对外提供服饰识别、分析和检索等 API 服务,帮助时尚领域的开发者轻松构建各种 AI 应用。

    文档内容

    本网站是开放平台开发者文档站,内容包括四大部分:

    示例代码

    这里是示例代码,可以通过 👆 的 tab 切换语言。

    echo "这里是 shell 代码"
    
    print "这里是 python 代码"
    
    System.out.printf("这里是 java 代码");
    
    <?php
    
    print_r("这里是 php 代码");
    
    console.log("这里是 javascript 代码");
    
    print "这里是 ruby 代码"
    
    package main
    
    import (
        "fmt"
    )
    
    func main() {
        fmt.Println("这里是 go 代码")
    }
    
    

    文档中介绍 API 调用的部分,会同时准备示例代码,方便开发者开发与调试。示例代码支持多种编程语言,包括:

    语言 依赖包
    shell curl
    python requests
    java Unirest
    php cURL
    javascript jQuery
    ruby -
    go -

    另外,您可以访问 开放平台开发者 站点,获取示例代码、多语言 SDK 等更多开发资源。

    GitHub 上,我们开源了 tutorial 和 example 工程,您可以按需使用,欢迎 pull request。

    强调内容

    文档中带背景颜色的段落,其颜色含义为:

    基础入门

    开放平台采用 HTTP+JSON 的 API 设计模式,遵循规范的、一致的调用逻辑。

    HTTP 协议是最简单的、可达性最好的网络通信协议之一,常用编程语言都能发起HTTP请求,开发者编写少量的代码便可调用我们的 API 服务。

    JSON 作为一种轻量级的数据交换格式,层次结构简洁清晰且数据传输效率高。

    我们在响应中一致使用 JSON 格式序列化返回结果,同时也推荐您在请求中使用 JSON 序列化请求参数。

    请求

    以 application/x-www-form-urlencoded 方式提交参数,例如:

    curl -X POST \
    https://api.aifashion.com/oauth2/token \
    -H 'content-type: application/x-www-form-urlencoded' \
    -d 'grant_type=client_credentials&client_id=<CLIENT_ID>&client_secret=<CLIENT_SECRET>'
    
    import requests
    
    token_url = 'https://api.aifashion.com/oauth2/token'
    
    resp = requests.post(token_url, data="grant_type=client_credentials&client_id=<CLIENT_ID>&client_secret=<CLIENT_SECRET>")
    

    以 application/json 方式提交参数,例如:

    curl -X POST \
    https://api.aifashion.com/fashion/detect \
    -H 'authorization: Bearer <ACCESS_TOKEN>' \
    -H 'content-type: application/json' \
    -d '{
        "image_url":"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg"
    }'
    
    import requests
    
    api_url = 'https://api.aifashion.com/fashion/detect'
    headers = {'Authorization': 'Bearer <ACCESS_TOKEN>'}
    
    resp = requests.post(api_url, headers=headers, json={"image_url":"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg"})
    

    以 multipart/form-data 方式提交数据,例如:

    curl -X POST \
    https://s.aifashion.com/upload \
    -F filename=@filename
    
    import requests
    
    upload_url = 'https://s.aifashion.com/upload'
    files = {'file': open('localimagefile', 'rb')}
    
    resp = requests.post(upload_url, files=files)
    

    开放平台支持标准 HTTP 请求,支持 GET、POST、PUT、PATCH 和 DELETE 方法。

    请求参数支持多种 Content-Type,包括:

    Content-Type 描述 适用场景
    application/x-www-form-urlencoded 以 urlencode 的方式提交数据 提交简单参数
    application/json 以 JSON 序列化的方式提交数据 提交结构复杂的参数
    multipart/form-data 以表单的方式提交数据 上传图片文件

    响应

    API 调用结果为标准 HTTP 响应,包括状态码和内容。

    响应状态码的定义和 RFC 规范可以参照 百度百科,常见错误可以参考 错误>协议错误 章节。

    响应内容使用 JSON 序列化,其中字段包括:

    响应内容一般样式为:

    {
        "code": 100,
        "message": "Success",
        "data": {
            "request_id": "359e2de7-be9a-46c4-9854-ce065f21d86f#5184"
            ...
        }
    }
    
    字段名 字段值类型 描述
    code Integer API 逻辑状态码
    message String API 逻辑状态信息
    data JSON API 逻辑结果内容

    code 为 100 时,代表 API 调用正确,此时,message 为 Success,data 中包含 API 返回结果。

    code 不为 100 时,代表 API 调用出现了逻辑错误,此时,message 包含逻辑错误信息,参照 错误>逻辑错误 章节。

    规范

    开放平台 API 的设计遵循一致的逻辑和规范,如下:

    安全信道

    总是使用 HTTPS 访问 API,保证敏感数据的安全性。未加密的请求将返回 403 Forbidden。

    版本

    使用 HTTP 请求头中的 Accept 字段发送版本信息,如:

    Accept: application/vnd.aifashion+json; version=1

    全局唯一标识

    API 的响应结果中包含全局唯一标识 request_id

    request_id 贯穿 API 调用的整个生命周期,记录在日志中,方便开发者跟踪和调试。

    标准时间戳

    为资源提供默认的 created_atupdated_atdeleted_at 时间戳,记录数据变化的关键时间点。

    时间戳使用 ISO8601 格式的 UTC 时间。一般格式为:

    YYYY-MM-DDTHH:MM:SSZ

    结构错误信息

    为错误生成一致的,结构化的响应,包含机器可读的 code 和人类可读的 message。

    code 为 100 时,代表 API 调用正确,此时,message 为 Success,data 中包含 API 返回结果。

    code 不为 100 时,代表 API 调用出现了逻辑错误,此时,message 包含逻辑错误信息,参照 错误>逻辑错误 章节。

    频率限制

    响应头中的频率限制信息:

    HTTP/1.1 200 OK
    Date: Thu, 05 Jul 2018 02:15:16 GMT
    Content-Type: application/json
    Content-Length: 1216
    Connection: keep-alive
    X-RateLimit-Limit-day: 600
    X-RateLimit-Remaining-day: 596
    X-RateLimit-Limit-minute: 60
    X-RateLimit-Remaining-minute: 59
    X-RateLimit-Limit-hour: 200
    X-RateLimit-Remaining-hour: 196
    X-RateLimit-Limit-second: 1
    X-RateLimit-Remaining-second: 0
    

    为了保证开放平台服务的健康稳定,我们对 API 调用进行了频率限制。

    频率限制状态信息会显示在 HTTP 响应头中,方便开发者调试,这些信息包括:

    关键字 描述
    X-RateLimit-Limit-second 每秒限制访问次数
    X-RateLimit-Limit-minute 每分钟限制访问次数
    X-RateLimit-Limit-hour 每小时限制访问次数
    X-RateLimit-Limit-day 每天限制访问次数
    X-RateLimit-Remaining-second 当前秒内剩余访问次数
    X-RateLimit-Remaining-minute 当前分钟内剩余访问次数
    X-RateLimit-Remaining-hour 当前小时内剩余访问次数
    X-RateLimit-Remaining-day 当前天内剩余访问次数

    如果调用频率超出了限制,服务器会返回状态码为 429 的协议错误,具体参照 错误>协议错误 章节。

    快速上手

    我们以 相似服饰检索 为例,介绍开放平台的使用方法,方便您快速上手。

    相似服饰检索 API 的功能是,在指定的数据集中,找到上传图片中服饰的相似服饰条目,其中,数据集和条目的概念可以参照 数据集接口 中关于实体的介绍。

    相似服饰检索的效果如下图:

    Alt text

    图片左侧为用户上传照片,右侧为相似服饰检索 API 在指定数据集上的返回结果。结果中包含了指定数量的和上传图片视觉相似的服饰条目,并按照相似程度排序。

    该 API 适用于拍照购物,以图搜图等场景。

    后面几小节,我们将逐步介绍从申请账号到调用接口的整套流程。

    申请账号

    为了使用开放平台 API,您首先需要到 开放平台 申请账号并等待审核通过。

    审核通过后,您可以登录到 开放平台控制台,如下图:

    Alt text

    同步数据

    相似服饰检索 API 需要指定搜索范围,在使用前,您需要先创建数据集并将您的商品数据同步到数据集条目。数据集和条目的概念参照 数据集接口 章节。

    我们提供两种同步数据方式,

    通过控制台

    1.登录控制台,在左侧菜单中点选 数据集管理>创建数据集,进入创建数据集页面,填入信息并完成创建,如下图:

    Alt text

    2.创建数据集后,在左侧菜单中点选 数据集管理>数据集列表,进入数据集列表页,选择数据集,进入数据集管理页,如下图:

    Alt text

    3.在数据集管理页,点击添加商品,进入商品添加页,填入信息完成添加,如下图:

    Alt text

    重复上述第 2 和 3 步,完成全部商品信息的同步。

    通过数据集接口

    控制台提供图形化界面管理数据集,适用于简单操作。当需要同步的商品条目过多时,控制台操作效率变得低下,建议使用 数据及接口

    数据集接口同步数据的过程和控制台类似,可以分为创建数据集、添加条目两个步骤。

    接口的具体调用方法请参照 创建数据集创建商品条目 两个小节。

    创建应用

    同步商品数据后,我们可以创建应用并开始使用开放平台接口了。

    1.登录控制台,点击左侧菜单栏中的 应用管理>创建应用,进入创建应用页面,按照提示填入必要信息。其中,接口选择智能检索中的相似服饰检索,数据集选择刚刚创建的数据集,如下图:

    Alt text

    2.点击 应用管理>应用列表,进入应用列表页,点击应用进入应用管理页面并来到页面最下方,获取接口授权凭证 application id 和 application secret,如下图:

    Alt text

    授权认证

    获取 access token

    curl -X POST \
    https://api.aifashion.com/oauth2/token \
    -H "Content-type: application/json" \
    -d '{
        "client_id": "<APPLICATION_ID>", 
        "client_secret":"<APPLICATION_SECRET>", 
        "grant_type": "client_credentials"
    }'
    

    上面命令返回如下结果:

    {
      "access_token": "57ed301af04bf35b40f255feb5ef469ab2f046aff14",
      "expires_in": 7200,
      "token_type": "bearer"
    }
    

    使用刚刚拿到的 application id 和 application secret,访问我们的 API 网关进行身份认证,获取调用 API 需要的访问令牌,即 access_token。

    这里我们使用 OAuth2 的 Client Credentials 模式进行身份认证,详细文档请参考 身份认证>获取访问令牌 小节。

    示例代码和结果如右侧。

    HTTP 请求

    POST https://api.aifashion.com/oauth2/token

    HTTP 响应

    返回结果中的 access_token 字段为后续调用 API 需要的访问令牌。

    调用接口

    调用接口

    curl -X POST \
    https://api.aifashion.com/fashion/imgsearch \
    -H "Content-type: application/json" \
    -H "Authorization: Bearer <ACCESS_TOKEN>" \
    -d '{
        "image_url":"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg",
        "dataset_name":"products"
    }'
    
    import requests
    
    url = "https://api.aifashion.com/fashion/imgsearch"
    
    payload = "{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\",\"dataset_name\":\"products\"}"
    
    headers = {
        'authorization': "Bearer <ACCESS_TOKEN>"
    }
    
    response = requests.request("POST", url, json=payload, headers=headers)
    
    HttpResponse<JsonNode> response = Unirest.post("https://api.aifashion.com/fashion/imgsearch")
        .header("accept", "application/json")
        .header("content-type", "application/json")
        .header("authorization", "Bearer <ACCESS_TOKEN>")
        .body("{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\",\"dataset_name\":\"products\"}")
        .asJson();
    
    <?php
    
    $curl = curl_init();
    
    curl_setopt_array($curl, array(
        CURLOPT_URL => "https://api.aifashion.com/fashion/imgsearch",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_POSTFIELDS => "{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\",\"dataset_name\":\"products\"}",
        CURLOPT_HTTPHEADER => array(
            "authorization: Bearer <ACCESS_TOKEN>",
            "content-type: application/json"
        ),
    ));
    
    $response = curl_exec($curl);
    
    var settings = {
        "async": true,
        "crossDomain": true,
        "url": "https://api.aifashion.com/fashion/imgsearch",
        "method": "POST",
        "headers": {
            "content-type": "application/json",
            "authorization": "Bearer <ACCESS_TOKEN>"
        },
        "processData": false,
        "data": "{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\",\"dataset_name\":\"products\"}"
    }
    
    $.ajax(settings).done(function (response) {
        console.log(response);
    });
    
    require 'uri'
    require 'net/http'
    
    url = URI("https://api.aifashion.com/fashion/imgsearch")
    
    http = Net::HTTP.new(url.host, url.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    
    request = Net::HTTP::Post.new(url)
    request["content-type"] = 'application/json'
    request["authorization"] = 'Bearer <ACCESS_TOKEN>'
    request.body = "{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\",\"dataset_name\":\"products\"}"
    
    response = http.request(request)
    
    package main
    
    import (
        "strings"
        "net/http"
        "io/ioutil"
    )
    
    func main() {
        url := "https://api.aifashion.com/fashion/imgsearch"
        payload := strings.NewReader("{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\",\"dataset_name\":\"products\"}")
    
        req, _ := http.NewRequest("POST", url, payload)
        req.Header.Add("content-type", "application/json")
        req.Header.Add("authorization", "Bearer <ACCESS_TOKEN>")
    
        res, _ := http.DefaultClient.Do(req)
        defer res.Body.Close()
        body, _ := ioutil.ReadAll(res.Body)
    }
    

    上面命令返回如下结果:

    {
        "code": 100,
        "message": "Success",
        "data": {
            "request_id": "16bdc4ee-25e8-4dea-8ba8-8ba18d0d54cf#5803",
            "image": {
                "id": "ef4bae7de3407938e0728427ec9f2f93",
                "url": "https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg",
                "width": 1200,
                "height": 1666
            },
            "object": {
                "category": "上衣",
                "category_id": 200,
                "confidence": 0.9732170104980469,
                "region": {
                    "x1": 0.2910948395729065,
                    "x2": 0.6117150187492371,
                    "y1": 0.23169997334480286,
                    "y2": 0.5400047302246094
                }
            },
            "similar_items": [
                {
                    "id": "5b2b82bab2f60626d8644b9f",
                    "product_id": "1234567890",
                    "name": "name",
                    "description": "",
                    "category": "category1",
                    "images": [
                        "http://a.com/1.jpg",
                        "https://a.com/2.jpg"
                    ],
                    "attributes": [
                        {
                            "key": "key1",
                            "value": "value1"
                        },
                        {
                            "key": "key2",
                            "value": "value2"
                        }
                    ]
                },
                {
                    "id": "5b2b82bab2f60626d8644b5b",
                    "product_id": "1234567891",
                    "name": "name1",
                    "description": "",
                    "category": "category2",
                    "images": [
                        "http://a.com/3.jpg",
                        "https://a.com/4.jpg"
                    ],
                    "attributes": [
                        {
                            "key": "key1",
                            "value": "value3"
                        },
                        {
                            "key": "key2",
                            "value": "value4"
                        }
                    ]
                }
            ]
        }
    }
    

    得到 access_token 后,我们可以访问 API 网关调用相似服饰检索 API 了,access_token 的使用方法请参照 身份认证>使用令牌 小节。

    开放平台接口遵循 HTTP+JSON API 标准,调用方法请参照 基础入门 章节,使用前请阅读一般 基础入门>规范

    示例代码和结果如右侧。

    HTTP 请求

    POST https://api.aifashion.com/fashion/imgsearch

    请求的详细规范请参照 基础入门>请求 小节,相似服饰检索 API 请求的详细参数请参照 功能接口>搜索同款 小节。

    HTTP 响应

    响应结果内容结构请参照 基础入门>响应 小节。

    响应结果内容具体含义请参照 功能接口>搜索同款 小节。

    身份认证

    开放平台上的 API 为授权使用,所有 API 的调用都需要身份认证。

    为了使用开放平台 API,您需要进行三个步骤:

    1. 获取认证凭证,即 application_id 和 application_secret
    2. 认证并获取访问令牌,即 access_token
    3. 使用访问令牌调用 API

    下面几个小节将对这几个步骤进行详细介绍。

    使用正确的 access_token,服务器将正常响应并返回结果;没有使用或使用错误的 access_token,服务器将返回状态码为 401 的协议错误,详细错误信息参照 错误>协议错误 章节。

    获取认证凭证

    身份认证前,您需要先获取认证凭证。

    首先,您需要到 控制台 申请账户并等待审核通过。

    通过审核后,您可以登录控制台,按需创建应用并在应用管理页面获取 application id 和 application secret 。如下图:

    TODO 应用管理图

    认证流程

    开放平台身份认证使用标准 OAuth2 协议,OAuth2 的详细介绍可以参照 官方文档

    OAuth2 Endpoint 如下:

    开放平台当前支持 Authorization Code 和 Client Credentials 两种 OAuth2 授权模式。

    其中,Authorization Code 授权模式流程复杂,用于对安全性要求较高的应用场景;Client Credentials 授权模式是 Authorization Code 的简化版本。

    下面以 Client Credentials 为例演示认证流程。

    获取访问令牌

    获取 access_token

    curl -X POST \
    https://api.aifashion.com/oauth2/token \
    -H "Content-type: application/x-www-form-urlencoded" \
    -d 'grant_type=client_credentials&client_id=<APPLICATION_ID>&client_secret=<APPLICATION_SECRET>'
    
    import requests
    
    url = "https://api.aifashion.com/oauth2/token"
    
    payload = "grant_type=client_credentials&client_id=<APPLICATION_ID>&client_secret=<APPLICATION_SECRET>"
    headers = {
        'content-type': "application/x-www-form-urlencoded"
    }
    
    response = requests.request("POST", url, data=payload, headers=headers)
    
    HttpResponse<JsonNode> response = Unirest.post("https://api.aifashion.com/oauth2/token")
        .header("accept", "application/json")
        .header("content-type", "application/x-www-form-urlencoded")
        .body("grant_type=client_credentials&client_id=<APPLICATION_ID>&client_secret=<APPLICATION_SECRET>")
        .asJson();
    
    <?php
    
    $curl = curl_init();
    
    curl_setopt_array($curl, array(
        CURLOPT_URL => "https://api.aifashion.com/oauth2/token",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_POSTFIELDS => "grant_type=client_credentials&client_id=<APPLICATION_ID>&client_secret=<APPLICATION_SECRET>",
        CURLOPT_HTTPHEADER => array(
            "content-type: application/x-www-form-urlencoded"
        ),
    ));
    
    $response = curl_exec($curl);
    
    var settings = {
        "async": true,
        "crossDomain": true,
        "url": "https://api.aifashion.com/oauth2/token",
        "method": "POST",
        "headers": {
            "content-type": "application/x-www-form-urlencoded"
        },
        "data": {
            "grant_type": "client_credentials",
            "client_id": "<APPLICATION_ID>",
            "client_secret": "<APPLICATION_SECRET>"
        }
    }
    
    $.ajax(settings).done(function (response) {
        console.log(response);
    });
    
    
    require 'uri'
    require 'net/http'
    
    url = URI("https://api.aifashion.com/oauth2/token")
    
    http = Net::HTTP.new(url.host, url.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    
    request = Net::HTTP::Post.new(url)
    request["content-type"] = 'application/x-www-form-urlencoded'
    request.body = "grant_type=client_credentials&client_id=<APPLICATION_ID>&client_secret=<APPLICATION_SECRET>"
    
    response = http.request(request)
    
    package main
    
    import (
        "strings"
        "net/http"
        "io/ioutil"
    )
    
    func main() {
        url := "https://api.aifashion.com/oauth2/token"
        payload := strings.NewReader("grant_type=client_credentials&client_id=<APPLICATION_ID>&client_secret=<APPLICATION_SECRET>")
    
        req, _ := http.NewRequest("POST", url, payload)
        req.Header.Add("content-type", "application/x-www-form-urlencoded")
    
        res, _ := http.DefaultClient.Do(req)
    
        defer res.Body.Close()
        body, _ := ioutil.ReadAll(res.Body)
    }
    
    

    上面命令返回如下结果:

    {
        "token_type": "bearer",
        "access_token": "IBRoMH7sRhIAzUsXPRXt3cUTUlx8gIgc",
        "expires_in": 7200
    }
    

    使用 application_id 和 application_secret 获取 access_token。

    HTTP 请求

    POST https://api.aifashion.com/oauth2/token

    请求参数

    参数名 参数值类型 描述
    client_id String 前面获取到的 application_id
    client_secret String 前面获取到的 application_secret
    grant_type String 授权模式,这里为 client_credentials

    HTTP 响应

    返回结果中包含:

    字段 描述
    token_type 令牌类型,一般为 Bearer,和 access_token 一起构成授权字符串
    access_token 访问令牌
    expires_in 生命期,单位为秒

    使用令牌

    使用 access_token 访问 API

    curl -X POST \
    https://api.aifashion.com/someapi \
    -H 'authorization: Bearer <ACCESS_TOKEN>' \
    -H 'content-type: application/json' \
    -d '{
        "image_url":"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg"
    }'
    
    import requests
    
    url = "https://api.aifashion.com/someapi"
    
    payload = { "image_url": "https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg" }
    
    headers = {
        'authorization': "Bearer <ACCESS_TOKEN>"
    }
    
    response = requests.request("POST", url, json=payload, headers=headers)
    
    HttpResponse<JsonNode> response = Unirest.post("https://api.aifashion.com/someapi")
        .header("accept", "application/json")
        .header("content-type", "application/json")
        .header("authorization", "Bearer <ACCESS_TOKEN>")
        .body("{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\"}")
        .asJson();
    
    <?php
    
    $curl = curl_init();
    
    curl_setopt_array($curl, array(
        CURLOPT_URL => "https://api.aifashion.com/someapi",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_POSTFIELDS => "{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\"}",
        CURLOPT_HTTPHEADER => array(
            "authorization: Bearer <ACCESS_TOKEN>",
            "content-type: application/json"
        ),
    ));
    
    $response = curl_exec($curl);
    
    var settings = {
        "async": true,
        "crossDomain": true,
        "url": "https://api.aifashion.com/someapi",
        "method": "POST",
        "headers": {
            "content-type": "application/json",
            "authorization": "Bearer <ACCESS_TOKEN>"
        },
        "processData": false,
        "data": "{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\"}"
    }
    
    $.ajax(settings).done(function (response) {
        console.log(response);
    });
    
    require 'uri'
    require 'net/http'
    
    url = URI("https://api.aifashion.com/someapi")
    
    http = Net::HTTP.new(url.host, url.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    
    request = Net::HTTP::Post.new(url)
    request["content-type"] = 'application/json'
    request["authorization"] = 'Bearer <ACCESS_TOKEN>'
    request.body = "{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\"}"
    
    response = http.request(request)
    
    package main
    
    import (
        "strings"
        "net/http"
        "io/ioutil"
    )
    
    func main() {
        url := "https://api.aifashion.com/someapi"
        payload := strings.NewReader("{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\"}")
    
        req, _ := http.NewRequest("POST", url, payload)
        req.Header.Add("content-type", "application/json")
        req.Header.Add("authorization", "Bearer <ACCESS_TOKEN>")
    
        res, _ := http.DefaultClient.Do(req)
        defer res.Body.Close()
        body, _ := ioutil.ReadAll(res.Body)
    }
    

    使用上面获取到的 access_token 访问 API。

    HTTP 请求

    POST https://api.aifashion.com/someapi

    在 HTTP header 中,增加 Authorization 字段,并将键值指定为刚刚获取的 access_token,键值的类型为 Bearer。

    刷新令牌

    访问令牌具有生命周期,过期的令牌不具有访问权限,需要刷新。

    令牌刷新操作可以参照 OAuth2 的 RFC 文档,授权模式为 Client Credentials 的令牌过期时,直接申请新的令牌即可。

    上传图片

    使用 image_url

    curl -X POST \
    https://api.aifashion.com/someapi \
    -H 'authorization: Bearer <ACCESS_TOKEN>' \
    -H 'content-type: application/json' \
    -d '{
        "image_url":"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg"
    }'
    
    import requests
    
    url = "https://api.aifashion.com/someapi"
    
    payload = { "image_url": "https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg" }
    
    headers = {
        'authorization': "Bearer <ACCESS_TOKEN>"
    }
    
    response = requests.request("POST", url, json=payload, headers=headers)
    
    HttpResponse<JsonNode> response = Unirest.post("https://api.aifashion.com/someapi")
        .header("accept", "application/json")
        .header("content-type", "application/json")
        .header("authorization", "Bearer <ACCESS_TOKEN>")
        .body("{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\"}")
        .asJson();
    
    <?php
    
    $curl = curl_init();
    
    curl_setopt_array($curl, array(
        CURLOPT_URL => "https://api.aifashion.com/someapi",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_POSTFIELDS => "{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\"}",
        CURLOPT_HTTPHEADER => array(
            "authorization: Bearer <ACCESS_TOKEN>",
            "content-type: application/json"
        ),
    ));
    
    $response = curl_exec($curl);
    
    var settings = {
        "async": true,
        "crossDomain": true,
        "url": "https://api.aifashion.com/someapi",
        "method": "POST",
        "headers": {
            "content-type": "application/json",
            "authorization": "Bearer <ACCESS_TOKEN>"
        },
        "processData": false,
        "data": "{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\"}"
    }
    
    $.ajax(settings).done(function (response) {
        console.log(response);
    });
    
    require 'uri'
    require 'net/http'
    
    url = URI("https://api.aifashion.com/someapi")
    
    http = Net::HTTP.new(url.host, url.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    
    request = Net::HTTP::Post.new(url)
    request["content-type"] = 'application/json'
    request["authorization"] = 'Bearer <ACCESS_TOKEN>'
    request.body = "{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\"}"
    
    response = http.request(request)
    
    package main
    
    import (
        "strings"
        "net/http"
        "io/ioutil"
    )
    
    func main() {
        url := "https://api.aifashion.com/someapi"
        payload := strings.NewReader("{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\"}")
    
        req, _ := http.NewRequest("POST", url, payload)
        req.Header.Add("content-type", "application/json")
        req.Header.Add("authorization", "Bearer <ACCESS_TOKEN>")
    
        res, _ := http.DefaultClient.Do(req)
        defer res.Body.Close()
        body, _ := ioutil.ReadAll(res.Body)
    }
    

    使用 image_base64

    curl -X POST \
    https://api.aifashion.com/someapi \
    -H 'authorization: Bearer <ACCESS_TOKEN>' \
    -H 'content-type: application/json' \
    -d '{
        "image_base64":"/9j/4AAQSkZJRgABAQEASABIAAD/2w..."
    }'
    
    import requests
    
    url = "https://api.aifashion.com/someapi"
    
    payload = { "image_url": "https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg" }
    
    headers = {
        'authorization': "Bearer <ACCESS_TOKEN>"
    }
    
    response = requests.request("POST", url, json=payload, headers=headers)
    
    HttpResponse<JsonNode> response = Unirest.post("https://api.aifashion.com/someapi")
        .header("accept", "application/json")
        .header("content-type", "application/json")
        .header("authorization", "Bearer <ACCESS_TOKEN>")
        .body("{\"image_base64\":\"/9j/4AAQSkZJRgABAQEASABIAAD/2w...\"}")
        .asJson();
    
    <?php
    
    $curl = curl_init();
    
    curl_setopt_array($curl, array(
        CURLOPT_URL => "https://api.aifashion.com/someapi",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_POSTFIELDS => "{\"image_base64\":\"/9j/4AAQSkZJRgABAQEASABIAAD/2w...\"}",
        CURLOPT_HTTPHEADER => array(
            "authorization: Bearer <ACCESS_TOKEN>",
            "content-type: application/json"
        ),
    ));
    
    $response = curl_exec($curl);
    
    var settings = {
        "async": true,
        "crossDomain": true,
        "url": "https://api.aifashion.com/someapi",
        "method": "POST",
        "headers": {
            "content-type": "application/json",
            "authorization": "Bearer <ACCESS_TOKEN>"
        },
        "processData": false,
        "data": "{\"image_base64\":\"/9j/4AAQSkZJRgABAQEASABIAAD/2w...\"}"
    }
    
    $.ajax(settings).done(function (response) {
        console.log(response);
    });
    
    require 'uri'
    require 'net/http'
    
    url = URI("https://api.aifashion.com/someapi")
    
    http = Net::HTTP.new(url.host, url.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    
    request = Net::HTTP::Post.new(url)
    request["content-type"] = 'application/json'
    request["authorization"] = 'Bearer <ACCESS_TOKEN>'
    request.body = "{\"image_base64\":\"/9j/4AAQSkZJRgABAQEASABIAAD/2w...\"}"
    
    response = http.request(request)
    
    package main
    
    import (
        "strings"
        "net/http"
        "io/ioutil"
    )
    
    func main() {
        url := "https://api.aifashion.com/someapi"
        payload := strings.NewReader("{\"image_base64\":\"/9j/4AAQSkZJRgABAQEASABIAAD/2w...\"}")
    
        req, _ := http.NewRequest("POST", url, payload)
        req.Header.Add("content-type", "application/json")
        req.Header.Add("authorization", "Bearer <ACCESS_TOKEN>")
    
        res, _ := http.DefaultClient.Do(req)
        defer res.Body.Close()
        body, _ := ioutil.ReadAll(res.Body)
    }
    

    开放平台上计算机视觉相关的 API 需要用户上传图片作为输入,现在我们支持两种上传图片的方法:

    提交图片信息需要包含在 HTTP 请求参数中。

    参数名 类型 描述
    image_url String 公网可访问到的图片 URL 地址
    image_base64 String 图片二进制数据的 base64 编码

    image_url 和 image_base64 二选一即可。

    使用存储服务

    表单上传图片:

    curl -X POST \
    https://s.aifashion.com/upload \
    -F filename=@localimagefile
    
    import requests
    
    upload_url = 'https://s.aifashion.com/upload'
    files = {'file': open('localimagefile', 'rb')}
    
    resp = requests.post(upload_url, files=files)
    
    HttpResponse<JsonNode> jsonResponse = Unirest.post("https://s.aifashion.com/upload")
        .header("accept", "application/json")
        .field("file", new File("localimagefile"))
        .asJson();
    
    <?php
    
    $curl = curl_init();
    
    $files = array('file' => new CURLFile('localimagefile'));
    
    curl_setopt_array($curl, array(
        CURLOPT_URL => "https://s.aifashion.com/upload",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_POSTFIELDS => $files,
        CURLOPT_HTTPHEADER => array(
            "content-type: multipart/form-data"
        ),
    ));
    
    $response = curl_exec($curl);
    
    var files = new FormData();
    files.append("file", "localimagefile");
    
    var settings = {
        "async": true,
        "crossDomain": true,
        "url": "https://s.aifashion.com/upload",
        "method": "POST",
        "mimeType": "multipart/form-data",
        "data": files
    }
    
    $.ajax(settings).done(function (response) {
        console.log(response);
    });
    
    require 'uri'
    require 'net/http'
    
    url = URI("https://s.aifashion.com/upload")
    
    http = Net::HTTP.new(url.host, url.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    
    request = Net::HTTP::Post::Multipart.new(url, "file" => UploadIO.new("localimagefile", "image/jpeg", "image.jpg"))
    request["content-type"] = 'multipart/form-data'
    
    response = http.request(request)
    
    package main
    
    import (
        "bytes"
        "io/ioutil"
        "mime/multipart"
        "net/http"
    )
    
    file, _ := os.Open("localimagefile")
    defer file.Close()
    
    bodyBuf := &bytes.Buffer{}
    bodyWriter := multipart.NewWriter(bodyBuf)
    
    fileWriter, _ := bodyWriter.CreateFormFile("file", "localimagefile")
    _, _ = io.Copy(fileWriter, file)
    
    contentType := bodyWriter.FormDataContentType()
    
    bodyWriter.Close()
    
    res, _ := http.Post(url, contentType, bodyBuf)
    defer res.Body.Close()
    
    body, _ := ioutil.ReadAll(resp.Body)
    

    上面命令返回如下结果:

    {
        "code": 100,
        "message": "Success",
        "data": {
            "image_id": "ef4bae7de3407938e0728427ec9f2f93",
            "image_url": "https:\/\/images.aifashion.com\/ef\/4b\/ae\/ef4bae7de3407938e0728427ec9f2f93.jpg",
        }
    }
    
    

    当您想用本地图片调用开放平台 API 时,您可以先将图片上传至 AIFashion Storage,然后再使用我们提供的 URL 调用 API。

    AIFashion Storage 图片存储服务,提供图片上传、暂存和下载等基本功能。

    上传方法

    AIFashion Storage 当前仅支持 Content-Type 为 multipart/form-data 的 HTTP POST 请求,即表单上传。右侧为示例代码。

    文件大小

    上传图片文件最大支持 2M,上传超过 2M 的图片将返回错误码为 413 的协议错误,即 Request Entity Too Large,请压缩后重新上传。

    图片格式

    图片格式当前支持:

    当图片无法打开或格式不支持时,会返回错误码为 400025 的逻辑错误,即 Image File Corrupted,请确认图片格式无误后重新上传。

    图片地址

    AIFashion Storage 将为您免费存储上传的文件,并提供公网可访问的 URL,URL格式为:

    https://images.aifashion.com/{HASH_PATH}/{HASH_FILENAME}

    例如:

    https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg。

    功能接口

    AIFashion 开放平台对外提供了包括计算机视觉、自然语言处理等领域的数十个 AI 功能接口,包括:

    方向 功能 描述 版本
    服饰检测 服饰检测 识别出图片中所有的服饰,给出分类、位置和置信度 v1
    单件服饰检测 识别出图片中最显著的一件衣服,给出分类、位置和置信度 v1
    指定服饰定位 在图片中找到指定的商品或服饰图像,给出位置和置信度 v1
    服饰语义分割 从图片中分割出所有服饰,给出类别、像素级分割区域和置信度 beta
    单件服饰语义分割 从图片中分割出最显著的一件服饰,给出类别、像素级分割区域和置信度 beta
    服饰关键点检测 检测出图片中指定服饰的关键点 v1
    时尚分析 时尚标签 为图片中指定服饰智能生成属性标签 v1
    服饰命名 为图片中指定服饰智能生成名字,支持多种语言 beta
    服饰颜色分析 智能分析图片中指定服饰的颜色信息 v1
    穿衣风格分析 智能分析图片中指定人物的穿衣风格 beta
    穿衣打分 智能为图片中指定任务的穿衣时尚度打分 alpha
    服饰吊牌OCR 使用OCR技术对服饰吊牌的内容进行识别 beta
    智能检索 相似服饰检索 从指定数据集中找到和指定服饰视觉相似的条目 v1
    搭配服饰检索 从指定数据集中找到和指定服饰时尚搭配的条目 beta
    人像分析 语义分割 从给定图片中对所有人像进行像素级的语义分割 v1
    人体关键点 从给定图片中对所有人的17个身体关键点进行定位 v1
    知识库 时尚知识库 beta
    机器翻译 服饰描述翻译 服饰描述专业级翻译,支持多种语言两两翻译 alpha

    服饰检测

    调用服饰检测 API

    curl -X POST \
    https://api.aifashion.com/fashion/detect \ 
    -H "Content-type: application/json" \
    -H "Authorization: Bearer <ACCESS_TOKEN>" \
    -d '{
        "image_url":"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg"
    }'
    
    import requests
    
    url = "https://api.aifashion.com/fashion/detect"
    
    payload = {
        'image_url': 'https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg'
    }
    
    headers = {
        'authorization': "Bearer <ACCESS_TOKEN>"
    }
    
    response = requests.request("POST", url, json=payload, headers=headers)
    
    HttpResponse<JsonNode> response = Unirest.post("https://api.aifashion.com/fashion/detect")
        .header("accept", "application/json")
        .header("content-type", "application/json")
        .header("authorization", "Bearer <ACCESS_TOKEN>")
        .body("{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\"}")
        .asJson();
    
    <?php
    
    $curl = curl_init();
    
    curl_setopt_array($curl, array(
        CURLOPT_URL => "https://api.aifashion.com/fashion/detect",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_POSTFIELDS => "{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\"}",
        CURLOPT_HTTPHEADER => array(
            "authorization: Bearer <ACCESS_TOKEN>",
            "content-type: application/json"
        ),
    ));
    
    $response = curl_exec($curl);
    
    var settings = {
        "async": true,
        "crossDomain": true,
        "url": "https://api.aifashion.com/fashion/detect",
        "method": "POST",
        "headers": {
            "content-type": "application/json",
            "authorization": "Bearer <ACCESS_TOKEN>"
        },
        "processData": false,
        "data": "{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\"}"
    }
    
    $.ajax(settings).done(function (response) {
        console.log(response);
    });
    
    require 'uri'
    require 'net/http'
    
    url = URI("https://api.aifashion.com/fashion/detect")
    
    http = Net::HTTP.new(url.host, url.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    
    request = Net::HTTP::Post.new(url)
    request["content-type"] = 'application/json'
    request["authorization"] = 'Bearer <ACCESS_TOKEN>'
    request.body = "{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\"}"
    
    response = http.request(request)
    
    package main
    
    import (
        "strings"
        "net/http"
        "io/ioutil"
    )
    
    func main() {
        url := "https://api.aifashion.com/fashion/detect"
        payload := strings.NewReader("{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\"}")
    
        req, _ := http.NewRequest("POST", url, payload)
        req.Header.Add("content-type", "application/json")
        req.Header.Add("authorization", "Bearer <ACCESS_TOKEN>")
    
        res, _ := http.DefaultClient.Do(req)
        defer res.Body.Close()
        body, _ := ioutil.ReadAll(res.Body)
    }
    

    上面命令返回如下结果:

    {
        "code": 100,
        "message": "Success",
        "data": {
            "request_id": "16bdc4ee-25e8-4dea-8ba8-8ba18d0d54cf#5803",
            "image": {
                "id": "ef4bae7de3407938e0728427ec9f2f93",
                "url": "https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg",
                "width": 1200,
                "height": 1666
            },
            "objects": [
                {
                    "category": "上衣",
                    "category_id": 101,
                    "confidence": 0.9732170104980469,
                    "region": {
                        "x1": 0.2910948395729065,
                        "x2": 0.6117150187492371,
                        "y1": 0.23169997334480286,
                        "y2": 0.5400047302246094
                    }
                }, 
                {
                    "category": "裤子",
                    "category_id": 201,
                    "confidence": 0.9998025298118591,
                    "region": {
                        "x1": 0.3177667260169983,
                        "x2": 0.5605792999267578,
                        "y1": 0.5061479210853577,
                        "y2": 0.8747797608375549
                    }
                },
                {
                    "category": "鞋靴",
                    "category_id": 401,
                    "confidence": 0.9982732534408569,
                    "region": {
                        "x1": 0.33513087034225464,
                        "x2": 0.5097233653068542,
                        "y1": 0.8630520701408386,
                        "y2": 0.9711063504219055
                    }
                }
            ]
        }
    }
    

    检测出图片中的所有服饰,给出每件服饰的类别、位置和置信度。

    例图如下:

    Alt text

    现支持的二级类别包括:上衣(101), 外套(102), 裤子(201), 连衣裙(301), 半身裙(302), 鞋靴(401), 箱包(501), 类别详细信息,请参照 常量 章节。

    HTTP 请求

    POST https://api.aifashion.com/fashion/detect

    请求参数

    参数名 参数值类型 描述
    image_url String 待识别图片 URL,公网可访问
    image_base64 String 待识别图片二进制数据的 base64 编码

    HTTP 响应结果

    响应结果中主要字段及描述如下:

    字段名 字段值类型 描述
    image Object 图片信息,包括 id、url 以及图的长和宽
    objects Array 检测结果数组,数组中每个对象为一件服饰

    单件服饰检测

    调用单件服饰检测 API

    curl -X POST \
    https://api.aifashion.com/fashion/detect-one \
    -H "Content-type: application/json" \
    -H "Authorization: Bearer <ACCESS_TOKEN>" \
    -d '{
        "image_url":"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg"
    }'
    
    import requests
    
    url = "https://api.aifashion.com/fashion/detect-one"
    
    payload = {
        'image_url': 'https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg'
    }
    
    headers = {
        'authorization': "Bearer <ACCESS_TOKEN>"
    }
    
    response = requests.request("POST", url, json=payload, headers=headers)
    
    HttpResponse<JsonNode> response = Unirest.post("https://api.aifashion.com/fashion/detect-one")
        .header("accept", "application/json")
        .header("content-type", "application/json")
        .header("authorization", "Bearer <ACCESS_TOKEN>")
        .body("{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\"}")
        .asJson();
    
    <?php
    
    $curl = curl_init();
    
    curl_setopt_array($curl, array(
        CURLOPT_URL => "https://api.aifashion.com/fashion/detect-one",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_POSTFIELDS => "{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\"}",
        CURLOPT_HTTPHEADER => array(
            "authorization: Bearer <ACCESS_TOKEN>",
            "content-type: application/json"
        ),
    ));
    
    $response = curl_exec($curl);
    
    var settings = {
        "async": true,
        "crossDomain": true,
        "url": "https://api.aifashion.com/fashion/detect-one",
        "method": "POST",
        "headers": {
            "content-type": "application/json",
            "authorization": "Bearer <ACCESS_TOKEN>"
        },
        "processData": false,
        "data": "{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\"}"
    }
    
    $.ajax(settings).done(function (response) {
        console.log(response);
    });
    
    require 'uri'
    require 'net/http'
    
    url = URI("https://api.aifashion.com/fashion/detect-one")
    
    http = Net::HTTP.new(url.host, url.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    
    request = Net::HTTP::Post.new(url)
    request["content-type"] = 'application/json'
    request["authorization"] = 'Bearer <ACCESS_TOKEN>'
    request.body = "{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\"}"
    
    response = http.request(request)
    
    package main
    
    import (
        "strings"
        "net/http"
        "io/ioutil"
    )
    
    func main() {
        url := "https://api.aifashion.com/fashion/detect-one"
        payload := strings.NewReader("{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\"}")
    
        req, _ := http.NewRequest("POST", url, payload)
        req.Header.Add("content-type", "application/json")
        req.Header.Add("authorization", "Bearer <ACCESS_TOKEN>")
    
        res, _ := http.DefaultClient.Do(req)
        defer res.Body.Close()
        body, _ := ioutil.ReadAll(res.Body)
    }
    

    上面命令返回如下结果:

    {
        "code": 100,
        "message": "Success",
        "data": {
            "request_id": "16bdc4ee-25e8-4dea-8ba8-8ba18d0d54cf#5803",
            "image": {
                "id": "ef4bae7de3407938e0728427ec9f2f93",
                "url": "https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg",
                "width": 1200,
                "height": 1666
            },
            "object": {
                "category": "上衣",
                "category_id": 101,
                "confidence": 0.9732170104980469,
                "region": {
                    "x1": 0.2910948395729065,
                    "x2": 0.6117150187492371,
                    "y1": 0.23169997334480286,
                    "y2": 0.5400047302246094
                }
            }
        }
    }
    

    识别图片中一件最显著服饰,并给出检测出服饰的类别、位置和置信度。

    单件服饰识别较多件服饰识别,算法上做了优化,在识别速度和精度上都有很大提升,适用于只需要检测图片中的主要服饰的应用场景,如拍照购物等。

    识别结果和上面多件服饰识别的基本相同,例图如下:

    Alt text

    HTTP 请求

    POST https://api.aifashion.com/fashion/detect-one

    请求参数

    参数名 参数值类型 描述
    image_url String 待识别图片 URL,公网可访问
    image_base64 String 待识别图片二进制数据的 base64 编码
    region [Float, Float, Float, Float] 待分析区域的相对位置,[x1, y1, x2, y2]

    HTTP 响应结果

    响应结果中主要字段及描述如下:

    字段名 字段值类型 描述
    image Object 图片信息,包括 id、url 以及图的长和宽
    object Object 检测到的最显著服饰对象

    指定服饰定位

    调用指定服饰定位 API

    curl -X POST \
    https://api.aifashion.com/fashion/locate \
    -H "Content-type: application/json" \
    -H "Authorization: Bearer <ACCESS_TOKEN>" \
    -d '{
        "image_url":"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg", 
        "dataset_name":"test", 
        "product_id":"12345678"
    }'
    
    import requests
    
    url = "https://api.aifashion.com/fashion/locate"
    
    payload = {
        'image_url': 'https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg',
        'dataset_name': 'test', 
        'product_id': '12345678'
    }
    
    headers = {
        'authorization': "Bearer <ACCESS_TOKEN>"
    }
    
    response = requests.request("POST", url, json=payload, headers=headers)
    
    HttpResponse<JsonNode> response = Unirest.post("https://api.aifashion.com/fashion/locate")
        .header("accept", "application/json")
        .header("content-type", "application/json")
        .header("authorization", "Bearer <ACCESS_TOKEN>")
        .body("{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\",\"dataset_name\":\"test\",\"product_id\":\"12345678\"}")
        .asJson();
    
    <?php
    
    $curl = curl_init();
    
    curl_setopt_array($curl, array(
        CURLOPT_URL => "https://api.aifashion.com/fashion/locate",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_POSTFIELDS => "{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\",\"dataset_name\":\"test\",\"product_id\":\"12345678\"}",
        CURLOPT_HTTPHEADER => array(
            "authorization: Bearer <ACCESS_TOKEN>",
            "content-type: application/json"
        ),
    ));
    
    $response = curl_exec($curl);
    
    var settings = {
        "async": true,
        "crossDomain": true,
        "url": "https://api.aifashion.com/fashion/locate",
        "method": "POST",
        "headers": {
            "content-type": "application/json",
            "authorization": "Bearer <ACCESS_TOKEN>"
        },
        "processData": false,
        "data": "{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\",\"dataset_name\":\"test\",\"product_id\":\"12345678\"}"
    }
    
    $.ajax(settings).done(function (response) {
        console.log(response);
    });
    
    require 'uri'
    require 'net/http'
    
    url = URI("https://api.aifashion.com/fashion/locate")
    
    http = Net::HTTP.new(url.host, url.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    
    request = Net::HTTP::Post.new(url)
    request["content-type"] = 'application/json'
    request["authorization"] = 'Bearer <ACCESS_TOKEN>'
    request.body = "{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\",\"dataset_name\":\"test\",\"product_id\":\"12345678\"}"
    
    response = http.request(request)
    
    package main
    
    import (
        "strings"
        "net/http"
        "io/ioutil"
    )
    
    func main() {
        url := "https://api.aifashion.com/fashion/locate"
        payload := strings.NewReader("{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\",\"dataset_name\":\"test\",\"product_id\":\"12345678\"}")
    
        req, _ := http.NewRequest("POST", url, payload)
        req.Header.Add("content-type", "application/json")
        req.Header.Add("authorization", "Bearer <ACCESS_TOKEN>")
    
        res, _ := http.DefaultClient.Do(req)
        defer res.Body.Close()
        body, _ := ioutil.ReadAll(res.Body)
    }
    

    上面命令返回如下结果:

    {
        "code": 100,
        "message": "Success",
        "data": {
            "request_id": "16bdc4ee-25e8-4dea-8ba8-8ba18d0d54cf#5803",
            "image": {
                "id": "ef4bae7de3407938e0728427ec9f2f93",
                "url": "https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg",
                "width": 1200,
                "height": 1666
            },
            "item": {
                "id": "5b2b82bab2f60626d8644b9f",
                "product_id": "1234567890",
                "name": "name",
                "description": "",
                "category": "category1",
                "images": [
                    "http://a.com/1.jpg",
                    "https://a.com/2.jpg"
                ],
                "attributes": [
                    {
                        "key": "key1",
                        "value": "value1"
                    },
                    {
                        "key": "key2",
                        "value": "value2"
                    }
                ]
            },
            "location": {
                "x": 0.4910948395729065,
                "y": 0.38169997334480286,
                "confidence": 0.9732170104980469
            }
        }
    }
    

    给定数据集中的商品或图片条目,在上传图片中识别出该服饰,并给出位置坐标和置信度。

    指定服饰定位适用于服饰电商看图购、买家秀,时尚内容服饰打点等应用场景。

    例如图片:

    TODO 指定服饰定位图

    HTTP 请求

    POST https://api.aifashion.com/fashion/locate

    请求参数

    参数名 参数值类型 描述
    dataset_name String 数据集名称,用于唯一指定数据集
    product_id String 条目 product_id,指定数据集中的特定商品
    image_url String 待识别图片 URL,公网可访问
    image_base64 String 待识别图片二进制数据的 base64 编码

    HTTP 响应结果

    响应结果中主要字段及描述如下:

    字段名 字段值类型 描述
    image Object 图片信息,包括 id、url 以及图的长和宽
    item Object 定位到的服饰条目
    location Object 位置信息

    返回的条目可以是商品条目或图片条目,条目字段的具体定义请参照 商品条目实体图片条目实体

    时尚标签

    调用时尚标签 API

    curl -X POST \
    https://api.aifashion.com/fashion/tagging \
    -H "Content-type: application/json" \
    -H "Authorization: Bearer <ACCESS_TOKEN>" \
    -d '{
        "image_url":"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg"
    }'
    
    import requests
    
    url = "https://api.aifashion.com/fashion/tagging"
    
    payload = {
        'image_url': 'https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg'
    }
    
    headers = {
        'authorization': "Bearer <ACCESS_TOKEN>"
    }
    
    response = requests.request("POST", url, json=payload, headers=headers)
    
    HttpResponse<JsonNode> response = Unirest.post("https://api.aifashion.com/fashion/tagging")
        .header("accept", "application/json")
        .header("content-type", "application/json")
        .header("authorization", "Bearer <ACCESS_TOKEN>")
        .body("{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\"}")
        .asJson();
    
    <?php
    
    $curl = curl_init();
    
    curl_setopt_array($curl, array(
        CURLOPT_URL => "https://api.aifashion.com/fashion/tagging",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_POSTFIELDS => "{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\"}",
        CURLOPT_HTTPHEADER => array(
            "authorization: Bearer <ACCESS_TOKEN>",
            "content-type: application/json"
        ),
    ));
    
    $response = curl_exec($curl);
    
    var settings = {
        "async": true,
        "crossDomain": true,
        "url": "https://api.aifashion.com/fashion/tagging",
        "method": "POST",
        "headers": {
            "content-type": "application/json",
            "authorization": "Bearer <ACCESS_TOKEN>"
        },
        "processData": false,
        "data": "{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\"}"
    }
    
    $.ajax(settings).done(function (response) {
        console.log(response);
    });
    
    require 'uri'
    require 'net/http'
    
    url = URI("https://api.aifashion.com/fashion/tagging")
    
    http = Net::HTTP.new(url.host, url.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    
    request = Net::HTTP::Post.new(url)
    request["content-type"] = 'application/json'
    request["authorization"] = 'Bearer <ACCESS_TOKEN>'
    request.body = "{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\"}"
    
    response = http.request(request)
    
    package main
    
    import (
        "strings"
        "net/http"
        "io/ioutil"
    )
    
    func main() {
        url := "https://api.aifashion.com/fashion/tagging"
        payload := strings.NewReader("{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\"}")
    
        req, _ := http.NewRequest("POST", url, payload)
        req.Header.Add("content-type", "application/json")
        req.Header.Add("authorization", "Bearer <ACCESS_TOKEN>")
    
        res, _ := http.DefaultClient.Do(req)
        defer res.Body.Close()
        body, _ := ioutil.ReadAll(res.Body)
    }
    

    上面命令返回如下结果:

    {
        "code": 100,
        "message": "Success",
        "data": {
            "request_id": "16bdc4ee-25e8-4dea-8ba8-8ba18d0d54cf#5803",
            "image": {
                "id": "ef4bae7de3407938e0728427ec9f2f93",
                "url": "https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg",
                "width": 1200,
                "height": 1666
            },
            "object": {
                "category": "上衣",
                "category_id": 101,
                "confidence": 0.9998025298118591,
                "region": {
                    "x1": 0.2910948395729065,
                    "x2": 0.6117150187492371,
                    "y1": 0.23169997334480286,
                    "y2": 0.5400047302246094
                }
            },
            "tags": [
                {
                    "key": "衣长",
                    "values": [
                        {
                            "value": "长款",
                            "confidence": 0.9732170104980469,
                        }
                    ]
                },
                {
                    "key": "袖长",
                    "values": [
                        {
                            "value": "长袖",
                            "confidence": 0.9732170104980469,
                        }
                    ]
                }
            ]
        }
    }
    

    为图片中指定的服饰智能打标签,标签内容包括类别和服饰属性等信息。

    例图如下:

    Alt text

    HTTP 请求

    POST https://api.aifashion.com/fashion/tagging

    请求参数

    参数名 参数值类型 描述
    image_url String 待识别图片 URL,公网可访问
    image_base64 String 待识别图片二进制数据的 base64 编码
    region [Float, Float, Float, Float] 待分析区域的相对位置,[x1, y1, x2, y2]

    HTTP 响应结果

    响应结果中主要字段及描述如下:

    字段名 字段值类型 描述
    image Object 图片信息,包括 id、url 以及图的长和宽
    object Object 检测到的服饰对象
    tags Array 服饰对象的标签键值对列表

    服饰命名

    调用服饰命名 API

    curl -X POST \
    https://api.aifashion.com/fashion/caption \
    -H "Content-type: application/json" \
    -H "Authorization: Bearer <ACCESS_TOKEN>" \
    -d '{
        "image_url":"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg"
    }'
    
    import requests
    
    url = "https://api.aifashion.com/fashion/caption"
    
    payload = {
        'image_url': 'https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg'
    }
    
    headers = {
        'authorization': "Bearer <ACCESS_TOKEN>"
    }
    
    response = requests.request("POST", url, json=payload, headers=headers)
    
    HttpResponse<JsonNode> response = Unirest.post("https://api.aifashion.com/fashion/caption")
        .header("accept", "application/json")
        .header("content-type", "application/json")
        .header("authorization", "Bearer <ACCESS_TOKEN>")
        .body("{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\"}")
        .asJson();
    
    <?php
    
    $curl = curl_init();
    
    curl_setopt_array($curl, array(
        CURLOPT_URL => "https://api.aifashion.com/fashion/caption",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_POSTFIELDS => "{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\"}",
        CURLOPT_HTTPHEADER => array(
            "authorization: Bearer <ACCESS_TOKEN>",
            "content-type: application/json"
        ),
    ));
    
    $response = curl_exec($curl);
    
    var settings = {
        "async": true,
        "crossDomain": true,
        "url": "https://api.aifashion.com/fashion/caption",
        "method": "POST",
        "headers": {
            "content-type": "application/json",
            "authorization": "Bearer <ACCESS_TOKEN>"
        },
        "processData": false,
        "data": "{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\"}"
    }
    
    $.ajax(settings).done(function (response) {
        console.log(response);
    });
    
    require 'uri'
    require 'net/http'
    
    url = URI("https://api.aifashion.com/fashion/caption")
    
    http = Net::HTTP.new(url.host, url.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    
    request = Net::HTTP::Post.new(url)
    request["content-type"] = 'application/json'
    request["authorization"] = 'Bearer <ACCESS_TOKEN>'
    request.body = "{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\"}"
    
    response = http.request(request)
    
    package main
    
    import (
        "strings"
        "net/http"
        "io/ioutil"
    )
    
    func main() {
        url := "https://api.aifashion.com/fashion/caption"
        payload := strings.NewReader("{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\"}")
    
        req, _ := http.NewRequest("POST", url, payload)
        req.Header.Add("content-type", "application/json")
        req.Header.Add("authorization", "Bearer <ACCESS_TOKEN>")
    
        res, _ := http.DefaultClient.Do(req)
        defer res.Body.Close()
        body, _ := ioutil.ReadAll(res.Body)
    }
    

    上面命令返回如下结果:

    {
        "code": 100,
        "message": "Success",
        "data": {
            "request_id": "16bdc4ee-25e8-4dea-8ba8-8ba18d0d54cf#5803",
            "image": {
                "id": "ef4bae7de3407938e0728427ec9f2f93",
                "url": "https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg",
                "width": 1200,
                "height": 1666
            },
            "object": {
                "category": "上衣",
                "category_id": 101,
                "confidence": 0.9998025298118591,
                "region": {
                    "x1": 0.2910948395729065,
                    "x2": 0.6117150187492371,
                    "y1": 0.23169997334480286,
                    "y2": 0.5400047302246094
                }
            },
            "caption": "红色横条纹毛衣"
        }
    }
    

    为图片中的给定服饰命名,当前支持多种语言,详细情况参照常量章节。

    以中文为例,例图如下:

    Alt text

    HTTP 请求

    POST https://api.aifashion.com/fashion/caption

    请求参数

    参数名 参数值类型 描述
    image_url String 待识别图片 URL,公网可访问
    image_base64 String 待识别图片二进制数据的 base64 编码
    region [Float, Float, Float, Float] 待分析区域的相对位置,[x1, y1, x2, y2]
    language String 命名所用语言,默认为 zh_cn

    HTTP 响应结果

    响应结果中主要字段及描述如下:

    字段名 字段值类型 描述
    image Object 图片信息,包括 id、url 以及图的长和宽
    object Object 检测到的服饰对象
    caption String 命名结果

    服饰颜色分析

    curl -X POST \
    https://api.aifashion.com/fashion/color-analysis \
    -H "Content-type: application/json" \
    -H "Authorization: Bearer <ACCESS_TOKEN>" \
    -d '{
        "image_url":"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg"
    }'
    
    import requests
    
    url = "https://api.aifashion.com/fashion/color-analysis"
    
    payload = {
        'image_url': 'https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg'
    }
    
    headers = {
        'authorization': "Bearer <ACCESS_TOKEN>"
    }
    
    response = requests.request("POST", url, json=payload, headers=headers)
    
    HttpResponse<JsonNode> response = Unirest.post("https://api.aifashion.com/fashion/color-analysis")
        .header("accept", "application/json")
        .header("content-type", "application/json")
        .header("authorization", "Bearer <ACCESS_TOKEN>")
        .body("{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\"}")
        .asJson();
    
    <?php
    
    $curl = curl_init();
    
    curl_setopt_array($curl, array(
        CURLOPT_URL => "https://api.aifashion.com/fashion/color-analysis",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_POSTFIELDS => "{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\"}",
        CURLOPT_HTTPHEADER => array(
            "authorization: Bearer <ACCESS_TOKEN>",
            "content-type: application/json"
        ),
    ));
    
    $response = curl_exec($curl);
    
    var settings = {
        "async": true,
        "crossDomain": true,
        "url": "https://api.aifashion.com/fashion/color-analysis",
        "method": "POST",
        "headers": {
            "content-type": "application/json",
            "authorization": "Bearer <ACCESS_TOKEN>"
        },
        "processData": false,
        "data": "{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\"}"
    }
    
    $.ajax(settings).done(function (response) {
        console.log(response);
    });
    
    require 'uri'
    require 'net/http'
    
    url = URI("https://api.aifashion.com/fashion/color-analysis")
    
    http = Net::HTTP.new(url.host, url.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    
    request = Net::HTTP::Post.new(url)
    request["content-type"] = 'application/json'
    request["authorization"] = 'Bearer <ACCESS_TOKEN>'
    request.body = "{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\"}"
    
    response = http.request(request)
    
    package main
    
    import (
        "strings"
        "net/http"
        "io/ioutil"
    )
    
    func main() {
        url := "https://api.aifashion.com/fashion/color-analysis"
        payload := strings.NewReader("{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\"}")
    
        req, _ := http.NewRequest("POST", url, payload)
        req.Header.Add("content-type", "application/json")
        req.Header.Add("authorization", "Bearer <ACCESS_TOKEN>")
    
        res, _ := http.DefaultClient.Do(req)
        defer res.Body.Close()
        body, _ := ioutil.ReadAll(res.Body)
    }
    

    上面命令返回如下结果:

    {
        "code": 100,
        "message": "Success",
        "data": {
            "request_id": "16bdc4ee-25e8-4dea-8ba8-8ba18d0d54cf#5803",
            "image": {
                "id": "ef4bae7de3407938e0728427ec9f2f93",
                "url": "https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg",
                "width": 1200,
                "height": 1666
            },
            "object": {
                "category": "上衣",
                "category_id": 101,
                "confidence": 0.9998025298118591,
                "region": {
                    "x1": 0.2910948395729065,
                    "x2": 0.6117150187492371,
                    "y1": 0.23169997334480286,
                    "y2": 0.5400047302246094
                }
            },
            "colors": [
                {
                    "rgb": "#8B0000",
                    "name_en": "DarkRed", 
                    "name_zh": "深红色",
                    "percentage": 0.74
                }, 
                {
                    "rgb": "#FFFFFF",
                    "name_en": "White",
                    "name_zh": "纯白",
                    "percentage": 0.26
                }
            ]
        }
    }
    

    分析图片中指定服饰的颜色分布,包括颜色 RGB 值、名称和所占比例。

    例如下图:

    TODO 颜色分布图

    HTTP 请求

    POST https://api.aifashion.com/fashion/color-analysis

    请求参数

    参数名 参数值类型 描述
    image_url String 待识别图片 URL,公网可访问
    image_base64 String 待识别图片二进制数据的 base64 编码
    region [Float, Float, Float, Float] 待分析区域的相对位置,[x1, y1, x2, y2]

    HTTP 响应结果

    响应结果中主要字段及描述如下:

    字段名 字段值类型 描述
    image Object 图片信息,包括 id、url 以及图的长和宽
    object Object 检测到的服饰对象
    colors Array 分析出的颜色列表

    搜索同款

    curl -X POST \
    https://api.aifashion.com/fashion/imgsearch \
    -H "Content-type: application/json" \
    -H "Authorization: Bearer <ACCESS_TOKEN>" \
    -d '{
        "image_url":"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg",
        "dataset_name":"products"
    }'
    
    import requests
    
    url = "https://api.aifashion.com/fashion/imgsearch"
    
    payload = {
        'image_url': 'https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg',
        'dataset_name': 'products'
    }
    
    headers = {
        'authorization': "Bearer <ACCESS_TOKEN>"
    }
    
    response = requests.request("POST", url, json=payload, headers=headers)
    
    HttpResponse<JsonNode> response = Unirest.post("https://api.aifashion.com/fashion/imgsearch")
        .header("accept", "application/json")
        .header("content-type", "application/json")
        .header("authorization", "Bearer <ACCESS_TOKEN>")
        .body("{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\",\"dataset_name\":\"products\"}")
        .asJson();
    
    <?php
    
    $curl = curl_init();
    
    curl_setopt_array($curl, array(
        CURLOPT_URL => "https://api.aifashion.com/fashion/imgsearch",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_POSTFIELDS => "{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\",\"dataset_name\":\"products\"}",
        CURLOPT_HTTPHEADER => array(
            "authorization: Bearer <ACCESS_TOKEN>",
            "content-type: application/json"
        ),
    ));
    
    $response = curl_exec($curl);
    
    var settings = {
        "async": true,
        "crossDomain": true,
        "url": "https://api.aifashion.com/fashion/imgsearch",
        "method": "POST",
        "headers": {
            "content-type": "application/json",
            "authorization": "Bearer <ACCESS_TOKEN>"
        },
        "processData": false,
        "data": "{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\",\"dataset_name\":\"products\"}"
    }
    
    $.ajax(settings).done(function (response) {
        console.log(response);
    });
    
    require 'uri'
    require 'net/http'
    
    url = URI("https://api.aifashion.com/fashion/imgsearch")
    
    http = Net::HTTP.new(url.host, url.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    
    request = Net::HTTP::Post.new(url)
    request["content-type"] = 'application/json'
    request["authorization"] = 'Bearer <ACCESS_TOKEN>'
    request.body = "{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\",\"dataset_name\":\"products\"}"
    
    response = http.request(request)
    
    package main
    
    import (
        "strings"
        "net/http"
        "io/ioutil"
    )
    
    func main() {
        url := "https://api.aifashion.com/fashion/imgsearch"
        payload := strings.NewReader("{\"image_url\":\"https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg\",\"dataset_name\":\"products\"}")
    
        req, _ := http.NewRequest("POST", url, payload)
        req.Header.Add("content-type", "application/json")
        req.Header.Add("authorization", "Bearer <ACCESS_TOKEN>")
    
        res, _ := http.DefaultClient.Do(req)
        defer res.Body.Close()
        body, _ := ioutil.ReadAll(res.Body)
    }
    

    上面命令返回如下结果:

    {
        "code": 100,
        "message": "Success",
        "data": {
            "request_id": "16bdc4ee-25e8-4dea-8ba8-8ba18d0d54cf#5803",
            "image": {
                "id": "ef4bae7de3407938e0728427ec9f2f93",
                "url": "https://images.aifashion.com/ef/4b/ae/ef4bae7de3407938e0728427ec9f2f93.jpg",
                "width": 1200,
                "height": 1666
            },
            "object": {
                "category": "上衣",
                "category_id": 101,
                "confidence": 0.9732170104980469,
                "region": {
                    "x1": 0.2910948395729065,
                    "x2": 0.6117150187492371,
                    "y1": 0.23169997334480286,
                    "y2": 0.5400047302246094
                }
            },
            "similar_items": [
                {
                    "id": "5b2b82bab2f60626d8644b9f",
                    "product_id": "1234567890",
                    "name": "name",
                    "description": "",
                    "category": "category1",
                    "images": [
                        "http://a.com/1.jpg",
                        "https://a.com/2.jpg"
                    ],
                    "attributes": [
                        {
                            "key": "key1",
                            "value": "value1"
                        },
                        {
                            "key": "key2",
                            "value": "value2"
                        }
                    ]
                },
                {
                    "product_id": "1234567891",
                    "name": "name1",
                    "description": "",
                    "category_id": 101,
                    "gender_id": 2,
                    "images": [
                        "http://a.com/3.jpg",
                        "https://a.com/4.jpg"
                    ],
                    "attributes": [
                        {
                            "key": "key1",
                            "value": "value3"
                        },
                        {
                            "key": "key2",
                            "value": "value4"
                        }
                    ]
                }
            ]
        }
    }
    

    在指定数据集中找出和图片中指定服饰外观相似的条目,搜索结果一般都为同类别服饰。

    例图如下:

    Alt text

    HTTP 请求

    POST https://api.aifashion.com/fashion/imgsearch

    请求参数

    参数名 参数值类型 描述
    image_url String 待识别图片 URL,公网可访问
    image_base64 String 待识别图片二进制数据的 base64 编码
    region [Float, Float, Float, Float] 待分析区域的相对位置,[x1, y1, x2, y2]
    dataset_name String 指定数据集进行搜索
    max_results Integer 最多返回条目数,默认值为 20,最小值为 1,最大值为 100

    HTTP 响应结果

    响应结果中主要字段及描述如下:

    字段名 字段值类型 描述
    image Object 图片信息,包括 id、url 以及图的长和宽
    object Object 检测到的服饰对象
    similar_items Array 搜索到的相似条目

    返回的条目可以是商品条目或图片条目,条目字段的具体定义请参照 商品条目实体图片条目实体

    搜索搭配

    在指定数据集中找出和图片中指定服饰外观搭配的条目,搜索结果一般都为跨类别服饰。

    HTTP 请求

    POST https://api.aifashion.com/fashion/mix

    请求参数

    参数名 参数值类型 描述
    image_url String 待识别图片 URL,公网可访问
    image_base64 String 待识别图片二进制数据的 base64 编码
    region [Float, Float, Float, Float] 待分析区域的相对位置,[x1, y1, x2, y2]
    dataset_name String 指定数据集进行搭配
    max_results Integer 最多返回条目数,默认值为 20,最小值为 1,最大值为 100

    HTTP 响应结果

    响应结果中主要字段及描述如下:

    字段名 字段值类型 描述
    image Object 图片信息,包括 id、url 以及图的长和宽
    object Object 检测到的服饰对象
    mix_items Array 搜索到的搭配条目

    返回的条目可以是商品条目或图片条目,条目字段的具体定义请参照 商品条目实体图片条目实体

    人像分割

    curl -X POST \
    https://api.aifashion.com/human/seg \
    -H "Content-type: application/json" \
    -H "Authorization: Bearer <ACCESS_TOKEN>" \
    -d '{
        "image_url":"http://a.hiphotos.baidu.com/image/pic/item/a6efce1b9d16fdfad7a9f863b88f8c5495ee7b71.jpg"
    }'
    
    import requests
    
    url = "https://api.aifashion.com/human/seg"
    
    payload = {
        'image_url': 'http://a.hiphotos.baidu.com/image/pic/item/a6efce1b9d16fdfad7a9f863b88f8c5495ee7b71.jpg'
    }
    
    headers = {
        'authorization': "Bearer <ACCESS_TOKEN>"
    }
    
    response = requests.request("POST", url, json=payload, headers=headers)
    
    HttpResponse<JsonNode> response = Unirest.post("https://api.aifashion.com/human/seg")
        .header("accept", "application/json")
        .header("content-type", "application/json")
        .header("authorization", "Bearer <ACCESS_TOKEN>")
        .body("{\"image_url\":\"http://a.hiphotos.baidu.com/image/pic/item/a6efce1b9d16fdfad7a9f863b88f8c5495ee7b71.jpg\"}")
        .asJson();
    
    <?php
    
    $curl = curl_init();
    
    curl_setopt_array($curl, array(
        CURLOPT_URL => "https://api.aifashion.com/human/seg",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_POSTFIELDS => "{\"image_url\":\"http://a.hiphotos.baidu.com/image/pic/item/a6efce1b9d16fdfad7a9f863b88f8c5495ee7b71.jpg\"}",
        CURLOPT_HTTPHEADER => array(
            "authorization: Bearer <ACCESS_TOKEN>",
            "content-type: application/json"
        ),
    ));
    
    $response = curl_exec($curl);
    
    var settings = {
        "async": true,
        "crossDomain": true,
        "url": "https://api.aifashion.com/human/seg",
        "method": "POST",
        "headers": {
            "content-type": "application/json",
            "authorization": "Bearer <ACCESS_TOKEN>"
        },
        "processData": false,
        "data": "{\"image_url\":\"http://a.hiphotos.baidu.com/image/pic/item/a6efce1b9d16fdfad7a9f863b88f8c5495ee7b71.jpg\"}"
    }
    
    $.ajax(settings).done(function (response) {
        console.log(response);
    });
    
    require 'uri'
    require 'net/http'
    
    url = URI("https://api.aifashion.com/human/seg")
    
    http = Net::HTTP.new(url.host, url.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    
    request = Net::HTTP::Post.new(url)
    request["content-type"] = 'application/json'
    request["authorization"] = 'Bearer <ACCESS_TOKEN>'
    request.body = "{\"image_url\":\"http://a.hiphotos.baidu.com/image/pic/item/a6efce1b9d16fdfad7a9f863b88f8c5495ee7b71.jpg\"}"
    
    response = http.request(request)
    
    package main
    
    import (
        "strings"
        "net/http"
        "io/ioutil"
    )
    
    func main() {
        url := "https://api.aifashion.com/human/seg"
        payload := strings.NewReader("{\"image_url\":\"http://a.hiphotos.baidu.com/image/pic/item/a6efce1b9d16fdfad7a9f863b88f8c5495ee7b71.jpg\"}")
    
        req, _ := http.NewRequest("POST", url, payload)
        req.Header.Add("content-type", "application/json")
        req.Header.Add("authorization", "Bearer <ACCESS_TOKEN>")
    
        res, _ := http.DefaultClient.Do(req)
        defer res.Body.Close()
        body, _ := ioutil.ReadAll(res.Body)
    }
    

    上面命令返回如下结果:

    {
        "code": 100,
        "data": {
            "image": {
                "height": 1517,
                "id": "9fa7b74f1768cae31adeb6351ac6ca89",
                "url": "http://a.hiphotos.baidu.com/image/pic/item/a6efce1b9d16fdfad7a9f863b88f8c5495ee7b71.jpg",
                "width": 960
            },
            "people_num": 2,
            "request_id": "489d1dfc-9334-4ca0-bb34-1261bea26100#312",
            "segs": [
                {
                    "counts": "d[[d02Y_17J6J6I6K4K6K4K5L4K5K5K5K4L4L3M2M4M2M4L3M4L3L5M2O1O2N1O1O100O1O100O2N100O100O100O100O2O0O010O10O010O010O10VYORMT1n2jNPN;P2BWN:h1D_N7b1GcN6\\1IiN3X1KmN2R1MRO1n0NVONj01ZOMe03]OLb04AJ>6EH99JD6=LA3?0_ONb05\\OJd0:YOEg0?VO@j0e0ROZOn0k0nNTOR1P1kNoNU1U1hNjNX1Z1dNfN[1_1bNaN]1b1aN]N^1g1`NXN`1k1^NUN`1o1^NPNa1S2^NlMa1X2]NhMa1[2]NeMb1_2\\NaMb1c2[N]Me1e2YN[Mf1i2WNXMh1k2UNUMj1P3SNoLm1T3PNmLo1W3mMiLS2[3hMfLX2^3dMcL[2a3aM_L_2e3]M[Lc2h3YMZLf2i3WMWLi2l3TMTLl2o3PMRLQ3o3lLSLS3P4iLQLW3Q4fLPL[3Q4bLPL^3R4_LPLa3P4]LQLd3P4YLQLh3o3ULTLj3n3SLSLn3m3PLTLQ4m3lKTLU4l3iKULW4m3fKULZ4l3cKUL^4k3`KVLa4k3\\KVLd4k3ZKVLg4k3VKVLk4j3SKWLm4k3PKVLQ5j3mJVLU5k3hJVLY5j3eJXLZ5j3cJWL^5i3`JYL_5i3]J[Lb5e3\\J^Lb5d3XJbLg5_3SJgLk5Z3PJkLP6V3iIRMT6P3dIXM[6h2^I`M`6b2WIgMg6[2nHPNQ7Q2UHiNi7Y1_G_O_8c0YGFd8<TGLj86PG0o81kF5S9MgF9W9IdF<Z9FaF`0\\9C^Fb0`9AZFf0b9]OXFj0d9YOUFo0g9SOSFW1g9lNQF_1i9cNPFi1i9ZNnEY2e9iMRFQ4[8RL[Gd4V8^KaGW5Q8kJhGg5k7[JoGR6h7PJRHX6j7jIQH]6k7eIPHb6m7_IoGf6n7\\InGi6o7XInGm6o7UImGP7Q8QIlGS7R8nHjGV7U8kHgGY7X8hHdG]7Z8dH_Gd7_8]H[Gj7c8WHVGP8j8PHnFZ8o8hGgFb8W9_G`Fk8^9WGWFU9f9lFnEb9o9`FfEl9W:VF_EV:]:lEYE_:d:cESEg:j:\\EmDm:Q;j<M2N2N2O1O2N1O2O1N2N3N3L3M6J4M4K3M3M3M3M2M3N1O2N1N3N4K7J7I8G9H:Ed0]Od0[O`0A9F8I6I7I6K4K3N1N2N101N100O100O1O10O0100O10O10O10O010O10O10O2N1O2N2N2N3M3M2N3M2N2N2N2N2N1O2N1O1O1O1O1O2N1O2M2O2N2N2N2N3M3L4M4L4L3M2N3L3N2N2N1O2N1O2N2M3N2N3M2N3M4L3M4K4M3M3M2N2N2N2N1O001O1O00100O001O1O010O001O00100O001O001O1O1O2N101N1O2N2N2N2N3M3M2N3M2N1O2N2N1O1O1O001O001O001O001O001O00001O001O00001O001O001O1O1O1O001O1O1O1O2N1O1O2N1O2N1O2N2N2N3M2N1O2N2N1O1O2N1O1O1O1O1O1O1O1O001O1O001O1O1O1O1O2N1O1O2N1O2N2N2N3M2N3M3M2N2N2N2N1O2N2N1O2N2M2O2N2N1O2N2N2N2N2N2N2N1dJd@eZO^?Te0m@fZOV?Re0UAhZOm>Qe0^AhZOf>od0gAjZO]>ld0PBmZOS>id0[BoZOj=ed0eBT[O^=ad0oBY[OV=\\d0UC`[Oo<Ud0[Cg[Oj<R;f_OTJj3fJe<e:S@XJb3oJ`<X:a@\\JY3YK[<i9o@aJP3bKW<_9WAcJl2kKS<U9]AeJh2SLR<l8aAfJf2[Ln;d8gAhJa2aLm;]8lAiJ_2fLj;Y8oAiJ]2lLh;R8TBkJY2PMg;o2U_OTNS3f1X2RMf;R2Z@dNQ2P2V2UMf;o0dAkNX1g2o1QM\\;1UCPO;d3T2]L_i0T3i9ZOf0XOjTP2",
                    "size": [
                        1517,
                        960
                    ]
                },
                {
                    "counts": "VgY5k1U]1d0]Oa0A?aKQMkkN^3\\S1nMckN`2iS1eNYkNg1_T1UObjNV1VU1f4G8H9F:E:D=A=hJaDSVOn;dh0kE^VOc:]i0QFcUO_:Yj0WFgTOX:Tk0_FmSOm9Pl0j4M3M3M3M3N2N2N1RZOg\\Of?\\c0Q@o]Ok>Sb0k@m^O]>Ua0WAi_OT>Z`0_Ah@i=[?iAiA^=Z>UBbBY=a=YBXCY=k<[BjCY=Y<aBUDVNXHY=gc0\\DPF[;T:_DWFW;m9dD]FT;f9hDbFR;a9iDgFP;]9kDjFo:Z9mDlFo:X9kDmFQ;^9bDfF\\;e9WD_Fg;n9iCWFV<af0N2N2O0O2N2O0O2O1N101N101N2O0O1O100O1O2N100O1O1O1O1O2N1N2O1O1N2O1M4M2N2M3N2N2O1N2N2O2M2O1O1O1N2O1O1O1O2M2O1N2N2N2M3N2M3M3N2N2N2N2O1N2O1O1O1000000O100000000O1000000O10000000001O000000000O100000000000000000000000000000000000000000000000000000000000000000000000000000000000O100oSOnFga0R9W^OVGca0j8Z^O^Gaa0b8]^OdG_a0\\8_^OjG]a0V8c^OnGYa0R8f^OSHVa0m7i^OXHSa0h7l^O^Ho`0b7P_OeHj`0[7U_OiHh`0W7X_OlHe`0T7Z_OoHd`0Q7[_ORIc`0n6]_OTI``0m6__OUI``0k6__OXI_`0h6a_OYI^`0g6a_O[I^`0e6b_O\\I]`0d6b_O^I]`0b6c_O`I[`0`6d_OaI\\`0_6d_ObI[`0^6e_OcIZ`0]6f_OdIX`0]6g_OdIY`0\\6g_OeIX`0[6h_OfIW`0Z6i_OgIV`0Y6j_OhIT`0Y6k_OiIT`0W6l_OjIS`0V6m_OkIR`0U6n_OlIQ`0T6n_OoIo?R6Q@oIn?Q6R@PJm?P6S@RJk?n5T@TJk?l5U@VJh?k5X@WJf?i5Y@ZJe?f5Z@]Jd?c5[@`Jc?a5[@bJb?_5\\@dJc?\\5\\@gJb?Y5]@iJb?W5\\@lJb?U5]@nJa?R5]@QKb?o4\\@TKc?l4[@WKc?j4[@YKd?g4Z@\\Ke?d4Y@^Kg?b4W@aKg?`4X@bKg?^4W@eKh?\\4V@eKi?\\4V@fKi?Z4U@iKi?Y4U@hKk?X4S@kKk?W4S@kKl?U4S@lKl?V4Q@mKn?S4Q@oKm?R4Q@QLn?P4P@RLn?P4P@QLP`0o3n_OTLP`0n3n_OTLP`0m3o_OULP`0l3m_OWLh<_JY^O[9n4XLm;\\KP_O^8P5ZLl;\\KP_O^8P5ZLn;XKQ_O`8n4\\Ln;VKR_Oa8l4]LP<RKS_Od8h4`LR<mJT_Of8e4cLS<iJV_Og8a4fLW<cJW_Ok8[4hL[<_JX_Om8W4jL^<ZJY_Oo8S4mLa<VJZ_OP9P4nLe<RJZ_OS9l3PMg<oI[_OT9i3RMj<kI[_OV9f3SMm<iI[_OV9d3VMo<dI\\_OY9`3WMS=aI[_OZ9_3XMT=`I[_O[9\\3YMX=]IZ_O\\9[3[MX=[IZ_O^9Y3[MY=^IX_OZ9[3]MX=_IW_OY9\\3\\MZ=`IT_OZ9[3\\M\\=aIR_OX9]3\\M[=cIR_OW9]3\\M[=cIQ_OX9]3[M\\=dIQ_OW9]3\\M[=e6\\BbI]=g6ZBaI]=h6[B_Il<[7lBlH]<l7ZC\\H_;k8XD]GV;V9bDQGU;Y9cDnFT;[9fDkFR;^9gDgFR;a9hDeFV;^9bDhF\\;\\9\\DkFa;cf0M4L3M4M3L5K4M3L3M4M2M2O2M3M2O2L3M4M3L5K4M4K6K5K7I8H6J7I5K6J5K4L5L5J6K4L4L3M4L3M3M3M2N3M2N2N3M3M3M2N3M3M3M4L3M3M3M2N3M2N2N2N2N2N1O2N1O1N3N1O1O1N2N2N2O1N2N2N2N2N2O1N2M2O2N2N2N1N4L3K5K6J5L5K4L5K5K5L6I9H8H9G8H7J7HkZYd0",
                    "size": [
                        1517,
                        960
                    ]
                }
            ]
        },
        "message": "Success"
    }
    

    在给定图片中返回人像的像素级分割信息。

    HTTP 请求

    POST https://api.aifashion.com/human/seg

    请求参数

    参数名 参数值类型 描述
    image_url String 待识别图片 URL,公网可访问
    image_base64 String 待识别图片二进制数据的 base64 编码

    HTTP 响应结果

    响应结果中主要字段及描述如下:

    字段名 字段值类型 描述
    image Object 图片信息,包括 id、url 以及图的长和宽
    segs list 检测到的人像语义分割信息,面积由大到小排列
    people_num int 图片中检测到人的个数

    seg 返回值使用方法

    seg信息经过了cocotools进行了编码,成为一个json类型,使用者需要将返回的seg信息进行解码,解码后得到图片的mask掩码。

    以使用cocotools的python接口为例:

    首先安装pycocotools的python接口,

    pip install pycocotools

    使用pycocotools对mask进行编码:

    from pycocotools import mask; img_mask_json = mask.encode(img_mask) # img_mask is a np-array mask(背景是0,人像是1)

    使用pycocotools对mask进行解码:

    from pycocotools import mask; img_mask = mask.decode(img_mask_json) # img_mask_json 为API中segs列表中每一个对应的json值。

    人体关键点

    curl -X POST \
    https://api.aifashion.com/human/keypoints \
    -H "Content-type: application/json" \
    -H "Authorization: Bearer <ACCESS_TOKEN>" \
    -d '{
        "image_url":"http://a.hiphotos.baidu.com/image/pic/item/a6efce1b9d16fdfad7a9f863b88f8c5495ee7b71.jpg"
    }'
    
    import requests
    
    url = "https://api.aifashion.com/human/keypoints"
    
    payload = {
        'image_url': 'http://a.hiphotos.baidu.com/image/pic/item/a6efce1b9d16fdfad7a9f863b88f8c5495ee7b71.jpg'
    }
    
    headers = {
        'authorization': "Bearer <ACCESS_TOKEN>"
    }
    
    response = requests.request("POST", url, json=payload, headers=headers)
    
    HttpResponse<JsonNode> response = Unirest.post("https://api.aifashion.com/human/keypoints")
        .header("accept", "application/json")
        .header("content-type", "application/json")
        .header("authorization", "Bearer <ACCESS_TOKEN>")
        .body("{\"image_url\":\"http://a.hiphotos.baidu.com/image/pic/item/a6efce1b9d16fdfad7a9f863b88f8c5495ee7b71.jpg\"}")
        .asJson();
    
    <?php
    
    $curl = curl_init();
    
    curl_setopt_array($curl, array(
        CURLOPT_URL => "https://api.aifashion.com/human/keypoints",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_POSTFIELDS => "{\"image_url\":\"http://a.hiphotos.baidu.com/image/pic/item/a6efce1b9d16fdfad7a9f863b88f8c5495ee7b71.jpg\"}",
        CURLOPT_HTTPHEADER => array(
            "authorization: Bearer <ACCESS_TOKEN>",
            "content-type: application/json"
        ),
    ));
    
    $response = curl_exec($curl);
    
    var settings = {
        "async": true,
        "crossDomain": true,
        "url": "https://api.aifashion.com/human/keypoints",
        "method": "POST",
        "headers": {
            "content-type": "application/json",
            "authorization": "Bearer <ACCESS_TOKEN>"
        },
        "processData": false,
        "data": "{\"image_url\":\"http://a.hiphotos.baidu.com/image/pic/item/a6efce1b9d16fdfad7a9f863b88f8c5495ee7b71.jpg\"}"
    }
    
    $.ajax(settings).done(function (response) {
        console.log(response);
    });
    
    require 'uri'
    require 'net/http'
    
    url = URI("https://api.aifashion.com/human/keypoints")
    
    http = Net::HTTP.new(url.host, url.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    
    request = Net::HTTP::Post.new(url)
    request["content-type"] = 'application/json'
    request["authorization"] = 'Bearer <ACCESS_TOKEN>'
    request.body = "{\"image_url\":\"http://a.hiphotos.baidu.com/image/pic/item/a6efce1b9d16fdfad7a9f863b88f8c5495ee7b71.jpg\"}"
    
    response = http.request(request)
    
    package main
    
    import (
        "strings"
        "net/http"
        "io/ioutil"
    )
    
    func main() {
        url := "https://api.aifashion.com/human/keypoints"
        payload := strings.NewReader("{\"image_url\":\"http://a.hiphotos.baidu.com/image/pic/item/a6efce1b9d16fdfad7a9f863b88f8c5495ee7b71.jpg\"}")
    
        req, _ := http.NewRequest("POST", url, payload)
        req.Header.Add("content-type", "application/json")
        req.Header.Add("authorization", "Bearer <ACCESS_TOKEN>")
    
        res, _ := http.DefaultClient.Do(req)
        defer res.Body.Close()
        body, _ := ioutil.ReadAll(res.Body)
    }
    

    上面命令返回如下结果:

    {
        "code": 100,
        "data": {
            "image": {
                "height": 1517,
                "id": "9fa7b74f1768cae31adeb6351ac6ca89",
                "url": "http://a.hiphotos.baidu.com/image/pic/item/a6efce1b9d16fdfad7a9f863b88f8c5495ee7b71.jpg",
                "width": 960
            },
            "keypoints": [
                [
                    {
                        "confidence": 0.999906,
                        "id": 0,
                        "name": "nose",
                        "x": 0.574165,
                        "y": 0.263841
                    },
                    {
                        "confidence": 0.99999,
                        "id": 1,
                        "name": "left_eye",
                        "x": 0.572082,
                        "y": 0.234187
                    },
                    {
                        "confidence": 0.998963,
                        "id": 2,
                        "name": "right_eye",
                        "x": 0.555416,
                        "y": 0.240117
                    },
                    {
                        "confidence": 0.999953,
                        "id": 3,
                        "name": "left_ear",
                        "x": 0.673114,
                        "y": 0.19333
                    },
                    {
                        "confidence": 0.972101,
                        "id": 4,
                        "name": "right_ear",
                        "x": 0.674156,
                        "y": 0.190694
                    },
                    {
                        "confidence": 0.997567,
                        "id": 5,
                        "name": "left_shoulder",
                        "x": 0.803311,
                        "y": 0.331057
                    },
                    {
                        "confidence": 0.985683,
                        "id": 6,
                        "name": "right_shoulder",
                        "x": 0.751232,
                        "y": 0.312605
                    },
                    {
                        "confidence": 0.999552,
                        "id": 7,
                        "name": "left_elbow",
                        "x": 0.755398,
                        "y": 0.548521
                    },
                    {
                        "confidence": 0.930756,
                        "id": 8,
                        "name": "right_elbow",
                        "x": 0.674156,
                        "y": 0.516231
                    },
                    {
                        "confidence": 0.999817,
                        "id": 9,
                        "name": "left_wrist",
                        "x": 0.563749,
                        "y": 0.64605
                    },
                    {
                        "confidence": 0.944119,
                        "id": 10,
                        "name": "right_wrist",
                        "x": 0.561666,
                        "y": 0.631553
                    },
                    {
                        "confidence": 0.999526,
                        "id": 11,
                        "name": "left_hip",
                        "x": 0.782479,
                        "y": 0.729082
                    },
                    {
                        "confidence": 0.993055,
                        "id": 12,
                        "name": "right_hip",
                        "x": 0.747066,
                        "y": 0.711948
                    },
                    {
                        "confidence": 0.916011,
                        "id": 13,
                        "name": "left_knee",
                        "x": 0.783521,
                        "y": 0.973564
                    },
                    {
                        "confidence": 0.696214,
                        "id": 14,
                        "name": "right_knee",
                        "x": 0.834558,
                        "y": 0.990039
                    },
                    {
                        "confidence": 0.007315,
                        "id": 15,
                        "name": "left_ankle",
                        "x": 0.743941,
                        "y": 0.990039
                    },
                    {
                        "confidence": 0.082811,
                        "id": 16,
                        "name": "right_ankle",
                        "x": 0.731442,
                        "y": 0.990039
                    }
                ],
                [
                    {
                        "confidence": 0.999966,
                        "id": 0,
                        "name": "nose",
                        "x": 0.40814,
                        "y": 0.304825
                    },
                    {
                        "confidence": 0.997587,
                        "id": 1,
                        "name": "left_eye",
                        "x": 0.417502,
                        "y": 0.277816
                    },
                    {
                        "confidence": 0.999953,
                        "id": 2,
                        "name": "right_eye",
                        "x": 0.398779,
                        "y": 0.274522
                    },
                    {
                        "confidence": 0.968229,
                        "id": 3,
                        "name": "left_ear",
                        "x": 0.284358,
                        "y": 0.258712
                    },
                    {
                        "confidence": 0.999969,
                        "id": 4,
                        "name": "right_ear",
                        "x": 0.286438,
                        "y": 0.258712
                    },
                    {
                        "confidence": 0.969635,
                        "id": 5,
                        "name": "left_shoulder",
                        "x": 0.266675,
                        "y": 0.378605
                    },
                    {
                        "confidence": 0.999473,
                        "id": 6,
                        "name": "right_shoulder",
                        "x": 0.208424,
                        "y": 0.395074
                    },
                    {
                        "confidence": 0.402283,
                        "id": 7,
                        "name": "left_elbow",
                        "x": 0.266675,
                        "y": 0.592042
                    },
                    {
                        "confidence": 0.99985,
                        "id": 8,
                        "name": "right_elbow",
                        "x": 0.162656,
                        "y": 0.608511
                    },
                    {
                        "confidence": 0.875194,
                        "id": 9,
                        "name": "left_wrist",
                        "x": 0.567289,
                        "y": 0.638155
                    },
                    {
                        "confidence": 0.999944,
                        "id": 10,
                        "name": "right_wrist",
                        "x": 0.416462,
                        "y": 0.686244
                    },
                    {
                        "confidence": 0.639169,
                        "id": 11,
                        "name": "left_hip",
                        "x": 0.321805,
                        "y": 0.749484
                    },
                    {
                        "confidence": 0.985825,
                        "id": 12,
                        "name": "right_hip",
                        "x": 0.266675,
                        "y": 0.773858
                    },
                    {
                        "confidence": 0.161474,
                        "id": 13,
                        "name": "left_knee",
                        "x": 0.396698,
                        "y": 0.973461
                    },
                    {
                        "confidence": 0.713775,
                        "id": 14,
                        "name": "right_knee",
                        "x": 0.284358,
                        "y": 0.960286
                    },
                    {
                        "confidence": 0.027301,
                        "id": 15,
                        "name": "left_ankle",
                        "x": 0.487195,
                        "y": 0.636178
                    },
                    {
                        "confidence": 0.009189,
                        "id": 16,
                        "name": "right_ankle",
                        "x": 0.596414,
                        "y": 0.638155
                    }
                ]
            ],
            "people_num": 2,
            "request_id": "5ec403e2-d5f1-4dc3-aa51-0109c6e43b56#274"
        },
        "message": "Success"
    }
    

    在给定图片中返回人体的关键点信息。

    HTTP 请求

    POST https://api.aifashion.com/human/keypoints

    请求参数

    参数名 参数值类型 描述
    image_url String 待识别图片 URL,公网可访问
    image_base64 String 待识别图片二进制数据的 base64 编码

    HTTP 响应结果

    响应结果中主要字段及描述如下:

    字段名 字段值类型 描述
    image Object 图片信息,包括 id、url 以及图的长和宽
    keypoints list 检测到的人体关键点信息
    people_num int 图片中检测到人的个数

    关键点的类别信息详见常量。

    服饰吊牌OCR

    curl -X POST \
    https://api.aifashion.com/fashion/ocr \
    -H "Content-type: application/json" \
    -H "Authorization: Bearer <ACCESS_TOKEN>" \
    -d '{
        "image_url":"http://a.hiphotos.baidu.com/image/pic/item/fea231vda3fvfgf3.jpg"
    }'
    
    import requests
    
    url = "https://api.aifashion.com/fashion/ocr"
    
    payload = {
        'image_url': 'http://a.hiphotos.baidu.com/image/pic/item/fea231vda3fvfgf3.jpg'
    }
    
    headers = {
        'authorization': "Bearer <ACCESS_TOKEN>"
    }
    
    response = requests.request("POST", url, json=payload, headers=headers)
    
    HttpResponse<JsonNode> response = Unirest.post("https://api.aifashion.com/fashion/ocr")
        .header("accept", "application/json")
        .header("content-type", "application/json")
        .header("authorization", "Bearer <ACCESS_TOKEN>")
        .body("{\"image_url\":\"http://a.hiphotos.baidu.com/image/pic/item/fea231vda3fvfgf3.jpg\"}")
        .asJson();
    
    <?php
    
    $curl = curl_init();
    
    curl_setopt_array($curl, array(
        CURLOPT_URL => "https://api.aifashion.com/fashion/ocr",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_POSTFIELDS => "{\"image_url\":\"http://a.hiphotos.baidu.com/image/pic/item/fea231vda3fvfgf3.jpg\"}",
        CURLOPT_HTTPHEADER => array(
            "authorization: Bearer <ACCESS_TOKEN>",
            "content-type: application/json"
        ),
    ));
    
    $response = curl_exec($curl);
    
    var settings = {
        "async": true,
        "crossDomain": true,
        "url": "https://api.aifashion.com/fashion/ocr",
        "method": "POST",
        "headers": {
            "content-type": "application/json",
            "authorization": "Bearer <ACCESS_TOKEN>"
        },
        "processData": false,
        "data": "{\"image_url\":\"http://a.hiphotos.baidu.com/image/pic/item/fea231vda3fvfgf3.jpg\"}"
    }
    
    $.ajax(settings).done(function (response) {
        console.log(response);
    });
    
    require 'uri'
    require 'net/http'
    
    url = URI("https://api.aifashion.com/fashion/ocr")
    
    http = Net::HTTP.new(url.host, url.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    
    request = Net::HTTP::Post.new(url)
    request["content-type"] = 'application/json'
    request["authorization"] = 'Bearer <ACCESS_TOKEN>'
    request.body = "{\"image_url\":\"http://a.hiphotos.baidu.com/image/pic/item/fea231vda3fvfgf3.jpg\"}"
    
    response = http.request(request)
    
    package main
    
    import (
        "strings"
        "net/http"
        "io/ioutil"
    )
    
    func main() {
        url := "https://api.aifashion.com/fashion/ocr"
        payload := strings.NewReader("{\"image_url\":\"http://a.hiphotos.baidu.com/image/pic/item/fea231vda3fvfgf3.jpg\"}")
    
        req, _ := http.NewRequest("POST", url, payload)
        req.Header.Add("content-type", "application/json")
        req.Header.Add("authorization", "Bearer <ACCESS_TOKEN>")
    
        res, _ := http.DefaultClient.Do(req)
        defer res.Body.Close()
        body, _ := ioutil.ReadAll(res.Body)
    }
    

    上面命令返回如下结果:

    {
        "code": 100,
        "data": {
            "image": {
                "height": 1920,
                "id": "bb5d36f9983791309f00ba7cf57c14e6",
                "url": "http://120.133.26.120:80/ocr_images/12.jpg",
                "width": 1080
            },
            "ocr_results": [
                {
                    "degree": -0.6078997088726946,
                    "height": 76.5032893313197,
                    "text": "合格证",
                    "width": 862.5338896990231,
                    "x_center": 467.25,
                    "y_center": 440.75
                },
                {
                    "degree": -0.6749540485739576,
                    "height": 54.504629232781554,
                    "text": "品牌:爱城市",
                    "width": 904.527201579903,
                    "x_center": 388.75,
                    "y_center": 515.25
                },
                {
                    "degree": 0.05945079816372075,
                    "height": 50.504999500099984,
                    "text": "款号:966847",
                    "width": 637.503521107358,
                    "x_center": 453.75,
                    "y_center": 574.25
                },
                {
                    "degree": -0.3068030040093623,
                    "height": 49.00510150968557,
                    "text": "品名:女式外套",
                    "width": 655.5068649885577,
                    "x_center": 500.75,
                    "y_center": 633
                },
                {
                    "degree": -0.7450552586667168,
                    "height": 48.505207768315586,
                    "text": "颜色:浅杏",
                    "width": 487.5230338008352,
                    "x_center": 448.75,
                    "y_center": 690.25
                },
                {
                    "degree": -0.3910467019286368,
                    "height": 44.50568108466541,
                    "text": "号型:160/84AM",
                    "width": 925.5121436947018,
                    "x_center": 503.75,
                    "y_center": 750.25
                },
                {
                    "degree": -0.9402138379191299,
                    "height": 52.00480724789168,
                    "text": "系列:皇家兵团",
                    "width": 736.5977535922532,
                    "x_center": 489.25,
                    "y_center": 806
                },
                {
                    "degree": -0.9557479292983108,
                    "height": 50.5049014897138,
                    "text": "检验员:检07",
                    "width": 724.627375850137,
                    "x_center": 413.25,
                    "y_center": 865.25
                },
                {
                    "degree": -0.854171486765133,
                    "height": 53.00471656139712,
                    "text": "产品等级:一等品",
                    "width": 890.555552629467,
                    "x_center": 385.25,
                    "y_center": 922
                },
                {
                    "degree": -0.664664769354871,
                    "height": 51.0049014897138,
                    "text": "零售价:¥899",
                    "width": 748.5254230075082,
                    "x_center": 351.25,
                    "y_center": 981
                },
                {
                    "degree": -0.6370513380434146,
                    "height": 46.505318547086404,
                    "text": "整标准:FZ/T81007-2012",
                    "width": 1078,
                    "x_center": 488.25,
                    "y_center": 1038.25
                },
                {
                    "degree": -1.2231141942083803,
                    "height": 51.02450180006326,
                    "text": ":安全类别:GB18401-2010C类",
                    "width": 1078,
                    "x_center": 501.25,
                    "y_center": 1096.5
                },
                {
                    "degree": -0.6281588578191143,
                    "height": 52.00480724789168,
                    "text": "非直接接触皮肤类)",
                    "width": 1031.0323877792068,
                    "x_center": 603.75,
                    "y_center": 1151
                },
                {
                    "degree": -0.9312107901651927,
                    "height": 49.504999500099984,
                    "text": "成份:",
                    "width": 562.6000657542736,
                    "x_center": 313.25,
                    "y_center": 1215.25
                },
                {
                    "degree": -1.0546388557493822,
                    "height": 53.004716561397345,
                    "text": "面料:51聚酯纤维46%棉",
                    "width": 1078,
                    "x_center": 458.75,
                    "y_center": 1272.5
                },
                {
                    "degree": -0.5899807370438808,
                    "height": 49.00510150968557,
                    "text": "3%氨纶",
                    "width": 352.51276595743417,
                    "x_center": 400.25,
                    "y_center": 1333
                },
                {
                    "degree": -1.1051942134834278,
                    "height": 50.504999500099984,
                    "text": "里料:95%聚酯纤维5%氨纶",
                    "width": 1078,
                    "x_center": 477.75,
                    "y_center": 1391.75
                },
                {
                    "degree": -1.0870672448183738,
                    "height": 30.00833101980379,
                    "text": "9535967143841",
                    "width": 955.6695301191737,
                    "x_center": 524.75,
                    "y_center": 1562
                },
                {
                    "degree": -0.35341673688166203,
                    "height": 31.008062419271027,
                    "text": "#96684700720021",
                    "width": 1012.5177776607234,
                    "x_center": 510.25,
                    "y_center": 1734.5
                },
                {
                    "degree": -0.19125210466350528,
                    "height": 41.5060966544097,
                    "text": "此条码仅供内部使用",
                    "width": 1000.5022455039498,
                    "x_center": 511.25,
                    "y_center": 1783.25
                }
            ],
            "request_id": "5ec403e2-d5f1-4dc3-aa51-0109c6e43b56#7236"
        },
        "message": "Success"
    }
    

    在给定吊牌图片中返回识别的文字及位置。

    例图如下:

    Alt text

    HTTP 请求

    POST https://api.aifashion.com/fashion/ocr

    请求参数

    参数名 参数值类型 描述
    image_url String 待识别图片 URL,公网可访问
    image_base64 String 待识别图片二进制数据的 base64 编码

    HTTP 响应结果

    响应结果中主要字段及描述如下:

    字段名 字段值类型 描述
    image Object 图片信息,包括 id、url 以及图的长和宽
    degree String 文字角度
    text String 识别的文字
    x_center Float 文字框横坐标中心点
    y_center Float 文字框纵坐标中心点
    width Float 文字框宽度
    height Float 文字框高度

    服饰智能切图

    curl -X POST \
    https://api.aifashion.com/fashion/crop \
    -H "Content-type: application/json" \
    -H "Authorization: Bearer <ACCESS_TOKEN>" \
    -d '{
        "image_url":"https://s3.aifashion.com/b7e5f8e2beb8bfe0441ed615d2a5a53c.jpg"
    }'
    
    import requests
    
    url = "https://api.aifashion.com/fashion/crop"
    
    payload = {
        'image_url': 'https://s3.aifashion.com/b7e5f8e2beb8bfe0441ed615d2a5a53c.jpg'
    }
    
    headers = {
        'authorization': "Bearer <ACCESS_TOKEN>"
    }
    
    response = requests.request("POST", url, json=payload, headers=headers)
    
    HttpResponse<JsonNode> response = Unirest.post("https://api.aifashion.com/fashion/crop")
        .header("accept", "application/json")
        .header("content-type", "application/json")
        .header("authorization", "Bearer <ACCESS_TOKEN>")
        .body("{\"image_url\":\"https://s3.aifashion.com/b7e5f8e2beb8bfe0441ed615d2a5a53c.jpg\"}")
        .asJson();
    
    <?php
    
    $curl = curl_init();
    
    curl_setopt_array($curl, array(
        CURLOPT_URL => "https://api.aifashion.com/fashion/crop",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_POSTFIELDS => "{\"image_url\":\"https://s3.aifashion.com/b7e5f8e2beb8bfe0441ed615d2a5a53c.jpg\"}",
        CURLOPT_HTTPHEADER => array(
            "authorization: Bearer <ACCESS_TOKEN>",
            "content-type: application/json"
        ),
    ));
    
    $response = curl_exec($curl);
    
    var settings = {
        "async": true,
        "crossDomain": true,
        "url": "https://api.aifashion.com/fashion/crop",
        "method": "POST",
        "headers": {
            "content-type": "application/json",
            "authorization": "Bearer <ACCESS_TOKEN>"
        },
        "processData": false,
        "data": "{\"image_url\":\"https://s3.aifashion.com/b7e5f8e2beb8bfe0441ed615d2a5a53c.jpg\"}"
    }
    
    $.ajax(settings).done(function (response) {
        console.log(response);
    });
    
    require 'uri'
    require 'net/http'
    
    url = URI("https://api.aifashion.com/fashion/crop")
    
    http = Net::HTTP.new(url.host, url.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    
    request = Net::HTTP::Post.new(url)
    request["content-type"] = 'application/json'
    request["authorization"] = 'Bearer <ACCESS_TOKEN>'
    request.body = "{\"image_url\":\"https://s3.aifashion.com/b7e5f8e2beb8bfe0441ed615d2a5a53c.jpg\"}"
    
    response = http.request(request)
    
    package main
    
    import (
        "strings"
        "net/http"
        "io/ioutil"
    )
    
    func main() {
        url := "https://api.aifashion.com/fashion/crop"
        payload := strings.NewReader("{\"image_url\":\"https://s3.aifashion.com/b7e5f8e2beb8bfe0441ed615d2a5a53c.jpg\"}")
    
        req, _ := http.NewRequest("POST", url, payload)
        req.Header.Add("content-type", "application/json")
        req.Header.Add("authorization", "Bearer <ACCESS_TOKEN>")
    
        res, _ := http.DefaultClient.Do(req)
        defer res.Body.Close()
        body, _ := ioutil.ReadAll(res.Body)
    }
    

    上面命令返回如下结果:

    {
        "code":100,
        "data":{
            "crop_results":[
                {
                    "confidence":0.9192447280883789,
                    "height":0.21460118118101051,
                    "name":"领口",
                    "width":0.28800002,
                    "x":0.5863278465270996,
                    "y":0.10730059059050526
                },
                {
                    "confidence":0.9074168777465821,
                    "height":0.2562490076852162,
                    "name":"左肩部",
                    "width":0.2818739084537378,
                    "x":0.4693278465270996,
                    "y":0.1409369542268689
                },
                {
                    "confidence":0.825676612854004,
                    "height":0.23476140437943105,
                    "name":"右肩部",
                    "width":0.25823754481737415,
                    "x":0.7018278465270996,
                    "y":0.12911877240868708
                },
                {
                    "confidence":0.863156852722168,
                    "height":0.19338844793388432,
                    "name":"左袖口",
                    "width":0.21272729272727275,
                    "x":0.3738278465270996,
                    "y":0.3650278633177779
                },
                {
                    "confidence":0.7450266265869141,
                    "height":0.14727274545454555,
                    "name":"右袖口",
                    "width":0.16200002000000013,
                    "x":0.7318278465270995,
                    "y":0.15457331786323253
                },
                {
                    "confidence":1.0070025253295898,
                    "height":0.3509091090909091,
                    "name":"腰部",
                    "width":0.38600002,
                    "x":0.5638278465270996,
                    "y":0.3004824087723234
                },
                {
                    "confidence":0.936206398010254,
                    "height":0.5253988188189895,
                    "name":"裙摆",
                    "width":0.84800002,
                    "x":0.5563278465270997,
                    "y":0.7373005905905052
                }
            ],
            "image":{
                "height":1100,
                "id":"4a625f64bcd9306f282a6be02f482e7c",
                "url":"https://images.aifashion.com/4a/62/5f/4a625f64bcd9306f282a6be02f482e7c.jpg",
                "width":1000
            },
            "object":{
                "category":"连衣裙",
                "category_id":302,
                "confidence":0.9997925162315369,
                "region":{
                    "x1":0.3033278465270996,
                    "x2":0.8033573150634765,
                    "y1":0.031846045135959795,
                    "y2":0.8324948485320667
                }
            },
            "request_id":"855be4d7-7896-4428-bcf1-507a89a835c5#194157"
        },
        "message":"Success"
    }
    

    智能分析给定服装图片,给服装的细节抠图。

    例图如下:

    Alt text

    HTTP 请求

    POST https://api.aifashion.com/fashion/crop

    请求参数

    参数名 参数值类型 描述
    image_url String 待识别图片 URL,公网可访问
    image_base64 String 待识别图片二进制数据的 base64 编码
    region [Float, Float, Float, Float] 待 crop 的服饰区域的相对位置 [x1, y1, x2, y2]

    HTTP 响应结果

    响应结果中主要字段及描述如下:

    字段名 字段值类型 描述
    object Object 检测到的服饰类别
    image Object 图片信息,包括 id、url 以及图的长和宽
    name String 切图的类别
    x Float 切图框中心点 x 坐标
    y Float 切图框中心点 y 坐标
    width Float 切图框宽
    height Float 切图框高
    confidence Float 切图置信度

    数据集接口

    为了使用相似服饰匹配等需要数据集的功能 API,开发者首先需要将自有的服饰图片同步到开放平台上。相对于其它平台的图片搜索接口,该数据集接口着眼于服饰实体,会在后端使用深度学习技术进行服装检测,整个过程更加透明,服饰检索更加精准。我们提供三种数据同步方式:

    同步方式 适用场景
    定制爬取 新创建数据集,需联系技术客服
    控制台 简单操作数据集(暂未开放)
    数据集接口 后台对接,频繁操作数据集

    数据集接口,定义了用户数据在开放平台上的创建、更新和删除方式。

    接口以 RESTFul 风格设计,主要定义了以下实体:

    实体名 中文名 描述
    Dataset 数据集 数据集定义为用于相同目的的一组条目的集合
    Index 数据集索引 数据集基于向量距离的图像索引
    Image 图片条目 一条图片数据,包含图片信息

    后面章节将对实体和相关操作一一介绍。

    数据集实体

    属性名 属性值类型 描述 备注
    id Int 数据集id 系统自动生成,不可修改(用户不可见)
    name String 数据集名称 不能为空,不可重复,只能包含大小写字母、数字和短横线
    type String 数据集类型 默认为image,暂不支持product
    brief String 数据集描述 可以为空
    status String 数据集状态 created 或者 deleted
    index_status String 数据集索引状态 DONE 、PROCESSING、ERROR
    created_at ISO8601 UTC 创建时间 数据集创建时,系统自动生成
    updated_at ISO8601 UTC 更新时间 数据集更新时,系统自动生成

    status 状态的切换:

    index_status状态:

    创建数据集

    创建数据集

    curl -X POST \
    https://api.aifashion.com/datasets/ \
    -H "Content-type: application/json" \
    -H "Authorization: Bearer <ACCESS_TOKEN>" \
    -d '{
          "name": "aifashion-test",
          "type": "image",
          "brief": "test"
    }'
    
    import requests
    
    url = "https://api.aifashion.com/datasets"
    
    payload = "{\n    \"name\": \"aifashion\",\n    \"type\": \"image\", \n    \"brief\": \"test\"\n}"
    headers = {
        'Content-Type': "application/json",
        'Authorization': "bearer <ACCESS_TOKEN>"
        }
    
    response = requests.request("POST", url, data=payload, headers=headers)
    
    print(response.text)
    
    HttpResponse<String> response = Unirest.post("https://api.aifashion.com/datasets")
      .header("Content-Type", "application/json")
      .header("Authorization", "bearer <ACCESS_TOKEN>")
      .body("{\n    \"name\": \"aifashion\",\n    \"type\": \"image\", \n    \"brief\": \"test\"\n}")
      .asString();
    
    
    <?php
    
    $request = new HttpRequest();
    $request->setUrl('https://api.aifashion.com/datasets');
    $request->setMethod(HTTP_METH_POST);
    
    $request->setHeaders(array(
      'Authorization' => 'bearer <ACCESS_TOKEN>',
      'Content-Type' => 'application/json'
    ));
    
    $request->setBody('{
        "name": "aifashion",
        "type": "image",
        "brief": "test"
    }');
    
    try {
      $response = $request->send();
    
      echo $response->getBody();
    } catch (HttpException $ex) {
      echo $ex;
    }
    

    上面命令返回如下结果:

    {
        "code": 100,
        "data": {
          "dataset": {
            "brief": "test",
            "name": "aifashion-test",
            "type": "image",
            "index_status": "DONE"
           }
        },
        "message": "Success"
    }
    

    创建一个数据集。

    HTTP 请求

    POST https://api.aifashion.com/datasets/,暂时每个用户只支持创建最多两个数据集

    请求参数

    参数名 中文名 备注
    name 数据集名称 唯一,不能重复
    type 数据集类型 image,product暂不支持
    brief 数据集描述 添加数据集描述

    获取数据集列表

    获取数据集列表

    curl -X GET \
    https://api.aifashion.com/datasets \
    -H "Content-type: application/json" \
    -H "Authorization: Bearer <ACCESS_TOKEN>"
    
    import requests
    
    url = "https://api.aifashion.com/datasets"
    
    payload = ""
    headers = {
        'Content-Type': "application/json",
        'Authorization': "bearer <ACCESS_TOKEN>"
        }
    
    response = requests.request("GET", url, data=payload, headers=headers)
    
    print(response.text)
    
    HttpResponse<String> response = Unirest.get("https://api.aifashion.com/datasets")
      .header("Content-Type", "application/json")
      .header("Authorization", "bearer <ACCESS_TOKEN>")
      .asString();
    
    <?php
    
    $request = new HttpRequest();
    $request->setUrl('https://api.aifashion.com/datasets');
    $request->setMethod(HTTP_METH_GET);
    
    $request->setHeaders(array(
      'Authorization' => 'bearer <ACCESS_TOKEN>',
      'Content-Type' => 'application/json'
    ));
    
    try {
      $response = $request->send();
    
      echo $response->getBody();
    } catch (HttpException $ex) {
      echo $ex;
    }
    

    上面命令返回如下结果:

    {
        "code": 100,
        "data": {
            "datasets": [
                {
                    "brief": "test_dataset",
                    "name": "aifashion",
                    "index_status": "DONE"
                },
                {
                    "brief": null,
                    "name": "aifashion-test",
                    "index_status": "DONE"
                }
            ],
            "page": 1,
            "per_page": 20,
            "total": 2
        },
        "message": "Success"
    }
    

    获取数据集列表,支持分页。

    HTTP 请求

    GET https://api.aifashion.com/datasets/

    过滤选项

    URL 中支持过滤选项,包括:

    过滤选项 默认值 描述
    page 1 分页的页数
    per_page 20 分页的每页显示数量

    删除指定数据集

    删除指定数据集

    curl -X DELETE \
    https://api.aifashion.com/datasets/aifashion-test \
    -H "Content-type: application/json" \
    -H "Authorization: Bearer <ACCESS_TOKEN>"
    
    import requests
    
    url = "https://api.aifashion.com/datasets/aifashion-test"
    
    payload = ""
    headers = {
        'Content-Type': "application/json",
        'Authorization': "bearer <ACCESS_TOKEN>"
        }
    
    response = requests.request("DELETE", url, data=payload, headers=headers)
    
    print(response.text)
    
    HttpResponse<String> response = Unirest.delete("https://api.aifashion.com/datasets/aifashion-test")
      .header("Content-Type", "application/json")
      .header("Authorization", "bearer <ACCESS_TOKEN>")
      .asString();
    
    <?php
    
    $request = new HttpRequest();
    $request->setUrl('https://api.aifashion.com/datasets/aifashion-test');
    $request->setMethod(HTTP_METH_DELETE);
    
    $request->setHeaders(array(
      'Authorization' => 'bearer <ACCESS_TOKEN>',
      'Content-Type' => 'application/json'
    ));
    
    try {
      $response = $request->send();
    
      echo $response->getBody();
    } catch (HttpException $ex) {
      echo $ex;
    }
    

    上面命令返回如下结果:

    {
        "code": 100,
        "data": {
          "dataset": {
            "brief": "test",
            "name": "aifashion-test",
            "type": "image"
           }
        },
        "message": "Success"
    }
    

    使用 dataset_name 作为标识查找并删除数据集。

    数据集的删除为软删除,即通过 status 字段表示数据集的删除状态,而并不从数据库中真正删除。

    HTTP 请求

    DELETE https://api.aifashion.com/datasets/{dataset_name}

    图片条目实体

    属性名 属性值类型 描述 备注
    id Int64 条目 id 系统自动生成,不可修改(用户不可见)
    image_sign Int64 实体签名 标识上传图片实体的唯一签名,用于之后的查询、和删除,用户需本地保存
    brief String 图片描述 用户自定义上传,建议包含用户可以索引到图片的信息,如图片url,图片在用户数据库中的ID等
    class_id Int 类别 0—1023,用户根据此字段对图片进行类别后筛选(暂不支持,近期更新)
    status String 图片状态 created, indexed, to_deleted, deleted
    category int 检测到的服饰类别 0-7,具体说明见下
    created_at ISO8601 UTC 创建时间 数据集创建时,系统自动生成
    updated_at ISO8601 UTC 更新时间 数据集更新时,系统自动生成

    status 状态的切换:

    category:

    创建图片条目

    创建图片条目

    curl -X POST \
    https://api.aifashion.com/datasets/aifashion/images/ \
    -H "Content-type: application/json" \
    -H "Authorization: Bearer <ACCESS_TOKEN>" \
    -d '{
      "image_url": "https://s3.aifashion.com/aaa.jpg",
        "brief": "上衣",
        "class_id": 1
    }'
    
    import requests
    
    url = "https://api.aifashion.com/datasets/aifashion/images"
    
    payload = "{\n\t\"image_url\": \"https://s3.aifashion.com/aaa.jpg\",\n\t\"brief\": \"上衣\",\n\t\"class_id\": 1\n}"
    headers = {
        'Content-Type': "application/json",
        'Authorization': "bearer <ACCESS_TOKEN>",
        }
    
    response = requests.request("POST", url, data=payload, headers=headers)
    
    print(response.text)
    
    HttpResponse<String> response = Unirest.post("https://api.aifashion.com/datasets/aifashion/images")
      .header("Content-Type", "application/json")
      .header("Authorization", "bearer <ACCESS_TOKEN>")
      .body("{\n\t\"image_url\": \"https://s3.aifashion.com/aaa.jpg\",\n\t\"brief\": \"上衣\",\n\t\"class_id\": 1\n}")
      .asString();
    
    <?php
    
    $request = new HttpRequest();
    $request->setUrl('https://api.aifashion.com/datasets/aifashion/images');
    $request->setMethod(HTTP_METH_POST);
    
    $request->setHeaders(array(
      'Authorization' => 'bearer <ACCESS_TOKEN>',
      'Content-Type' => 'application/json'
    ));
    
    $request->setBody('{
        "image_url": "https://s3.aifashion.com/aaa.jpg",
        "brief": "上衣",
        "class_id": 1
    }');
    
    try {
      $response = $request->send();
    
      echo $response->getBody();
    } catch (HttpException $ex) {
      echo $ex;
    }
    
    {
        "code": 100,
        "data": {
           "image": {
              "brief": "上衣",
              "category": 2,
              "class_id": 1,
              "image_sign": 4750591673602550921,
              "status": "created"
            }
        },
        "message": "Success"
    }
    

    在指定数据集中创建图片条目

    HTTP 请求

    POST https://api.aifashion.com/datasets/{dataset_name}/images/

    请求参数

    参数名 中文名 备注
    image_url 图片 URL 可公网访问
    image_base64 图片Base64编码 和 image_url 二选一
    brief 图片描述 图片在用户端的信息,如url或在数据库中的id等
    class_id 后筛选类别 可以为空,0-1023

    获取图片条目列表

    获取商品条目列表

    curl -X GET \
    https://api.aifashion.com/datasets/aifashion/images/?page=1&per_page=20 \
    -H "Content-type: application/json" \
    -H "Authorization: Bearer <ACCESS_TOKEN>"
    
    import requests
    
    url = "https://api.aifashion.com/datasets/aifashion/images"
    
    payload = ""
    headers = {
        'Content-Type': "application/json",
        'Authorization': "bearer <ACCESS_TOKEN>",
        }
    
    response = requests.request("GET", url, data=payload, headers=headers)
    
    print(response.text)
    
    HttpResponse<String> response = Unirest.get("https://api.aifashion.com/datasets/aifashion/images")
      .header("Content-Type", "application/json")
      .header("Authorization", "bearer <ACCESS_TOKEN>")
      .asString();
    
    <?php
    
    $request = new HttpRequest();
    $request->setUrl('https://api.aifashion.com/datasets/aifashion/images');
    $request->setMethod(HTTP_METH_GET);
    
    $request->setHeaders(array(
      'Authorization' => 'bearer <ACCESS_TOKEN>',
      'Content-Type' => 'application/json'
    ));
    
    try {
      $response = $request->send();
    
      echo $response->getBody();
    } catch (HttpException $ex) {
      echo $ex;
    }
    

    上面命令返回如下结果:

    {
        "code": 100,
        "data": {
            "images": [
                {
                    "brief": "http://s3.aifashion.com/aaa.jpg",
                    "category": 2,
                    "class_id": 1,
                    "image_sign": 5157678754262692073,
                    "status": "indexed"
                },
                {
                    "brief": "http://s3.aifashion.com/bbb.jpg",
                    "category": 2,
                    "class_id": 1,
                    "image_sign": 5152389551597825385,
                    "status": "created"
                },
            ],
            "page": 1,
            "per_page": 20,
            "total": 5
        },
        "message": "Success"
    }
    

    获取指定数据集图片条目列表,支持分页。

    HTTP 请求

    GET https://api.aifashion.com/datasets/{dataset_name}/images/

    过滤选项

    URL 中支持分页筛选,包括:

    过滤选项 默认值 描述
    page 1 分页的页数
    per_page 20 分页的每页显示数量

    获取指定图片条目

    curl -X GET \
    https://api.aifashion.com/datasets/aifashion/images/5157678754262692073 \
    -H "Content-type: application/json" \
    -H "Authorization: Bearer <ACCESS_TOKEN>" 
    
    import requests
    
    url = "https://api.aifashion.com/datasets/aifashion/images/5157678754262692073"
    
    payload = ""
    headers = {
        'Content-Type': "application/json",
        'Authorization': "bearer <ACCESS_TOKEN>"
        }
    
    response = requests.request("GET", url, data=payload, headers=headers)
    
    print(response.text)
    
    HttpResponse<String> response = Unirest.get("https://api.aifashion.com/datasets/aifashion/images/5157678754262692073")
      .header("Content-Type", "application/json")
      .header("Authorization", "bearer <ACCESS_TOKEN>")
    
    <?php
    
    $request = new HttpRequest();
    $request->setUrl('https://api.aifashion.com/datasets/aifashion/images/5157678754262692073');
    $request->setMethod(HTTP_METH_GET);
    
    $request->setHeaders(array(
      'Authorization' => 'bearer <ACCESS_TOKEN>',
      'Content-Type' => 'application/json'
    ));
    
    try {
      $response = $request->send();
    
      echo $response->getBody();
    } catch (HttpException $ex) {
      echo $ex;
    }
    
    {
        "code": 100,
        "data":{
          "image": {
            "brief": "http://s3.aifashion.com/aaa.jpg",
            "category": 2,
            "class_id": 1,
            "image_sign": 5157678754262692073,
            "status": "indexed"
            }
        },
        "message": "Success"
    }
    

    在数据集中获取指定图片条目

    HTTP 请求

    GET https://api.aifashion.com/datasets/{dataset_name}/images/{image_sign}

    更新指定图片条目

    curl -X PATCH \
    https://api.aifashion.com/datasets/aifashion/images/5157678754262692073 \
    -H "Content-type: application/json" \
    -H "Authorization: Bearer <ACCESS_TOKEN>"
    -d '{
        "brief": "http://s3.aifashion.com/ccc.jpg"
    }'
    
    import requests
    
    url = "https://api.aifashion.com/datasets/aifashion/images/5157678754262692073"
    
    payload = "{\n\t\"brief\": \"http://s3.aifashion.com/ccc.jpg\"\n}"
    headers = {
        'Content-Type': "application/json",
        'Authorization': "bearer <ACCESS_TOKEN>"
        }
    
    response = requests.request("PATCH", url, data=payload, headers=headers)
    
    print(response.text)
    
    HttpResponse<String> response = Unirest.patch("https://api.aifashion.com/datasets/aifashion/images/5157678754262692073")
      .header("Content-Type", "application/json")
      .header("Authorization", "bearer <ACCESS_TOKEN>")
      .body("{\n\t\"brief\": \"http://s3.aifashion.com/ccc.jpg\"\n}")
      .asString();
    
    <?php
    
    HttpRequest::methodRegister('PATCH');
    $request = new HttpRequest();
    $request->setUrl('https://api.aifashion.com/datasets/aifashion/images/5157678754262692073');
    $request->setMethod(HttpRequest::HTTP_METH_PATCH);
    
    $request->setHeaders(array(
      'Authorization' => 'bearer <ACCESS_TOKEN>',
      'Content-Type' => 'application/json'
    ));
    
    $request->setBody('{
        "brief": "http://s3.aifashion.com/ccc.jpg"
    }');
    
    try {
      $response = $request->send();
    
      echo $response->getBody();
    } catch (HttpException $ex) {
      echo $ex;
    }
    
    {
        "code": 100,
        "data": {
          "image":{
              "brief": "http://s3.aifashion.com/ccc.jpg",
              "category": 2,
              "class_id": 1,
              "image_sign": 5157678754262692073,
              "status": "indexed"
          }
        }
        "message": "Success"
    }
    

    在数据集中更新指定图片条目

    图片条目中可以被修改的字段有:

    字段名 中文名 备注
    brief 图片描述
    class_id 图片标签列表

    HTTP 请求

    PATCH https://api.aifashion.com/datasets/{dataset_name}/images/{image_sign}

    删除指定图片条目

    删除图片条目

    curl -X DELETE \
    https://api.aifashion.com/datasets/aifashion/images/5157678754262692073 \
    -H "Content-type: application/json" \
    -H "Authorization: Bearer <ACCESS_TOKEN>"
    
    import requests
    
    url = "https://api.aifashion.com/datasets/aifashion/images/5157678754262692073"
    
    payload = ""
    headers = {
        'Authorization': "bearer <ACCESS_TOKEN>"
        }
    
    response = requests.request("DELETE", url, data=payload, headers=headers)
    
    print(response.text)
    
    HttpResponse<String> response = Unirest.delete("https://api.aifashion.com/datasets/aifashion/images/5157678754262692073")
      .header("Authorization", "bearer <ACCESS_TOKEN>")
      .asString();
    
    <?php
    
    $request = new HttpRequest();
    $request->setUrl('https://api.aifashion.com/datasets/aifashion/images/5157678754262692073');
    $request->setMethod(HTTP_METH_DELETE);
    
    $request->setHeaders(array(
      'Authorization' => 'bearer <ACCESS_TOKEN>'
    ));
    
    try {
      $response = $request->send();
    
      echo $response->getBody();
    } catch (HttpException $ex) {
      echo $ex;
    }
    

    上面命令返回如下结果:

    {
        "code": 100,
        "data": {
          "image":{
            "brief": "上衣",
            "category": 2,
            "class_id": 1,
            "image_sign": 5157678754262692073,
            "status": "to_deleted"
            }
        },
        "message": "Success"
    }
    

    使用 image_sign 作为标识查找并删除图片条目。

    HTTP 请求

    DELETE https://api.aifashion.com/datasets/{dataset_name}/images/{image_sign}

    更新数据集索引

    curl -X GET \
    https://api.aifashion.com/datasets/aifashion/update_index \
    -H "Content-type: application/json" \
    -H "Authorization: Bearer <ACCESS_TOKEN>"
    
    import requests
    
    url = "https://api.aifashion.com/datasets/aifashion/update_index"
    
    payload = ""
    headers = {
        'Authorization': "bearer <ACCESS_TOKEN>"
        }
    
    response = requests.request("GET", url, data=payload, headers=headers)
    
    print(response.text)
    
    HttpResponse<String> response = Unirest.get("https://api.aifashion.com/datasets/aifashion/update_index")
      .header("Authorization", "bearer <ACCESS_TOKEN>")
      .asString();
    
    {
        "code": 100,
        "data": {
          "image":{
            "brief": "上衣",
            "category": 2,
            "class_id": 1,
            "image_sign": 5157678754262692073,
            "status": "to_deleted"
            }
        },
        "message": "Success"
    }
    
    <?php
    
    $request = new HttpRequest();
    $request->setUrl('https://api.aifashion.com/datasets/aifashion/update_index');
    $request->setMethod(HTTP_METH_GET);
    
    $request->setHeaders(array(
      'Authorization' => 'bearer <ACCESS_TOKEN>'
    ));
    
    try {
      $response = $request->send();
    
      echo $response->getBody();
    } catch (HttpException $ex) {
      echo $ex;
    }
    

    更新数据集中的索引,新插入的图片或者删除的图片只有在更新索引后,才能在搜索中生效

    HTTP 请求

    GET https://api.aifashion.com/datasets/{dataset_name}/update_index

    常量

    服饰类别

    开放平台服饰检测当前支持的类别包括:

    ID 一级类别 Sub-ID 二级类别 简要描述

    10

    上装
    101 上衣 上半身穿着,长度不超过大腿中部且不适宜套在其他外套、上衣之上
    102 外套 又称为大衣,穿在最外的服装,前端有钮扣或者拉链

    20

    裤装
    201 裤子 长裤、短裤等
    202 连体裤 背带裤等连体裤装

    30

    裙装
    301 半身裙 穿着在下身的单独的裙装
    302 连衣裙 裙子的一类,指吊带背心和裙子连在一起的服装
    40 鞋靴 401 鞋靴 运动鞋、靴子、高跟鞋等

    50

    箱包
    501 背包、挎包、手提包等
    502 旅行箱、拉杆箱等

    60

    贴身服饰
    601 内裤 男士内裤、女士内裤等
    602 女士内衣 女士文胸等
    603 女士泳装 女士泳装、比基尼




    90




    其它
    901 帽子 帽子
    902 太阳镜 太阳镜
    903 配饰 耳环、手链等珠宝首饰
    904 腕表 腕表

    支持语言

    服饰命名当前支持的语言,包括:

    代码 语言 描述
    zh_cn 简体中文
    zh_hk 繁体中文
    en 英文
    ja 日语
    ko 韩语
    fr 法语
    de 德语
    es 西班牙语
    pt 葡萄牙语
    ar 阿拉伯语

    人体关键点

    ID 英文名称 中文名称
    0 nose 鼻子
    1 left_eye 左眼
    2 right_eye 右眼
    3 left_ear 左耳
    4 right_ear 右耳
    5 left_shoulder 左肩
    6 right_shoulder 右肩
    7 left_elbow 左肘
    8 right_elbow 右肘
    9 left_wrist 左腕
    10 right_wrist 右腕
    11 left_hip 左臀
    12 right_hip 右臀
    13 left_knee 左膝
    14 right_knee 右膝
    15 left_ankle 左踝
    16 right_ankle 右踝

    错误

    当 API 调用出错时,返回的 HTTP 响应结果中带有错误信息,错误信息由两部分组成:HTTP 状态码(status code)和 JSON 序列化的 HTTP body。

    一般的,API 调用错误可以分为协议错误和逻辑错误。

    协议错误

    协议错误为调用 API 时没有遵照 HTTP 规范或标准而易产生的错误,出错信息体现在 HTTP 状态码中。 HTTP 状态码的定义和相应 RFC 规范可以参照百度百科

    错误发生时,HTTP 状态码一般为 4xx 或 5xx,可能状态码列表如下:

    状态码 错误信息 错误描述
    400 Bad Request 请求出现语法错误
    401 Unauthorized 请求未授权
    403 Forbidden 禁止访问
    404 Not Found 资源未找到
    405 Method Not Allowed 请求方法不适用
    406 Not Acceptable 资源MIME类型不兼容
    413 Request Entity Too Large 请求实体过大
    429 Too Many Requests 请求次数过多或过频繁
    500 Internal Server Error 服务器内部错误
    503 Service Unavailable 服务不可用

    逻辑错误

    调用 API 时没有出现协议错误,但返回结果不正确,通常是逻辑错误。

    API 返回的具体信息体现在 HTTP body 中的 codemessage 字段中。

    所有 code 不为 100 的 API 调用都出现了逻辑错误,可能的逻辑错误包括:

    code message 错误描述
    40011 Failed to download image 无法使用 image_url 下载图片
    40012 Invalid image base64 image_base64 无法解码
    40013 Image size must be at least 200x200 pixels 图片尺寸要大于 200x200 像素
    40014 Image size must be smaller than 2048x2048 pixels 图片尺寸要小于 2048x2048 像素
    40015 Image must be less than 2 MB 图片大小不能超过 2 MB
    40016 Corrupted image 图片损坏
    40017 Image format not supported 图片格式不支持
    40021 Invalid parameters 请求参数不符合文档规范
    40022 Dataset not found 无法找到指定数据集
    40023 Item not found 无法找到指定条目
    40024 Item category not supported 条目服饰类别不支持
    40025 Invalid region coordinates region 坐标值不合法
    40026 Language not supported language 指定的语言不被支持
    40051 Invalid fields 字段不合法
    40052 Field name must contain only letters, numbers and dashes 字段只能包含大小写字母、数字和短横线
    40053 Field name must be in values 字段值必须在 values 数组中。
    40054 Field name must be of type type_name 字段必须为指定类型
    40055 Field name length must be less than max_length 字段长度不能超出限制
    40056 Field name duplicate 字段必须唯一
    40057 Field name should not be null 字段不能为空
    40091 Internal error 服务器内部错误
    40099 Unexpected error 未知错误

    常见问题