阿里云机器学习ModelHub使用Quick Start

Step By Step

1、获取模型
2、模型在线部署
3、SDK调用部署模型


一、获取模型
在机器学习PAI模型管理获取模型,控制台地址

阿里云机器学习ModelHub使用Quick Start

  • 货架商品计数模型介绍
该模型采用YoloV5检测模型和细粒度分类模型两阶段串联,能够返回常见物体的类别信息、检测框位置及图像中每类商品的计数。目前,该模型共支持171种不同的瓶饮SKU类别,类别名称列表请参见drink_unique_hierarchy
二、模型在线部署
  • 2.1 模型部署

阿里云机器学习ModelHub使用Quick Start

阿里云机器学习ModelHub使用Quick Start

阿里云机器学习ModelHub使用Quick Start

注意:GPU资源部署配置要求:使用T4显卡,不低于4 核,内存不低于16G。如未按上述配置要求部署,会导致部署失败或服务无法调用

  • 2.2 模型调用参数获取

阿里云机器学习ModelHub使用Quick Start

阿里云机器学习ModelHub使用Quick Start

三、Python SDK调用部署模型
  • 3.1 SDK 安装
pip install -U eas-prediction --user
  • 3.2 Code Sample
#!/usr/bin/env python
from eas_prediction import PredictClient
from eas_prediction import StringRequest
import base64

# 读取本地图片
filenamePath = "C:\\Users\\Administrator\\Desktop\\29.jpg"  # 测试图片存放在项目目录下
base64_data = ''
with open(filenamePath, "rb") as f:
    base64_data = base64.b64encode(f.read())

if __name__ == '__main__':

    # 完整的接口地址:http://17214402********.cn-shanghai.pai-eas.aliyuncs.com/api/predict/demo
    client = PredictClient('17214402********.cn-shanghai.pai-eas.aliyuncs.com', 'demo')
    #  注意上面的client = PredictClient()内填入的信息,是通过对调用信息窗口(下图)中获取的访问地址的拆分
    client.set_token('YmJiOWZhMDQ**************')

    #  Token信息在“EAS控制台—服务列表—服务—调用信息—公网地址调用—Token”中获取
    client.init()
    requestBody = '{"image":"'+base64_data.decode()+'"}'
    print(requestBody)

    request = StringRequest(requestBody)
    #  输入请求请根据模型进行构造,此处仅以字符串为输入输出的程序示例
    resp = client.predict(request)
    print(resp)
  • 3.3 The Result

b'{"request_id": "b1a06aec-0d2e-4513-af84-75d92302de4a", "success": true, "ori_img_shape": [1280, 720], "detection_boxes": [[327.481201171875, 714.094482421875, 404.125244140625, 937.6309814453125], [408.24554443359375, 716.003662109375, 479.36468505859375, 929.5745849609375], [247.078369140625, 420.04150390625, 331.18603515625, 637.4111328125], [337.09954833984375, 424.40948486328125, 413.90777587890625, 636.4845581054688], [246.8751220703125, 700.114990234375, 320.654541015625, 948.1328125], [536.753662109375, 456.63800048828125, 611.7236328125, 645.9170532226562], [417.15240478515625, 460.482421875, 465.25823974609375, 639.4288330078125], [557.0704345703125, 687.0117797851562, 605.61328125, 911.1828002929688], [407.97161865234375, 979.4371337890625, 466.75860595703125, 1094.9622802734375], [91.69937133789062, 757.7470703125, 157.96780395507812, 937.9561767578125], [489.9420166015625, 687.8649291992188, 553.0584716796875, 921.3740844726562], [532.0812377929688, 956.2311401367188, 580.8801879882812, 1067.905517578125], [172.47622680664062, 467.41741943359375, 235.27001953125, 636.8656616210938], [363.77398681640625, 1126.81689453125, 414.26031494140625, 1255.906005859375], [410.3504638671875, 265.8154296875, 472.620849609375, 396.99310302734375], [340.90704345703125, 260.6723327636719, 404.50653076171875, 397.0931091308594], [265.55389404296875, 255.7691192626953, 334.20501708984375, 402.55047607421875], [477.82781982421875, 285.53643798828125, 533.5737915039062, 399.93988037109375], [311.66107177734375, 1129.9979248046875, 359.06097412109375, 1261.0616455078125], [114.4017333984375, 478.44720458984375, 167.9227294921875, 632.7005004882812], [170.59661865234375, 750.3878173828125, 236.74688720703125, 946.761962890625], [416.9654541015625, 1120.63134765625, 455.64892578125, 1248.25927734375], [252.3658447265625, 974.9986572265625, 310.1572265625, 1105.2547607421875], [314.91033935546875, 985.51416015625, 372.83477783203125, 1091.97216796875], [580.1760864257812, 331.96722412109375, 626.5945434570312, 410.743896484375], [120.94692993164062, 973.6834106445312, 177.46969604492188, 1116.9759521484375], [217.83059692382812, 1134.9564208984375, 269.346435546875, 1258.7301025390625], [457.27593994140625, 1110.9752197265625, 489.77276611328125, 1233.9022216796875], [268.48651123046875, 1131.84130859375, 308.86138916015625, 1259.72705078125], [166.51290893554688, 1139.879638671875, 214.55819702148438, 1250.445068359375], [548.14501953125, 1085.05126953125, 591.8983154296875, 1190.6103515625]], "detection_scores": [0.5326253771781921, 0.4829007089138031, 0.4735769033432007, 0.56972736120224, 0.5581203103065491, 0.47067806124687195, 0.4176042973995209, 0.6494063138961792, 0.9763787984848022, 0.6203807592391968, 0.6229503154754639, 0.995220959186554, 0.7561615109443665, 0.96540766954422, 0.7088794112205505, 0.6708459854125977, 0.9078369140625, 0.4620403051376343, 0.6637236475944519, 0.539475679397583, 0.537329912185669, 0.5928680896759033, 0.9760238528251648, 0.7584733366966248, 0.505286693572998, 0.4664297103881836, 0.8538541197776794, 0.41185709834098816, 0.4183993935585022, 0.9568557739257812, 0.9400320053100586], "detection_classes": [97, 97, 98, 16, 80, 29, 147, 9, 4, 131, 5, 95, 7, 124, 29, 29, 71, 114, 21, 7, 5, 147, 66, 111, 98, 159, 111, 80, 52, 66, 0], "detection_class_names": ["299", "299", "298", "349", "308", "332", "320", "342", "306", "478", "305", "368", "303", "712", "332", "332", "301", "433", "341", "303", "305", "320", "468", "432", "298", "4", "432", "308", "777", "468", "189"], "product_count": {"299": 2, "298": 2, "349": 1, "308": 2, "332": 3, "320": 2, "342": 1, "306": 1, "478": 1, "305": 2, "368": 1, "303": 2, "712": 1, "301": 1, "433": 1, "341": 1, "468": 2, "432": 2, "4": 1, "777": 1, "189": 1}}'

更多参考

图像智能处理类模型
Python SDK使用说明

上一篇:阿里云视觉智能开放平台人脸人体API Net SDK Quick Start


下一篇:LVS-NAT配置