如何将算法部署在 Triton Inference Server
基于Python后端的基础模型 (基础示例)
编写配置 config.pbtxt
以目标检测为例
定义输入输出: 参数名, 参数类型, 参数维度
name: "object_detect" # 模型名称, 与当前目录文件名一致
backend: "python" # 推理后端类型
max_batch_size: 1 # 最大批次
input [
{
name: "image"
data_type: TYPE_UINT8
dims: [-1,-1,3 ] # -1代表动态大小
},
{
name: "score"
data_type: TYPE_FP32
dims: [1]
optional: true # optional 为 true 时, 该参数为可选参数, 默认为 false
}
]
output [
{
name: "labels"
data_type: TYPE_STRING
dims: [-1,-1]
},
{
name: "classes"
data_type: TYPE_UINT16
dims: [-1]
},
{
name: "scores"
data_type: TYPE_FP32
dims: [ -1 ]
},
{
name: "bboxes"
data_type: TYPE_UINT32
dims: [-1, 4 ]
}
]
编写model.py
需要实现 TritonPythonModel
类的成员函数: initialize
, execute
, finalize
initialize
initialize
函数在加载模型时只会调用一次。
实现initialize
函数是可选的。该函数允许模型初始化与此模型关联的任何状态。
参数
args
: dict
键和值都是字符串。字典的键和值包括:
model_config
:包含模型配置的JSON字符串model_instance_kind
:包含模型实例类型的字符串model_instance_device_id
:包含模型实例设备ID的字符串model_repository
:模型存储库路径model_version
:模型版本model_name
:模型名称
execute
每个Python模型必须实现execute
函数。execute
函数接收一个pb_utils.InferenceReques