华为云用户手册

  • QoS策略设计 为了保证在网络拥塞情况下关键应用流量得到优先调度,需要配置QoS策略,保障关键流量的带宽,同时限制非关键流量的带宽。 办公软件、VoIP流量等为重要业务,属于关键流量,需要优先调度并保证带宽;保卫监控流量等属于非关键流量,对该部分流量进行带宽限制。 根据上行带宽大小与拥塞时的链路使用情况,设置限制流量的带宽占用大小。 按照实际使用情况与用户需求,对Spoke站点绑定QoS策略。 父主题: 用户业务设计
  • 安装硬件设备 根据部署规划时的网络设备安装点位设计、设备间互联等信息,完成网络设备的硬件安装、连线、上电等操作,具体指导文档请参见表1。 表1 硬件安装与布线任务一览表 任务 任务说明 参考链接 安装硬件设备 硬件设备安装需要遵循施工规范,常见的硬件施工规范有: 物理设备必须可靠接地。 物理设备谨慎搬运,要连带外纸箱或泡沫垫,不要裸机搬运。 所有光纤、网线、高速电缆和电源线分开布线,规范折弯有序捆扎。 所有光纤、网线和电源线需要考虑长度和传输距离是否能够满足环境的需求。 请单击以下设备名称,进入“硬件安装与维护指南”手册,查看对应设备款型的安装指导。 若无法找到,请在搜索框中输入设备款型查找安装指导。 AR 连接线缆 根据布线规划完成线缆连接,连接时注意按照规范在线缆两端打上标签。 设备配电、上电 请按照规划的配电参数和各个产品的产品文档来执行设备上电操作。 父主题: 配置前准备
  • 部署流程 表1 部署流程 部署任务 子任务 配置前准备 开通云管理网络服务 安装华为乾坤APP(可选) 安装硬件设备 AR开局部署 开启SD-WAN服务 创建站点并添加设备 配置网络设计参数 配置WAN链路模板 配置站点接入WAN侧网络的链路 配置NTP 配置站点连接RR 邮件开局 确认开局成功 站点互联配置 配置Underlay网络 创建Overlay网络 确认配置是否成功 配置站点上网策略 应用管理 查看预定义应用 创建自定义应用 创建应用组 使用应用及应用组 业务体验优化策略 配置流量分配 配置Overlay ACL策略 配置QoS策略 配置智能选路策略 查看全网数据 查看全网数据 父主题: 部署指导
  • 站点及ZTP开局数据规划 添加多个站点时,往往需要配置相同的网关类型、WAN链路条数和传输网络。通过定制链路模板可以将这些重复的配置信息模块化。 配置站点在WAN侧的物理链路,是进行开局的前提条件。站点配置或激活后,可新增或删除WAN侧链路。 表1 站点模板(RR设备) 参数 数据 模板名 Double_RR_Mix 单/双网关 双网关 WAN链路 名称 internet mpls internet1 mpls1 设备 Device1 Device2 端口 GE0/0/1 GE0/0/2 GE0/0/1 GE0/0/2 Overlay隧道 ON ON ON ON 传输网络(路由域) Internet MPLS Internet MPLS 角色 Active Active Active Active Inter-CPE链路 使用LAN侧二层物理口 OFF VLAN ID 4086~4094 设备1端口 GE0/0/3 GE0/0/4 设备2端口 GE0/0/3 GE0/0/4 表2 站点模板(CPE设备) 参数 数据 模板名 Single_CPE_Mix Double_CPE_Mix Single_CPE_Internet 单/双网关 单网关 双网关 单网关 WAN链路 名称 internet mpls internet mpls internet internet_5g 设备 Device1 Device1 Device1 Device2 Device1 Device1 端口 GE0/0/8 GE0/0/9 GE0/0/8 GE0/0/8 GE0/0/8 LTE1/0/0 Overlay隧道 ON ON ON ON ON ON 传输网络(路由域) Internet MPLS Internet MPLS Internet Internet_5G 角色 Active Active Active Active Active Standby Inter-CPE链路 使用LAN侧二层物理口 - - OFF - - VLAN ID - - 4086~4094 - - 设备1端口 - - GE0/0/1 GE0/0/2 - - 设备2端口 - - GE0/0/1 GE0/0/2 - - 为了便于用户管理设备和提升业务部署效率,同一个租户下,同一个网络的设备可以规划到一个站点中。 表3 站点及ZTP配置(1) 参数 数据 创建后,是否可以修改 备注 站点 Hub1 Hub2 是 站点名称可修改 是否开启RR功能 ON ON - - 单/双网关 双网关 双网关 - - 设备 Hub1_1 Hub1_2 Hub2_1 Hub2_2 - - 多子接口 OFF OFF OFF OFF 否 - RDB方式开局 OFF OFF OFF OFF 否 后续如果需要修改WAN链路,则需要打开该开关 WAN链路模板 Double_RR_Mix Double_RR_Mix - - 链路名称 internet mpls internet1 mpls1 internet mpls internet1 mpls1 否 配置完成后不可修改 VN实例 underlay_1 underlay_2 underlay_3 underlay_4 underlay_1 underlay_2 underlay_3 underlay_4 否 配置完成后不可修改 接口协议类型 IPoE IPoE IPoE IPoE IPoE IPoE IPoE IPoE - - 链路接入网络方式 静态 静态 静态 静态 静态 静态 静态 静态 - - IPv4地址/掩码 20.1.1.1/24 110.1.1.1/24 20.1.2.1/24 110.1.2.1/24 30.1.1.1/24 120.1.1.1/24 30.1.2.1/24 120.1.2.1/24 否 配置完成后不可修改 IPv4网关 20.1.1.2 110.1.1.2 20.1.2.2 110.1.2.2 30.1.1.2 120.1.1.2 30.1.2.2 120.1.2.2 否 配置完成后不可修改 IPv4公网IP 20.1.1.1 - 20.1.2.1 - 30.1.1.1 120.1.1.1 30.1.2.1 120.1.2.1 是 可以修改。公网IP为该链路上外部可访问的IP地址,分支可通过该地址注册到RR站点,当RR在NAT设备后或RR在云上部署时,需要填写映射到外部的外网IP。 上行容量(Mbps) 1000 1000 1000 1000 1000 1000 1000 1000 - 需要根据客户实际购买的链路带宽设置。 下行容量(Mbps) 1000 1000 1000 1000 1000 1000 1000 1000 - URL开局配置 ON ON ON ON ON ON ON ON 否 配置完成后开局链路不可修改,非开局链路支持删除和新增。 南向接入服务 Public Default South Access Public Default South Access Public Default South Access Public Default South Access Public Default South Access Public Default South Access Public Default South Access Public Default South Access 否 WAN链路默认均使用默认南向接入服务,也可选择其他自定义接入服务,开局后不可更改。 南向接入优先级 低 低 低 低 低 低 低 低 否 - 表4 站点及ZTP配置(2) 参数 数据 站点 Site1 Site2 Site3 是否开启RR功能 OFF OFF OFF 连接到RR Hub1、Hub2 Hub1、Hub2 Hub1、Hub2 单/双网关 单网关 双网关 单网关 多子接口 OFF OFF OFF RDB方式开局 OFF OFF OFF 站点模板 Single_CPE_Mix Double_CPE_Mix Single_CPE_Internet 设备 Site1_1 Site2_1 Site2_2 Site3_1 链路名称 internet mpls internet mpls internet internet_5g VN实例 underlay_1 underlay_2 underlay_1 underlay_2 underlay_1 underlay_2 接口协议类型 IPoE IPoE IPoE IPoE IPoE - 链路接入网络方式 静态 静态 静态 静态 动态 5G IPv4地址/掩码 40.1.1.1/24 130.1.1.1/24 50.1.1.1/24 140.1.1.1/24 - - IPv4网关 40.1.1.2 130.1.1.2 50.1.1.2 140.1.1.2 - - NAT穿越 ON OFF ON OFF ON ON 上行容量(Mbps) 20 20 20 20 20 20 下行容量(Mbps) 100 100 100 100 100 100 URL开局 ON ON ON ON ON OFF 南向接入服务 Public Default South Access Public Default South Access Public Default South Access Public Default South Access Public Default South Access Public Default South Access 南向接入优先级 低 低 低 低 低 低 父主题: 开局部署数据规划
  • LAN侧接入数据规划 站点网关与LAN侧网络对接时,需要配置相应对接参数。 本章节及后续所有章节数据规划,无特殊说明,均以办公业务VN(OA)为例。 表1 站点LAN接口信息 参数 数据 创建后,是否可以修改 备注 VN OA - - 站点 Hub1 Hub2 Site1 Site2 - - 设备 Hub1_1 Hub1_2 Hub2_1 Hub2_2 Site1_1 Site2_1 Site2_2 - - 网关接口 L3 L3 L3 L3 L2 L2 L2 - - VLANID - - - - 400 300 300 是 子接口ID不能与内联的ID重复。 接口 GE0/0/6 GE0/0/6 GE0/0/6 GE0/0/6 GE0/0/6 GE0/0/6 GE0/0/6 是 建议总行统一分配,以便对上线站点做预配置,后续进行批量开局,以及业务割接。 模式 - - - - Untag Untag Untag - - 信任模式 信任 信任 信任 信任 信任 信任 信任 - - IPv4地址 170.1.1.10/24 170.1.1.20/24 180.1.1.10/24 180.1.1.20/24 33.1.1.10/24 22.1.1.10/24 22.1.1.20/24 - - VRRP VRRP ID - - - - - 1 1 - - 虚拟IP - - - - - 22.1.1.1 22.1.1.1 - - 默认角色 - - - - - Master Backup - - 优先级 - - - - - 120 100 - VRRP备份组中,优先级最高的成为Master设备(主设备),其余为Backup设备(备设备)。 抢占延迟(s) - - - - - 0 0 - - 认证方式 - - - - - 不认证 不认证 - - DHCP DHCP类型 - - - - Server Server Server - - Exclude IPv4 - - - - - 22.1.1.20~22.1.1.20 22.1.1.10~22.1.1.10 - - 租约时间 - - - - - - - - - 父主题: 站点互联数据规划
  • 模型包规范 模型包必须存储在OBS中,且必须以“model”命名。“model”文件夹下面放置模型文件、模型推理代码。 模型推理代码文件必选,其文件名必须为“customize_service.py”,“model”文件夹下有且只能有1个推理代码文件,模型推理代码编写请参见模型推理代码编写说明。 使用模板导入的模型包结构如下所示: model/ │ ├── 模型文件 //必选,不同的框架,其模型文件格式不同,详细可参考模型包示例。 ├── 自定义Python包 //可选,用户自有的Python包,在模型推理代码中可以直接引用。 ├── customize_service.py //必选,模型推理代码,文件名称必须为“customize_service.py”,否则不视为推理代码。
  • 模型包规范 模型包必须存储在OBS中,且必须以“model”命名。“model”文件夹下面放置模型文件、模型推理代码。 模型推理代码文件必选,其文件名必须为“customize_service.py”,“model”文件夹下有且只能有1个推理代码文件,模型推理代码编写请参见模型推理代码编写说明。 使用模板导入的模型包结构如下所示: model/ │ ├── 模型文件 //必选,不同的框架,其模型文件格式不同,详细可参考模型包示例。 ├── 自定义Python包 //可选,用户自有的Python包,在模型推理代码中可以直接引用。 ├── customize_service.py //必选,模型推理代码,文件名称必须为“customize_service.py”,否则不视为推理代码。
  • 模型包规范 模型包必须存储在OBS中,且必须以“model”命名。“model”文件夹下面放置模型文件、模型推理代码。 模型推理代码文件必选,其文件名必须为“customize_service.py”,“model”文件夹下有且只能有1个推理代码文件,模型推理代码编写请参见模型推理代码编写说明。 使用模板导入的模型包结构如下所示: model/ │ ├── 模型文件 //必选,不同的框架,其模型文件格式不同,详细可参考模型包示例。 ├── 自定义Python包 //可选,用户自有的Python包,在模型推理代码中可以直接引用。 ├── customize_service.py //必选,模型推理代码,文件名称必须为“customize_service.py”,否则不视为推理代码。
  • 模型包规范 模型包必须存储在OBS中,且必须以“model”命名。“model”文件夹下面放置模型文件、模型推理代码。 模型推理代码文件必选,其文件名必须为“customize_service.py”,“model”文件夹下有且只能有1个推理代码文件,模型推理代码编写请参见模型推理代码编写说明。 使用模板导入的模型包结构如下所示: model/ │ ├── 模型文件 //必选,不同的框架,其模型文件格式不同,详细可参考模型包示例。 ├── 自定义Python包 //可选,用户自有的Python包,在模型推理代码中可以直接引用。 ├── customize_service.py //必选,模型推理代码,文件名称必须为“customize_service.py”,否则不视为推理代码。
  • 推理代码 在模型代码推理文件customize_service.py中,需要添加一个子类,该子类继承对应模型类型的父类,各模型类型的父类名称和导入语句如请参考表1。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 # coding:utf-8 import collections import json import traceback import model_service.log as log from model_service.spark_model_service import SparkServingBaseService from pyspark.ml.classification import LogisticRegression logger = log.getLogger(__name__) class UserService(SparkServingBaseService): # 数据预处理 def _preprocess(self, data): logger.info("Begin to handle data from user data...") # 读取数据 req_json = json.loads(data, object_pairs_hook=collections.OrderedDict) try: # 将数据转换成spark dataframe格式 predict_spdf = self.spark.createDataFrame(pd.DataFrame(req_json["data"]["req_data"])) except Exception as e: logger.error("check your request data does meet the requirements ?") logger.error(traceback.format_exc()) raise Exception("check your request data does meet the requirements ?") return predict_spdf # 模型推理 def _inference(self, data): try: # 加载模型文件 predict_model = LogisticRegression.load(self.model_path) # 对数据进行推理 prediction_result = predict_model.transform(data) except Exception as e: logger.error(traceback.format_exc()) raise Exception("Unable to load model and do dataframe transformation.") return prediction_result # 数据后处理 def _postprocess(self, pre_data): logger.info("Get new data to respond...") predict_str = pre_data.toPandas().to_json(orient='records') predict_result = json.loads(predict_str) return predict_result
  • 训练并保存模型 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 from pyspark.ml import Pipeline, PipelineModel from pyspark.ml.linalg import Vectors from pyspark.ml.classification import LogisticRegression # 创建训练数据,此处通过tuples创建 # Prepare training data from a list of (label, features) tuples. training = spark.createDataFrame([ (1.0, Vectors.dense([0.0, 1.1, 0.1])), (0.0, Vectors.dense([2.0, 1.0, -1.0])), (0.0, Vectors.dense([2.0, 1.3, 1.0])), (1.0, Vectors.dense([0.0, 1.2, -0.5]))], ["label", "features"]) # 创建训练实例,此处使用逻辑回归算法进行训练 # Create a LogisticRegression instance. This instance is an Estimator. lr = LogisticRegression(maxIter=10, regParam=0.01) # 训练逻辑回归模型 # Learn a LogisticRegression model. This uses the parameters stored in lr. model = lr.fit(training) # 保存模型到本地目录 # Save model to local path. model.save("/tmp/spark_model") 保存完模型后,需要上传到OBS目录才能发布。发布时需要带上config.json配置和推理代码customize_service.py。config.json编写请参考模型配置文件编写说明,推理代码请参考推理代码。
  • 前提条件 数据已完成准备:已在ModelArts中创建状态“正常”可用的AI应用。 已在IEF上创建边缘节点。如果您未创建边缘节点,具体操作请参见创建边缘节点。 确认用户的委托权限已包含Tenant Administrator权限。由于边缘服务依赖IEF纳管的边缘节点,而使用IEF服务需要授予IAM用户Tenant Administrator权限,所以若ModelArts委托不包含Tenant Administrator权限时,将导致边缘服务部署失败。 在ModelArts管理控制台,左侧导航栏选择“全局配置”,进入全局配置列表页。 在用户名对应的“操作”列,单击“查看权限”,在“权限详情”弹出框中确认委托权限已包含Tenant Administrator。 图1 查看委托权限详情 由于在线运行需消耗资源,确保帐户未欠费。
  • 模型包规范 模型包必须存储在OBS中,且必须以“model”命名。“model”文件夹下面放置模型文件、模型推理代码。 模型推理代码文件必选,其文件名必须为“customize_service.py”,“model”文件夹下有且只能有1个推理代码文件,模型推理代码编写请参见模型推理代码编写说明。 使用模板导入的模型包结构如下所示: model/ │ ├── 模型文件 //必选,不同的框架,其模型文件格式不同,详细可参考模型包示例。 ├── 自定义Python包 //可选,用户自有的Python包,在模型推理代码中可以直接引用。 ├── customize_service.py //必选,模型推理代码,文件名称必须为“customize_service.py”,否则不视为推理代码。
  • 推理代码 在模型代码推理文件customize_service.py中,需要添加一个子类,该子类继承对应模型类型的父类,各模型类型的父类名称和导入语句如请参考表1。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 from model_service.caffe_model_service import CaffeBaseService import numpy as np import os, json import caffe from PIL import Image class LenetService(CaffeBaseService): def __init__(self, model_name, model_path): # 调用父类推理方法 super(LenetService, self).__init__(model_name, model_path) # 设置预处理 transformer = caffe.io.Transformer({'data': self.net.blobs['data'].data.shape}) # 转换为NCHW格式 transformer.set_transpose('data', (2, 0, 1)) # 归一化处理 transformer.set_raw_scale('data', 255.0) # batch size设为1,只支持一张图片的推理 self.net.blobs['data'].reshape(1, 1, 28, 28) self.transformer = transformer # 设置类别标签 self.label = [0,1,2,3,4,5,6,7,8,9] def _preprocess(self, data): for k, v in data.items(): for file_name, file_content in v.items(): im = caffe.io.load_image(file_content, color=False) # 图片预处理 self.net.blobs['data'].data[...] = self.transformer.preprocess('data', im) return def _postprocess(self, data): data = data['prob'][0, :] predicted = np.argmax(data) predicted = {"predicted" : str(predicted) } return predicted
  • 训练并保存模型 “lenet_train_test.prototxt”文件 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 name: "LeNet" layer { name: "mnist" type: "Data" top: "data" top: "label" include { phase: TRAIN } transform_param { scale: 0.00390625 } data_param { source: "examples/mnist/mnist_train_lmdb" batch_size: 64 backend: LMDB } } layer { name: "mnist" type: "Data" top: "data" top: "label" include { phase: TEST } transform_param { scale: 0.00390625 } data_param { source: "examples/mnist/mnist_test_lmdb" batch_size: 100 backend: LMDB } } layer { name: "conv1" type: "Convolution" bottom: "data" top: "conv1" param { lr_mult: 1 } param { lr_mult: 2 } convolution_param { num_output: 20 kernel_size: 5 stride: 1 weight_filler { type: "xavier" } bias_filler { type: "constant" } } } layer { name: "pool1" type: "Pooling" bottom: "conv1" top: "pool1" pooling_param { pool: MAX kernel_size: 2 stride: 2 } } layer { name: "conv2" type: "Convolution" bottom: "pool1" top: "conv2" param { lr_mult: 1 } param { lr_mult: 2 } convolution_param { num_output: 50 kernel_size: 5 stride: 1 weight_filler { type: "xavier" } bias_filler { type: "constant" } } } layer { name: "pool2" type: "Pooling" bottom: "conv2" top: "pool2" pooling_param { pool: MAX kernel_size: 2 stride: 2 } } layer { name: "ip1" type: "InnerProduct" bottom: "pool2" top: "ip1" param { lr_mult: 1 } param { lr_mult: 2 } inner_product_param { num_output: 500 weight_filler { type: "xavier" } bias_filler { type: "constant" } } } layer { name: "relu1" type: "ReLU" bottom: "ip1" top: "ip1" } layer { name: "ip2" type: "InnerProduct" bottom: "ip1" top: "ip2" param { lr_mult: 1 } param { lr_mult: 2 } inner_product_param { num_output: 10 weight_filler { type: "xavier" } bias_filler { type: "constant" } } } layer { name: "accuracy" type: "Accuracy" bottom: "ip2" bottom: "label" top: "accuracy" include { phase: TEST } } layer { name: "loss" type: "SoftmaxWithLoss" bottom: "ip2" bottom: "label" top: "loss" } “lenet_solver.prototxt”文件 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 # The train/test net protocol buffer definition net: "examples/mnist/lenet_train_test.prototxt" # test_iter specifies how many forward passes the test should carry out. # In the case of MNIST, we have test batch size 100 and 100 test iterations, # covering the full 10,000 testing images. test_iter: 100 # Carry out testing every 500 training iterations. test_interval: 500 # The base learning rate, momentum and the weight decay of the network. base_lr: 0.01 momentum: 0.9 weight_decay: 0.0005 # The learning rate policy lr_policy: "inv" gamma: 0.0001 power: 0.75 # Display every 100 iterations display: 100 # The maximum number of iterations max_iter: 1000 # snapshot intermediate results snapshot: 5000 snapshot_prefix: "examples/mnist/lenet" # solver mode: CPU or GPU solver_mode: CPU 执行训练 ./build/tools/caffe train --solver=examples/mnist/lenet_solver.prototxt 训练后生成“caffemodel”文件,然后将“lenet_train_test.prototxt”文件改写成部署用的lenet_deploy.prototxt,修改输入层和输出层。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 name: "LeNet" layer { name: "data" type: "Input" top: "data" input_param { shape: { dim: 1 dim: 1 dim: 28 dim: 28 } } } layer { name: "conv1" type: "Convolution" bottom: "data" top: "conv1" param { lr_mult: 1 } param { lr_mult: 2 } convolution_param { num_output: 20 kernel_size: 5 stride: 1 weight_filler { type: "xavier" } bias_filler { type: "constant" } } } layer { name: "pool1" type: "Pooling" bottom: "conv1" top: "pool1" pooling_param { pool: MAX kernel_size: 2 stride: 2 } } layer { name: "conv2" type: "Convolution" bottom: "pool1" top: "conv2" param { lr_mult: 1 } param { lr_mult: 2 } convolution_param { num_output: 50 kernel_size: 5 stride: 1 weight_filler { type: "xavier" } bias_filler { type: "constant" } } } layer { name: "pool2" type: "Pooling" bottom: "conv2" top: "pool2" pooling_param { pool: MAX kernel_size: 2 stride: 2 } } layer { name: "ip1" type: "InnerProduct" bottom: "pool2" top: "ip1" param { lr_mult: 1 } param { lr_mult: 2 } inner_product_param { num_output: 500 weight_filler { type: "xavier" } bias_filler { type: "constant" } } } layer { name: "relu1" type: "ReLU" bottom: "ip1" top: "ip1" } layer { name: "ip2" type: "InnerProduct" bottom: "ip1" top: "ip2" param { lr_mult: 1 } param { lr_mult: 2 } inner_product_param { num_output: 10 weight_filler { type: "xavier" } bias_filler { type: "constant" } } } layer { name: "prob" type: "Softmax" bottom: "ip2" top: "prob" }
  • 模型包规范 模型包必须存储在OBS中,且必须以“model”命名。“model”文件夹下面放置模型文件、模型推理代码。 模型推理代码文件必选,其文件名必须为“customize_service.py”,“model”文件夹下有且只能有1个推理代码文件,模型推理代码编写请参见模型推理代码编写说明。 使用模板导入的模型包结构如下所示: model/ │ ├── 模型文件 //必选,不同的框架,其模型文件格式不同,详细可参考模型包示例。 ├── 自定义Python包 //可选,用户自有的Python包,在模型推理代码中可以直接引用。 ├── customize_service.py //必选,模型推理代码,文件名称必须为“customize_service.py”,否则不视为推理代码。
  • 训练并保存模型 1 2 3 4 5 6 7 8 9 10 11 12 13 14 import json import pandas as pd from sklearn.datasets import load_iris from sklearn.model_selection import train_test_split from sklearn.linear_model import LogisticRegression from sklearn.externals import joblib iris = pd.read_csv('/home/ma-user/work/iris.csv') X = iris.drop(['variety'],axis=1) y = iris[['variety']] # Create a LogisticRegression instance and train model logisticRegression = LogisticRegression(C=1000.0, random_state=0) logisticRegression.fit(X,y) # Save model to local path joblib.dump(logisticRegression, '/tmp/sklearn.m') 训练前请先下载iris.csv数据集,解压后上传至Notebook本地路径/home/ma-user/work/。iris.csv数据集下载地址:https://gist.github.com/netj/8836201。Notebook上传文件操作请参见上传本地文件至Notebook中。 保存完模型后,需要上传到OBS目录才能发布。发布时需要带上“config.json”配置以及“customize_service.py”,定义方式参考模型包规范介绍。
  • 推理代码 在模型代码推理文件customize_service.py中,需要添加一个子类,该子类继承对应模型类型的父类,各模型类型的父类名称和导入语句如请参考表1。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 # coding:utf-8 import collections import json from sklearn.externals import joblib from model_service.python_model_service import XgSklServingBaseService class UserService(XgSklServingBaseService): # request data preprocess def _preprocess(self, data): list_data = [] json_data = json.loads(data, object_pairs_hook=collections.OrderedDict) for element in json_data["data"]["req_data"]: array = [] for each in element: array.append(element[each]) list_data.append(array) return list_data # predict def _inference(self, data): sk_model = joblib.load(self.model_path) pre_result = sk_model.predict(data) pre_result = pre_result.tolist() return pre_result # predict result process def _postprocess(self,data): resp_data = [] for element in data: resp_data.append({"predictresult": element}) return resp_data
  • 最佳实践 免费体验:一键完成商超商品识别模型部署:ModelArts的AI Gallery中提供了大量免费的模型供用户一键部署,进行AI体验学习。 使用自定义镜像创建AI应用:提供了在ModelArts平台使用自定义镜像导入模型的样例,帮助您快速熟悉平台的使用方法。 纳管Atlas 500,将模型部署为边缘服务:Atlas人工智能计算平台,是基于华为昇腾系列AI处理器,打造面向“端、边、云”的全场景AI基础设施方案。配合Atlas系列边缘设备,华为云智能边缘服务(IEF)和AI开发平台(ModelArts)结合,将构建的AI模型快速部署至Atlas设备中,满足在安防、交通、社区、园区、 商场、超市等复杂环境区域的应用需求。 推理服务访问公网:提供了推理服务访问公网的方法。 推理服务端到端运维:ModelArts推理服务的端到端运维覆盖了算法开发、服务运维和业务运行的整个AI流程。 使用自定义引擎创建AI应用:用户可以通过选择自己存储在SWR服务中的镜像作为AI应用的引擎,指定预先存储于OBS服务中的文件目录路径作为模型包,来创建AI应用,轻松地应对ModelArts平台预置引擎无法满足个性化诉求的场景。 推理服务支持虚拟私有云(VPC)直连的高速访问通道:使用VPC直连的高速访问通道,用户的业务请求不需要经过推理平台,而是直接经VPC对等连接发送到实例处理,访问速度更快。 WebSocket在线服务全流程开发:用户在部署在线服务时如果选择了“升级为WebSocket”,服务部署完成后,API接口公网地址将是一个WebSocket协议地址。本案例介绍WebSocket在线服务全流程开发过程。 使用大模型创建AI应用部署在线服务:目前大模型的参数量已经达到千亿甚至万亿,随之大模型的体积也越来越大。千亿参数大模型的体积超过200G,在版本管理、生产部署上对平台系统产生了新的要求。例如:导入AI应用管理时,需要支持动态调整租户存储配额;模型加载、启动慢,部署时需要灵活的超时配置;当负载异常重启,模型需要重新加载,服务恢复时间长的问题亟待解决。为了应对如上诉求,ModelArts推理平台针对性给出解决方案,用于支持大模型场景下的AI应用管理和服务部署。 TFServing框架迁移到推理自定义引擎:从TFServing迁移到使用ModelArts推理的AI应用管理和服务管理时,需要对原生TFServing镜像的构建方式做一定的改造,以使用ModelArts推理平台的模型版本管理能力和动态加载模型的部署能力。本案例将一步一步指导用户完成原生TFServing镜像到ModelArts推理自定义引擎的改造。
  • 训练并保存模型 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 import pandas as pd import xgboost as xgb from sklearn.model_selection import train_test_split # Prepare training data and setting parameters iris = pd.read_csv('/home/ma-user/work/iris.csv') X = iris.drop(['variety'],axis=1) y = iris[['variety']] X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=1234565) params = { 'booster': 'gbtree', 'objective': 'multi:softmax', 'num_class': 3, 'gamma': 0.1, 'max_depth': 6, 'lambda': 2, 'subsample': 0.7, 'colsample_bytree': 0.7, 'min_child_weight': 3, 'silent': 1, 'eta': 0.1, 'seed': 1000, 'nthread': 4, } plst = params.items() dtrain = xgb.DMatrix(X_train, y_train) num_rounds = 500 model = xgb.train(plst, dtrain, num_rounds) model.save_model('/tmp/xgboost.m') 训练前请先下载iris.csv数据集,解压后上传至Notebook本地路径/home/ma-user/work/。iris.csv数据集下载地址:https://gist.github.com/netj/8836201。Notebook上传文件操作请参见上传本地文件至Notebook中。 保存完模型后,需要上传到OBS目录才能发布。发布时需要带上config.json配置和推理代码customize_service.py。config.json编写请参考模型配置文件编写说明,推理代码请参考推理代码。
  • 推理代码 在模型代码推理文件customize_service.py中,需要添加一个子类,该子类继承对应模型类型的父类,各模型类型的父类名称和导入语句如请参考表1。 # coding:utf-8 import collections import json import xgboost as xgb from model_service.python_model_service import XgSklServingBaseService class UserService(XgSklServingBaseService): # request data preprocess def _preprocess(self, data): list_data = [] json_data = json.loads(data, object_pairs_hook=collections.OrderedDict) for element in json_data["data"]["req_data"]: array = [] for each in element: array.append(element[each]) list_data.append(array) return list_data # predict def _inference(self, data): xg_model = xgb.Booster(model_file=self.model_path) pre_data = xgb.DMatrix(data) pre_result = xg_model.predict(pre_data) pre_result = pre_result.tolist() return pre_result # predict result process def _postprocess(self,data): resp_data = [] for element in data: resp_data.append({"predictresult": element}) return resp_data
  • 使用自定义依赖包的模型配置文件示例 如下示例中,定义了1.16.4版本的numpy的依赖环境。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 { "model_algorithm": "image_classification", "model_type": "TensorFlow", "runtime": "python3.6", "apis": [ { "url": "/", "method": "post", "request": { "Content-type": "multipart/form-data", "data": { "type": "object", "properties": { "images": { "type": "file" } } } }, "response": { "Content-type": "applicaton/json", "data": { "type": "object", "properties": { "mnist_result": { "type": "array", "item": [ { "type": "string" } ] } } } } } ], "metrics": { "f1": 0.124555, "recall": 0.171875, "precision": 0.00234938928519385, "accuracy": 0.00746268656716417 }, "dependencies": [ { "installer": "pip", "packages": [ { "restraint": "EXACT", "package_version": "1.16.4", "package_name": "numpy" } ] } ] }
  • 机器学习类型的模型配置文件示例 以下代码以XGBoost为例。 模型输入: { "req_data": [ { "sepal_length": 5, "sepal_width": 3.3, "petal_length": 1.4, "petal_width": 0.2 }, { "sepal_length": 5, "sepal_width": 2, "petal_length": 3.5, "petal_width": 1 }, { "sepal_length": 6, "sepal_width": 2.2, "petal_length": 5, "petal_width": 1.5 } ] } 模型输出: { "resp_data": [ { "predict_result": "Iris-setosa" }, { "predict_result": "Iris-versicolor" } ] } 配置文件: { "model_type": "XGBoost", "model_algorithm": "xgboost_iris_test", "runtime": "python2.7", "metrics": { "f1": 0.345294, "accuracy": 0.462963, "precision": 0.338977, "recall": 0.351852 }, "apis": [ { "url": "/", "method": "post", "request": { "Content-type": "application/json", "data": { "type": "object", "properties": { "req_data": { "items": [ { "type": "object", "properties": {} } ], "type": "array" } } } }, "response": { "Content-type": "applicaton/json", "data": { "type": "object", "properties": { "resp_data": { "type": "array", "items": [ { "type": "object", "properties": { "predict_result": {} } } ] } } } } } ] }
  • 图像分类模型配置文件示例 如下代码以TensorFlow引擎为例,您可以根据实际使用的引擎类型修改model_type参数后使用。 模型输入 key:images value:图片文件 模型输出 1 2 3 4 5 6 7 { "predicted_label": "flower", "scores": [ ["rose", 0.99], ["begonia", 0.01] ] } 配置文件 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 { "model_type": "TensorFlow", "model_algorithm": "image_classification", "metrics": { "f1": 0.345294, "accuracy": 0.462963, "precision": 0.338977, "recall": 0.351852 }, "apis": [{ "url": "/", "method": "post", "request": { "Content-type": "multipart/form-data", "data": { "type": "object", "properties": { "images": { "type": "file" } } } }, "response": { "Content-type": "application/json", "data": { "type": "object", "properties": { "predicted_label": { "type": "string" }, "scores": { "type": "array", "items": [{ "type": "array", "minItems": 2, "maxItems": 2, "items": [ { "type": "string" }, { "type": "number" } ] }] } } } } }], "dependencies": [{ "installer": "pip", "packages": [{ "restraint": "ATLEAST", "package_version": "1.15.0", "package_name": "numpy" }, { "restraint": "", "package_version": "", "package_name": "Pillow" } ] }] } 如下代码以MindSpore引擎为例,您可以根据实际使用的引擎类型修改model_type参数后使用。 模型输入 key:images value:图片文件 模型输出 1 "[[-2.404526 -3.0476532 -1.9888215 0.45013925 -1.7018927 0.40332815\n -7.1861157 11.290332 -1.5861531 5.7887416 ]]" 配置文件 { "model_algorithm": "image_classification", "model_type": "MindSpore", "metrics": { "f1": 0.124555, "recall": 0.171875, "precision": 0.0023493892851938493, "accuracy": 0.00746268656716417 }, "apis": [{ "url": "/", "method": "post", "request": { "Content-type": "multipart/form-data", "data": { "type": "object", "properties": { "images": { "type": "file" } } } }, "response": { "Content-type": "applicaton/json", "data": { "type": "object", "properties": { "mnist_result": { "type": "array", "item": [{ "type": "string" }] } } } } } ], "dependencies": [] }
  • 目标检测模型配置文件示例 如下代码以TensorFlow引擎为例,您可以根据实际使用的引擎类型修改model_type参数后使用。 模型输入 key:images value:图片文件 模型输出 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 { "detection_classes": [ "face", "arm" ], "detection_boxes": [ [ 33.6, 42.6, 104.5, 203.4 ], [ 103.1, 92.8, 765.6, 945.7 ] ], "detection_scores": [0.99, 0.73] } 配置文件 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 { "model_type": "TensorFlow", "model_algorithm": "object_detection", "metrics": { "f1": 0.345294, "accuracy": 0.462963, "precision": 0.338977, "recall": 0.351852 }, "apis": [{ "url": "/", "method": "post", "request": { "Content-type": "multipart/form-data", "data": { "type": "object", "properties": { "images": { "type": "file" } } } }, "response": { "Content-type": "application/json", "data": { "type": "object", "properties": { "detection_classes": { "type": "array", "items": [{ "type": "string" }] }, "detection_boxes": { "type": "array", "items": [{ "type": "array", "minItems": 4, "maxItems": 4, "items": [{ "type": "number" }] }] }, "detection_scores": { "type": "array", "items": [{ "type": "number" }] } } } } }], "dependencies": [{ "installer": "pip", "packages": [{ "restraint": "EXACT", "package_version": "1.15.0", "package_name": "numpy" }, { "restraint": "EXACT", "package_version": "5.2.0", "package_name": "Pillow" } ] }] }
  • 预测分析模型配置文件示例 如下代码以TensorFlow引擎为例,您可以根据实际使用的引擎类型修改model_type参数后使用。 模型输入 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 { "data": { "req_data": [ { "buying_price": "high", "maint_price": "high", "doors": "2", "persons": "2", "lug_boot": "small", "safety": "low", "acceptability": "acc" }, { "buying_price": "high", "maint_price": "high", "doors": "2", "persons": "2", "lug_boot": "small", "safety": "low", "acceptability": "acc" } ] } } 模型输出 1 2 3 4 5 6 7 8 9 10 11 12 { "data": { "resp_data": [ { "predict_result": "unacc" }, { "predict_result": "unacc" } ] } } 配置文件 代码中request结构和response结构中的data参数是json schema数据结构。data/properties里面的内容对应“模型输入”和“模型输出”。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 { "model_type": "TensorFlow", "model_algorithm": "predict_analysis", "metrics": { "f1": 0.345294, "accuracy": 0.462963, "precision": 0.338977, "recall": 0.351852 }, "apis": [ { "url": "/", "method": "post", "request": { "Content-type": "application/json", "data": { "type": "object", "properties": { "data": { "type": "object", "properties": { "req_data": { "items": [ { "type": "object", "properties": {} } ], "type": "array" } } } } } }, "response": { "Content-type": "application/json", "data": { "type": "object", "properties": { "data": { "type": "object", "properties": { "resp_data": { "type": "array", "items": [ { "type": "object", "properties": {} } ] } } } } } } } ], "dependencies": [ { "installer": "pip", "packages": [ { "restraint": "EXACT", "package_version": "1.15.0", "package_name": "numpy" }, { "restraint": "EXACT", "package_version": "5.2.0", "package_name": "Pillow" } ] } ] }
  • apis参数代码示例 [{ "url": "/", "method": "post", "request": { "Content-type": "multipart/form-data", "data": { "type": "object", "properties": { "images": { "type": "file" } } } }, "response": { "Content-type": "applicaton/json", "data": { "type": "object", "properties": { "mnist_result": { "type": "array", "item": [ { "type": "string" } ] } } } } }]
  • 自定义镜像类型的模型配置文件示例 模型输入和输出与目标检测模型配置文件示例类似。 模型预测输入为图片类型时,request请求示例如下: 该实例表示模型预测接收一个参数名为images、参数类型为file的预测请求,在推理界面会显示文件上传按钮,以文件形式进行预测。 1 2 3 4 5 6 7 8 9 10 11 { "Content-type": "multipart/form-data", "data": { "type": "object", "properties": { "images": { "type": "file" } } } } 模型预测输入为json数据类型时,request请求示例如下: 该实例表示模型预测接收json请求体,只有一个参数名为input、参数类型为string的预测请求,在推理界面会显示文本输入框,用于填写预测请求。 1 2 3 4 5 6 7 8 9 10 11 { "Content-type": "application/json", "data": { "type": "object", "properties": { "input": { "type": "string" } } } } 完整请求示例如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 { "model_algorithm": "image_classification", "model_type": "Image", "metrics": { "f1": 0.345294, "accuracy": 0.462963, "precision": 0.338977, "recall": 0.351852 }, "apis": [{ "url": "/", "method": "post", "request": { "Content-type": "multipart/form-data", "data": { "type": "object", "properties": { "images": { "type": "file" } } } }, "response": { "Content-type": "application/json", "data": { "type": "object", "required": [ "predicted_label", "scores" ], "properties": { "predicted_label": { "type": "string" }, "scores": { "type": "array", "items": [{ "type": "array", "minItems": 2, "maxItems": 2, "items": [{ "type": "string" }, { "type": "number" } ] }] } } } } }] }
  • 模型包规范 模型包必须存储在OBS中,且必须以“model”命名。“model”文件夹下面放置模型文件、模型推理代码。 模型推理代码文件必选,其文件名必须为“customize_service.py”,“model”文件夹下有且只能有1个推理代码文件,模型推理代码编写请参见模型推理代码编写说明。 使用模板导入的模型包结构如下所示: model/ │ ├── 模型文件 //必选,不同的框架,其模型文件格式不同,详细可参考模型包示例。 ├── 自定义Python包 //可选,用户自有的Python包,在模型推理代码中可以直接引用。 ├── customize_service.py //必选,模型推理代码,文件名称必须为“customize_service.py”,否则不视为推理代码。
  • 简介 搭载TensorFlow1.8引擎,运行环境为“python2.7”,适合导入以“SavedModel”格式保存的TensorFlow图像分类模型。该模板使用平台预置的图像处理模式,模式详情参见预置图像处理模式,推理时向模型输入一张“key”为“images”的待处理图片,所以需确保您的模型能处理“key”为“images”的输入。使用该模板导入模型时请选择到包含模型文件的“model”目录。
共100000条