跳到主要内容

输入结构

推理载荷分为图像与张量两类。

图像​

传图有三种形态。

形态C#Python
文件路径ai.InferFile("a.jpg")ai.infer_file("a.jpg")
编码字节ai.InferImage(b, ImageDesc.Auto())ai.infer_image(b)
裸像素ai.InferImage(p, ImageDesc.Bgr888(1920, 1080))ai.infer_buffer(p, format=IMAGE_BGR888, width=1920, height=1080)

图像描述字段:

字段含义
format0 AUTO / 1 ENCODED / 2 RGB888 / 3 BGR888 / 4 GRAY8 / 5 RGBA8888 / 6 BGRA8888
width / height裸像素必填,编码图填 0
stride每行字节,0 为紧凑排列
alpha_premultiplied仅 RGBA / BGRA:0 丢 A,1 先去预乘再丢 A

裸缓冲的字节长度须盖住 stride * height。

张量​

张量会话走 AiSession.OpenTensors。

字段含义
name输入名,与模型一致,不可重复
typeFloat32 / UInt8 / Int8 / Int32 / Int64 / Bool / Float64
shape维度列表,标量为空
data连续字节,小端,长度须与 shape 匹配
var t = new AiTensor("images", AiTensorType.Float32, new long[] { 1, 3, 640, 640 }, buf);
var outs = session.InferTensors(new[] { t });
t = Tensor("images", TensorType.FLOAT32, [1, 3, 640, 640], buf)
outs = session.infer_tensors([t])