最近更新时间:2021-06-07
选择左侧“在线服务”,点击“创建服务”,弹出创建在线服务配置页面。在弹窗中填写服务名称如:
inference-mnist
服务配置中,“添加”服务配置如下:
模型:model-mnist,v0.0.1版本
流量比例:100%
资源池:公共资源池
资源套餐:CPU_4核8GiB
副本数:1
点击“确认”后,等待服务部署完成,直到服务状态为“运行中”表示服务部署成功,可以响应请求。
预测图片是一张从测试集中随机选择的手写数字“1”。如图所示:
将此图片转化成28x28的像素矩阵图片。然后使用numpy转化成预测服务可识别的784维数组。转化numpy数组代码示例如下:
import cv2 as cv import numpy as np np.set_printoptions(threshold=np.inf) img = cv.imread('minisit-1.jpg', 0) # 读取图片 img1 = img / 255 # 归一化 fname = open('minist-1.1.txt', 'w') # 数组存储的文件 Xlenth = img1.shape[1] # 图片列数 Ylenth = img1.shape[0] # 图片行数 for i in range(Ylenth): for j in range(Xlenth): if i < Ylenth-1: if i == 0: if j == 0: fname.write('['+ str(img1[i][j].tolist()) + ',') else: fname.write(str(img1[i][j].tolist()) + ',') else: fname.write(str(img1[i][j].tolist()) + ',') else: if j < Xlenth-1: fname.write(str(img1[i][j].tolist()) + ',') else: fname.write(str(img1[i][j].tolist()) + ']') fname.close()
import cv2 as cvimport numpy as np np.set_printoptions(threshold=np.inf) img = cv.imread('minisit-1.jpg', 0) # 读取图片img1 = img / 255 # 归一化fname = open('minist-1.1.txt', 'w') # 数组存储的文件Xlenth = img1.shape[1] # 图片列数Ylenth = img1.shape[0] # 图片行数for i in range(Ylenth): for j in range(Xlenth): if i < Ylenth-1: if i == 0: if j == 0: fname.write('['+ str(img1[i][j].tolist()) + ',') else: fname.write(str(img1[i][j].tolist()) + ',') else: fname.write(str(img1[i][j].tolist()) + ',') else: if j < Xlenth-1: fname.write(str(img1[i][j].tolist()) + ',') else: fname.write(str(img1[i][j].tolist()) + ']') fname.close()
此数组用于组装Body用于向在线服务发送请求。
在服务列表中,得到在线服务访问的url。
使用postman发送请求,需要使用您的ak/sk完成签名,获取签名的代码请参考SignatureUtil.java,请求方式如下。
请求方式:POST
返回类型:json
Params如下:
参数 | 值 | 说明 |
---|---|---|
AccessKeyId | Access Key值 | ak值 |
Signature | 签名值 | ak/sk生成的签名,获取签名的代码请参考SignatureUtil.java |
Body如下:
{ "inputs": { "myInput": [[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.011764705882352941,0.0,0.00392156862745098,0.0,0.0,0.0,0.00784313725490196,0.0,0.0196078431372549,0.0,0.0,0.0,0.0,0.011764705882352941,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.011764705882352941,0.0,0.00784313725490196,0.00784313725490196,0.0,0.00784313725490196,0.0,0.0,0.00784313725490196,0.00392156862745098,0.011764705882352941,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.00784313725490196,0.00784313725490196,0.0,0.0,0.0,0.0,0.00784313725490196,0.0,0.011764705882352941,0.011764705882352941,0.011764705882352941,0.0,0.00784313725490196,0.00784313725490196,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.00392156862745098,0.0196078431372549,0.00392156862745098,0.00392156862745098,0.0,0.011764705882352941,0.0,0.00392156862745098,0.0,0.0,0.023529411764705882,0.0,0.0,0.011764705882352941,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.00784313725490196,0.0,0.0,0.01568627450980392,0.00392156862745098,0.0,0.00392156862745098,0.0,0.0,0.0,0.01568627450980392,0.0,0.00784313725490196,0.0,0.0,0.00784313725490196,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.011764705882352941,0.0,0.0,0.0,0.03137254901960784,0.3058823529411765,1.0,0.6823529411764706,0.054901960784313725,0.0,0.0,0.00784313725490196,0.00392156862745098,0.00392156862745098,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.01568627450980392,0.0,0.0,0.00392156862745098,0.00392156862745098,0.06666666666666667,0.8862745098039215,0.9803921568627451,0.984313725490196,0.09019607843137255,0.00784313725490196,0.0,0.00392156862745098,0.0,0.00392156862745098,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.00392156862745098,0.0,0.011764705882352941,0.0,0.6313725490196078,0.9882352941176471,1.0,0.984313725490196,0.09019607843137255,0.0,0.00392156862745098,0.00784313725490196,0.0,0.0,0.00784313725490196,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.023529411764705882,0.0,0.0,0.00392156862745098,0.6549019607843137,0.996078431372549,0.9921568627450981,0.9882352941176471,0.08627450980392157,0.0,0.00392156862745098,0.0,0.00392156862745098,0.0,0.00784313725490196,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.01568627450980392,0.0,0.043137254901960784,0.807843137254902,0.9803921568627451,0.9921568627450981,0.8431372549019608,0.058823529411764705,0.0,0.0,0.00784313725490196,0.0,0.00392156862745098,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.00784313725490196,0.0,0.0,0.00392156862745098,0.1450980392156863,0.996078431372549,0.9882352941176471,0.984313725490196,0.7215686274509804,0.023529411764705882,0.00784313725490196,0.0,0.011764705882352941,0.0196078431372549,0.0,0.00784313725490196,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.5058823529411764,0.9803921568627451,0.9882352941176471,1.0,0.8745098039215686,0.06274509803921569,0.0,0.0196078431372549,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.00784313725490196,0.0,0.10980392156862745,0.996078431372549,0.9764705882352941,0.9686274509803922,0.25882352941176473,0.0,0.0,0.01568627450980392,0.0,0.0,0.03529411764705882,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.00784313725490196,0.0,0.0,0.00392156862745098,0.08235294117647059,0.9921568627450981,0.996078431372549,0.8352941176470589,0.0,0.00392156862745098,0.0,0.0,0.011764705882352941,0.00784313725490196,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.011764705882352941,0.0,0.0,0.10196078431372549,0.9764705882352941,0.9803921568627451,0.9058823529411765,0.09803921568627451,0.0,0.00784313725490196,0.00392156862745098,0.0,0.011764705882352941,0.00784313725490196,0.00784313725490196,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.00392156862745098,0.07058823529411765,1.0,0.9921568627450981,0.8156862745098039,0.00392156862745098,0.00392156862745098,0.00392156862745098,0.0,0.00784313725490196,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.00392156862745098,0.0,0.0,0.00784313725490196,0.07450980392156863,0.9921568627450981,0.9921568627450981,0.8274509803921568,0.0,0.0,0.00392156862745098,0.0,0.011764705882352941,0.00392156862745098,0.00392156862745098,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.011764705882352941,0.08235294117647059,0.9882352941176471,0.9803921568627451,0.9803921568627451,0.23137254901960785,0.011764705882352941,0.0,0.00392156862745098,0.0,0.0,0.01568627450980392,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.00784313725490196,0.0,0.0,0.09019607843137255,0.9882352941176471,0.9764705882352941,1.0,0.25098039215686274,0.0,0.00784313725490196,0.0,0.011764705882352941,0.0,0.0,0.00392156862745098,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.09411764705882353,0.9882352941176471,1.0,0.984313725490196,0.596078431372549,0.01568627450980392,0.0,0.0,0.0,0.0,0.00784313725490196,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.00784313725490196,0.00784313725490196,0.08235294117647059,0.9803921568627451,0.9882352941176471,1.0,0.6470588235294118,0.0,0.0,0.00784313725490196,0.0,0.0,0.0,0.00392156862745098,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.00392156862745098,0.0,0.0,0.0,0.08627450980392157,1.0,0.9647058823529412,0.9921568627450981,0.6509803921568628,0.0196078431372549,0.00392156862745098,0.0,0.011764705882352941,0.01568627450980392,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.08235294117647059,0.9686274509803922,1.0,0.9921568627450981,0.6705882352941176,0.0,0.0,0.011764705882352941,0.0,0.0,0.011764705882352941,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.00784313725490196,0.0,0.0,0.011764705882352941,0.0196078431372549,0.7647058823529411,0.9882352941176471,0.9882352941176471,0.5568627450980392,0.0,0.00392156862745098,0.0,0.00392156862745098,0.0,0.00392156862745098,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.011764705882352941,0.0,0.0,0.00392156862745098,0.3137254901960784,0.9921568627450981,0.8470588235294118,0.027450980392156862,0.011764705882352941,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.01568627450980392,0.0,0.011764705882352941,0.0,0.0,0.00392156862745098,0.00784313725490196,0.0,0.011764705882352941,0.00392156862745098,0.0,0.0,0.00392156862745098,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.01568627450980392,0.0,0.0,0.00392156862745098,0.0,0.0,0.0,0.0,0.00392156862745098,0.0,0.0,0.0,0.00392156862745098,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.00392156862745098,0.0,0.0,0.00784313725490196,0.0,0.0,0.0,0.0,0.0,0.00392156862745098,0.00392156862745098,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]] } }
{ "inputs": { "myInput": [[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.011764705882352941,0.0,0.00392156862745098,0.0,0.0,0.0,0.00784313725490196,0.0,0.0196078431372549,0.0,0.0,0.0,0.0,0.011764705882352941,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.011764705882352941,0.0,0.00784313725490196,0.00784313725490196,0.0,0.00784313725490196,0.0,0.0,0.00784313725490196,0.00392156862745098,0.011764705882352941,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.00784313725490196,0.00784313725490196,0.0,0.0,0.0,0.0,0.00784313725490196,0.0,0.011764705882352941,0.011764705882352941,0.011764705882352941,0.0,0.00784313725490196,0.00784313725490196,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.00392156862745098,0.0196078431372549,0.00392156862745098,0.00392156862745098,0.0,0.011764705882352941,0.0,0.00392156862745098,0.0,0.0,0.023529411764705882,0.0,0.0,0.011764705882352941,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.00784313725490196,0.0,0.0,0.01568627450980392,0.00392156862745098,0.0,0.00392156862745098,0.0,0.0,0.0,0.01568627450980392,0.0,0.00784313725490196,0.0,0.0,0.00784313725490196,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.011764705882352941,0.0,0.0,0.0,0.03137254901960784,0.3058823529411765,1.0,0.6823529411764706,0.054901960784313725,0.0,0.0,0.00784313725490196,0.00392156862745098,0.00392156862745098,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.01568627450980392,0.0,0.0,0.00392156862745098,0.00392156862745098,0.06666666666666667,0.8862745098039215,0.9803921568627451,0.984313725490196,0.09019607843137255,0.00784313725490196,0.0,0.00392156862745098,0.0,0.00392156862745098,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.00392156862745098,0.0,0.011764705882352941,0.0,0.6313725490196078,0.9882352941176471,1.0,0.984313725490196,0.09019607843137255,0.0,0.00392156862745098,0.00784313725490196,0.0,0.0,0.00784313725490196,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.023529411764705882,0.0,0.0,0.00392156862745098,0.6549019607843137,0.996078431372549,0.9921568627450981,0.9882352941176471,0.08627450980392157,0.0,0.00392156862745098,0.0,0.00392156862745098,0.0,0.00784313725490196,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.01568627450980392,0.0,0.043137254901960784,0.807843137254902,0.9803921568627451,0.9921568627450981,0.8431372549019608,0.058823529411764705,0.0,0.0,0.00784313725490196,0.0,0.00392156862745098,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.00784313725490196,0.0,0.0,0.00392156862745098,0.1450980392156863,0.996078431372549,0.9882352941176471,0.984313725490196,0.7215686274509804,0.023529411764705882,0.00784313725490196,0.0,0.011764705882352941,0.0196078431372549,0.0,0.00784313725490196,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.5058823529411764,0.9803921568627451,0.9882352941176471,1.0,0.8745098039215686,0.06274509803921569,0.0,0.0196078431372549,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.00784313725490196,0.0,0.10980392156862745,0.996078431372549,0.9764705882352941,0.9686274509803922,0.25882352941176473,0.0,0.0,0.01568627450980392,0.0,0.0,0.03529411764705882,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.00784313725490196,0.0,0.0,0.00392156862745098,0.08235294117647059,0.9921568627450981,0.996078431372549,0.8352941176470589,0.0,0.00392156862745098,0.0,0.0,0.011764705882352941,0.00784313725490196,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.011764705882352941,0.0,0.0,0.10196078431372549,0.9764705882352941,0.9803921568627451,0.9058823529411765,0.09803921568627451,0.0,0.00784313725490196,0.00392156862745098,0.0,0.011764705882352941,0.00784313725490196,0.00784313725490196,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.00392156862745098,0.07058823529411765,1.0,0.9921568627450981,0.8156862745098039,0.00392156862745098,0.00392156862745098,0.00392156862745098,0.0,0.00784313725490196,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.00392156862745098,0.0,0.0,0.00784313725490196,0.07450980392156863,0.9921568627450981,0.9921568627450981,0.8274509803921568,0.0,0.0,0.00392156862745098,0.0,0.011764705882352941,0.00392156862745098,0.00392156862745098,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.011764705882352941,0.08235294117647059,0.9882352941176471,0.9803921568627451,0.9803921568627451,0.23137254901960785,0.011764705882352941,0.0,0.00392156862745098,0.0,0.0,0.01568627450980392,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.00784313725490196,0.0,0.0,0.09019607843137255,0.9882352941176471,0.9764705882352941,1.0,0.25098039215686274,0.0,0.00784313725490196,0.0,0.011764705882352941,0.0,0.0,0.00392156862745098,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.09411764705882353,0.9882352941176471,1.0,0.984313725490196,0.596078431372549,0.01568627450980392,0.0,0.0,0.0,0.0,0.00784313725490196,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.00784313725490196,0.00784313725490196,0.08235294117647059,0.9803921568627451,0.9882352941176471,1.0,0.6470588235294118,0.0,0.0,0.00784313725490196,0.0,0.0,0.0,0.00392156862745098,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.00392156862745098,0.0,0.0,0.0,0.08627450980392157,1.0,0.9647058823529412,0.9921568627450981,0.6509803921568628,0.0196078431372549,0.00392156862745098,0.0,0.011764705882352941,0.01568627450980392,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.08235294117647059,0.9686274509803922,1.0,0.9921568627450981,0.6705882352941176,0.0,0.0,0.011764705882352941,0.0,0.0,0.011764705882352941,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.00784313725490196,0.0,0.0,0.011764705882352941,0.0196078431372549,0.7647058823529411,0.9882352941176471,0.9882352941176471,0.5568627450980392,0.0,0.00392156862745098,0.0,0.00392156862745098,0.0,0.00392156862745098,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.011764705882352941,0.0,0.0,0.00392156862745098,0.3137254901960784,0.9921568627450981,0.8470588235294118,0.027450980392156862,0.011764705882352941,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.01568627450980392,0.0,0.011764705882352941,0.0,0.0,0.00392156862745098,0.00784313725490196,0.0,0.011764705882352941,0.00392156862745098,0.0,0.0,0.00392156862745098,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.01568627450980392,0.0,0.0,0.00392156862745098,0.0,0.0,0.0,0.0,0.00392156862745098,0.0,0.0,0.0,0.00392156862745098,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.00392156862745098,0.0,0.0,0.00784313725490196,0.0,0.0,0.0,0.0,0.0,0.00392156862745098,0.00392156862745098,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]] } }
Body中的myInput就是手写数字"1"的numpy数组。
图中看到预测结果是一个长度为10的置信度数组,其中第二个标签的置信度最高。手写数字MNIST数据集的标签为0-9,所以预测结果为1,预测结果正确。
在“在线服务”列表页,点击操作列的“停止”按钮,停止在线服务。
至此,我们完成了准备数据/文件->训练->模型管理->预测,整个AI开发流程的体验。更多详细操作请参考用户指南。