作者:俏巴
概述
货架商品识别与管理(Retail Image Recognition)是基于深度学习、图像检测、图像识别等技术,为新零售品牌商/经销商提供AI商品识别能力的阿里云产品;适用于货架商品识别、陈列识别、形象化识别等多个业务应用场景中,提供对渠道的数据全面精准洞察,助力渠道业务管理实现数字化、智能化的转型升级。目前该产品还在公测预览版免费试用阶段,下面通过结合Python SDK介绍该产品的使用流程。
操作步骤
1、服务开通
申请一般需要一到三个工作日审批通过,如果想加快审批流程,可以提工单,注意提工单的时候带上申请的账户Uid。
2、创建项目
3、控制台快速测试
4、Python SDK测试
- 4.1 Python SDK的安装可以参考链接
- 4.2 Code Sample
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.request import CommonRequest
import json
import time
# DefaultProfile.getProfile的参数分别是access_key_id, access_key_secret,region(目前固定为杭州) https://yq.aliyun.com/articles/693979
client = AcsClient("LTAIOZZg********", "v7CjUJCMk7j9aKduMAQLjy********", "cn-hangzhou")
# createTask API 创建商品识别任务
def createTask(Appkey:"实例ID",ImageLeftTop:"影像左上"):
request = CommonRequest()
request.set_method("POST")
request.set_domain("retailir.cn-hangzhou.aliyuncs.com")
request.set_action_name("CreateTask")
request.set_version("2019-09-06")
request.set_accept_format('json')
request.add_body_params("Appkey", Appkey)
request.add_body_params("TaskName", "test1")
request.add_body_params("ImageLeftTop", ImageLeftTop)
response = client.get_response(request)
response_str = str(response[2], 'utf-8') # bytes 转 string
print(response_str) # 打印输出结果
JobId = (json.loads(response_str))["Task"]["JobId"] # 获取任务id
return JobId
# getTask API 获取提交任务的结果
def getTask(Appkey:"实例ID", JobId:"任务Id"):
request = CommonRequest()
request.set_method("POST")
request.set_domain("retailir.cn-hangzhou.aliyuncs.com")
request.set_action_name("GetTask")
request.set_version("2019-09-06")
request.set_accept_format('json')
request.add_body_params("Appkey", Appkey)
request.add_body_params("JobId", JobId)
response = client.get_response(request)
response_str = str(response[2], 'utf-8') # bytes 转 string
print(response_str) # 打印输出结果
if __name__ == '__main__':
Appkey = "GGU4dslp********"
ImageLeftTop = "https://img.alicdn.com/tfs/TB1OFfegEY1gK0jSZFCXXcwqXXa-720-1440.png"
JobId = createTask(Appkey, ImageLeftTop)
time.sleep(10) # 创建完的Task需要后端等待一段时间才能获取运行结果
getTask(Appkey, JobId)
- 4.3 代码测试结果
{"RequestId":"99020@73d2c29d-4bd2-4d44-bc72-3ab674072d8f","Task":{"Status":"INIT","Appkey":"GGU4dslp********","JobId":"29ffee3863504d1493b4104600a6283b","Namespace":"ShelfInsight","Request":"{\"images\":[{\"path\":\"https://img.alicdn.com/tfs/TB1OFfegEY1gK0jSZFCXXcwqXXa-720-1440.png\",\"position\":{\"x\":0,\"y\":1}}]}","UserId":"1848217816617278","Version":"0","Progress":0},"ResultCode":0,"ResultMessage":"SUCCESS"}
{"RequestId":"99002@d500a6d0-6876-4cf8-babf-92fb7da65deb","Task":{"StatusCode":"20000000","Appkey":"GGU4dslp********","Response":"{\"data\":[{\"col_idx\":0,\"conf\":0.9962239265441895,\"img_idx\":0,\"layer_idx\":0,\"name\":\",品客酸乳酪洋葱味110g\",\"skuid\":9,\"x1\":55,\"x2\":108,\"y1\":112,\"y2\":269},{\"col_idx\":1,\"conf\":0.5302411317825317,\"img_idx\":0,\"layer_idx\":0,\"name\":\",others\",\"skuid\":0,\"x1\":102,\"x2\":153,\"y1\":115,\"y2\":269},{\"col_idx\":2,\"conf\":0.8753538727760315,\"img_idx\":0,\"layer_idx\":0,\"name\":\",品客番茄味110g\",\"skuid\":6,\"x1\":149,\"x2\":201,\"y1\":117,\"y2\":274},{\"col_idx\":3,\"conf\":0.999996542930603,\"img_idx\":0,\"layer_idx\":0,\"name\":\",others\",\"skuid\":0,\"x1\":200,\"x2\":272,\"y1\":127,\"y2\":278},{\"col_idx\":4,\"conf\":0.9997768998146057,\"img_idx\":0,\"layer_idx\":0,\"name\":\",others\",\"skuid\":0,\"x1\":270,\"x2\":332,\"y1\":103,\"y2\":278},{\"col_idx\":5,\"conf\":0.9999973773956299,\"img_idx\":0,\"layer_idx\":0,\"name\":\",others\",\"skuid\":0,\"x1\":326,\"x2\":383,\"y1\":100,\"y2\":282},{\"col_idx\":6,\"conf\":0.9999891519546509,\"img_idx\":0,\"layer_idx\":0,\"name\":\",others\",\"skuid\":0,\"x1\":379,\"x2\":441,\"y1\":102,\"y2\":283},{\"col_idx\":7,\"conf\":0.9999785423278809,\"img_idx\":0,\"layer_idx\":0,\"name\":\",others\",\"skuid\":0,\"x1\":431,\"x2\":568,\"y1\":173,\"y2\":289},{\"col_idx\":8,\"conf\":0.9982232451438904,\"img_idx\":0,\"layer_idx\":0,\"name\":\",others\",\"skuid\":0,\"x1\":560,\"x2\":630,\"y1\":108,\"y2\":288},{\"col_idx\":9,\"conf\":0.9994756579399109,\"img_idx\":0,\"layer_idx\":0,\"name\":\",others\",\"skuid\":0,\"x1\":616,\"x2\":688,\"y1\":106,\"y2\":286},{\"col_idx\":0,\"conf\":0.9999978542327881,\"img_idx\":0,\"layer_idx\":1,\"name\":\",others\",\"skuid\":0,\"x1\":72,\"x2\":184,\"y1\":333,\"y2\":485},{\"col_idx\":1,\"conf\":0.997977077960968,\"img_idx\":0,\"layer_idx\":1,\"name\":\",others\",\"skuid\":0,\"x1\":164,\"x2\":266,\"y1\":340,\"y2\":485},{\"col_idx\":2,\"conf\":0.9996862411499023,\"img_idx\":0,\"layer_idx\":1,\"name\":\",others\",\"skuid\":0,\"x1\":257,\"x2\":363,\"y1\":348,\"y2\":495},{\"col_idx\":3,\"conf\":0.9999994039535522,\"img_idx\":0,\"layer_idx\":1,\"name\":\",others\",\"skuid\":0,\"x1\":354,\"x2\":401,\"y1\":349,\"y2\":495},{\"col_idx\":4,\"conf\":1,\"img_idx\":0,\"layer_idx\":1,\"name\":\",others\",\"skuid\":0,\"x1\":401,\"x2\":448,\"y1\":349,\"y2\":497},{\"col_idx\":5,\"conf\":0.9999985694885254,\"img_idx\":0,\"layer_idx\":1,\"name\":\",others\",\"skuid\":0,\"x1\":441,\"x2\":551,\"y1\":344,\"y2\":499},{\"col_idx\":6,\"conf\":0.9971520900726318,\"img_idx\":0,\"layer_idx\":1,\"name\":\",others\",\"skuid\":0,\"x1\":555,\"x2\":673,\"y1\":350,\"y2\":509},{\"col_idx\":0,\"conf\":0.9999005794525146,\"img_idx\":0,\"layer_idx\":2,\"name\":\",others\",\"skuid\":0,\"x1\":68,\"x2\":150,\"y1\":505,\"y2\":653},{\"col_idx\":1,\"conf\":0.9999954700469971,\"img_idx\":0,\"layer_idx\":2,\"name\":\",others\",\"skuid\":0,\"x1\":146,\"x2\":198,\"y1\":531,\"y2\":654},{\"col_idx\":2,\"conf\":0.9950171113014221,\"img_idx\":0,\"layer_idx\":2,\"name\":\",others\",\"skuid\":0,\"x1\":191,\"x2\":286,\"y1\":530,\"y2\":661},{\"col_idx\":3,\"conf\":0.9942479133605957,\"img_idx\":0,\"layer_idx\":2,\"name\":\",others\",\"skuid\":0,\"x1\":264,\"x2\":352,\"y1\":547,\"y2\":668},{\"col_idx\":4,\"conf\":0.9999996423721313,\"img_idx\":0,\"layer_idx\":2,\"name\":\",others\",\"skuid\":0,\"x1\":346,\"x2\":466,\"y1\":559,\"y2\":629},{\"col_idx\":5,\"conf\":0.9999014139175415,\"img_idx\":0,\"layer_idx\":2,\"name\":\",others\",\"skuid\":0,\"x1\":379,\"x2\":453,\"y1\":622,\"y2\":676},{\"col_idx\":6,\"conf\":0.8119478225708008,\"img_idx\":0,\"layer_idx\":2,\"name\":\",others\",\"skuid\":0,\"x1\":459,\"x2\":582,\"y1\":554,\"y2\":685},{\"col_idx\":7,\"conf\":0.9999927282333374,\"img_idx\":0,\"layer_idx\":2,\"name\":\",others\",\"skuid\":0,\"x1\":554,\"x2\":619,\"y1\":582,\"y2\":692},{\"col_idx\":0,\"conf\":0.9999759197235107,\"img_idx\":0,\"layer_idx\":3,\"name\":\",others\",\"skuid\":0,\"x1\":98,\"x2\":138,\"y1\":690,\"y2\":804},{\"col_idx\":1,\"conf\":0.9999908208847046,\"img_idx\":0,\"layer_idx\":3,\"name\":\",others\",\"skuid\":0,\"x1\":134,\"x2\":194,\"y1\":699,\"y2\":809},{\"col_idx\":2,\"conf\":0.9979485869407654,\"img_idx\":0,\"layer_idx\":3,\"name\":\",others\",\"skuid\":0,\"x1\":191,\"x2\":237,\"y1\":689,\"y2\":811},{\"col_idx\":3,\"conf\":0.9999998807907104,\"img_idx\":0,\"layer_idx\":3,\"name\":\",others\",\"skuid\":0,\"x1\":234,\"x2\":275,\"y1\":698,\"y2\":813},{\"col_idx\":4,\"conf\":0.9999997615814209,\"img_idx\":0,\"layer_idx\":3,\"name\":\",others\",\"skuid\":0,\"x1\":272,\"x2\":312,\"y1\":696,\"y2\":819},{\"col_idx\":5,\"conf\":0.9999927282333374,\"img_idx\":0,\"layer_idx\":3,\"name\":\",others\",\"skuid\":0,\"x1\":309,\"x2\":357,\"y1\":695,\"y2\":824},{\"col_idx\":6,\"conf\":0.9559051990509033,\"img_idx\":0,\"layer_idx\":3,\"name\":\",others\",\"skuid\":0,\"x1\":352,\"x2\":395,\"y1\":702,\"y2\":829},{\"col_idx\":7,\"conf\":0.9999561309814453,\"img_idx\":0,\"layer_idx\":3,\"name\":\",others\",\"skuid\":0,\"x1\":394,\"x2\":441,\"y1\":708,\"y2\":834},{\"col_idx\":8,\"conf\":0.9999920129776001,\"img_idx\":0,\"layer_idx\":3,\"name\":\",others\",\"skuid\":0,\"x1\":436,\"x2\":479,\"y1\":709,\"y2\":837},{\"col_idx\":9,\"conf\":0.9999998807907104,\"img_idx\":0,\"layer_idx\":3,\"name\":\",others\",\"skuid\":0,\"x1\":472,\"x2\":518,\"y1\":712,\"y2\":842},{\"col_idx\":10,\"conf\":0.9999518394470215,\"img_idx\":0,\"layer_idx\":3,\"name\":\",others\",\"skuid\":0,\"x1\":510,\"x2\":618,\"y1\":731,\"y2\":856},{\"col_idx\":0,\"conf\":0.9999423027038574,\"img_idx\":0,\"layer_idx\":4,\"name\":\",others\",\"skuid\":0,\"x1\":109,\"x2\":161,\"y1\":843,\"y2\":959},{\"col_idx\":1,\"conf\":0.9999912977218628,\"img_idx\":0,\"layer_idx\":4,\"name\":\",others\",\"skuid\":0,\"x1\":152,\"x2\":209,\"y1\":859,\"y2\":963},{\"col_idx\":2,\"conf\":0.9999891519546509,\"img_idx\":0,\"layer_idx\":4,\"name\":\",others\",\"skuid\":0,\"x1\":207,\"x2\":264,\"y1\":864,\"y2\":965},{\"col_idx\":3,\"conf\":0.9999963045120239,\"img_idx\":0,\"layer_idx\":4,\"name\":\",others\",\"skuid\":0,\"x1\":264,\"x2\":321,\"y1\":866,\"y2\":972},{\"col_idx\":4,\"conf\":0.8745280504226685,\"img_idx\":0,\"layer_idx\":4,\"name\":\",品客番茄味110g\",\"skuid\":6,\"x1\":321,\"x2\":365,\"y1\":861,\"y2\":976},{\"col_idx\":5,\"conf\":0.9999991655349731,\"img_idx\":0,\"layer_idx\":4,\"name\":\",others\",\"skuid\":0,\"x1\":367,\"x2\":428,\"y1\":878,\"y2\":988},{\"col_idx\":6,\"conf\":0.9999672174453735,\"img_idx\":0,\"layer_idx\":4,\"name\":\",others\",\"skuid\":0,\"x1\":427,\"x2\":471,\"y1\":883,\"y2\":995},{\"col_idx\":7,\"conf\":0.9999639987945557,\"img_idx\":0,\"layer_idx\":4,\"name\":\",others\",\"skuid\":0,\"x1\":470,\"x2\":522,\"y1\":891,\"y2\":1003},{\"col_idx\":8,\"conf\":0.9998511075973511,\"img_idx\":0,\"layer_idx\":4,\"name\":\",others\",\"skuid\":0,\"x1\":516,\"x2\":579,\"y1\":896,\"y2\":1010}],\"stitched_info\":[{\"input_id\":\"0\",\"output_id\":-1,\"path\":\"https://img.alicdn.com/tfs/TB1OFfegEY1gK0jSZFCXXcwqXXa-720-1440.png\"}],\"version\":\"Weichaishi v0.2.5\"}\n","Request":"{\"images\":[{\"path\":\"https://img.alicdn.com/tfs/TB1OFfegEY1gK0jSZFCXXcwqXXa-720-1440.png\",\"position\":{\"x\":0,\"y\":1}}]}","UserId":"1848217816617278","LastUpdateTime":1577511690932,"Progress":100,"Status":"COMPLETED","JobId":"29ffee3863504d1493b4104600a6283b","CreateTime":1577511690000,"StatusMessage":"SUCCESS","Namespace":"ShelfInsight","Version":"1"},"ResultCode":0,"ResultMessage":"SUCCESS"}
5、其它开发语言的调用问题
目前提供的两个API接口都是通过pop接口对接,所以使用阿里云的core sdk均可做认证对接,然后使用CommonRequest()方法即可完成调用过程。相关语言可以参考阿里云新版人脸识别综述 新版本SDK调用示例参考部分即可。