一、获取模型
模型可以是自己训练获取的模型,也可以是模型库中现有的模型。这里使用模型库现有模型测试。
二、相关参数获取
- 2.1 your_modelscope_sdk_token获取地址


三、使用SDK代码部署模型
from modelscope.hub.deploy import (Accelerator, EASCpuInstanceType, EASRegion,
EASDeployParameters, ServiceResourceConfig,
ServiceScalingConfig, ServiceDeployer
)
from modelscope.hub.api import HubApi
scaling = ServiceScalingConfig(min_replica=1,
max_replica=1)
res = ServiceResourceConfig(accelerator=Accelerator.CPU,
instance_type=EASCpuInstanceType.tiny,
scaling=scaling)
eas_params = EASDeployParameters(region=EASRegion.hangzhou,
access_key_id='LTAI********',
access_key_secret='7wAa***************')
model_id = 'damo/nlp_structbert_sentiment-classification_chinese-ecommerce-base'
instance_name = 'taro_modelscope_deploy_eas'
revision = 'v1.0.0'
# login first.
HubApi().login('0b6****-9a48-a357********')
deployer = ServiceDeployer()
ins = deployer.create(instance_name=instance_name,
model_id=model_id,
revision=revision,
resource=res,
provider=eas_params)
四、阿里云控制台查看模型部署情况
目前服务均部署公共资源池(ch-hanghzou和cn-beijing)区域


五、模型在线调用

import requests
import json
# header
headers = {"Authorization" : "MjUyNjQxZWJmYTMxZDdlYTYwZWY2ODFk********"}
url = 'http://17214402********.cn-hangzhou.pai-eas.aliyuncs.com/api/predict/taro_modelscope_deploy_eas'
# 输入数据
str = '上海自来水来自海上'
input_data = str.encode("UTF-8")
# post请求
response = requests.post(url=url, headers=headers, data=input_data)
if response.status_code != 200:
print('error: ', response.status_code, response.text)
# 输出结果
print(json.loads(response.text))

更多参考
部署EAS
阿里云机器学习PAI EAS部署TensorFlow Model