如何为具有未知组件的形状创建TensorFloat



我已经按照这个例子将输入和输出绑定到ONNX模型。

// I can bind this shape fine since it has all known components:
std::vector<int64_t> shape({ 1, 1000, 1, 1 });
binding.Bind(L"softmaxout_1", TensorFloat::Create(shape));

然而,我自己的模型有一个未知组件的输入:

// This is the type shows in Netron: float32[unk__518,224,224,3], I tried:
std::vector<int64_t> shape({ "unk__518", 224, 224, 3 }); // Note: this doesn't compile since the first component is a string!
binding.Bind(L"Image:0", TensorFloat::Create(shape));

如何为这样的形状创建TensorFloat并绑定它?

当创建一个将与用自由维度(即:"unk_518"(定义的模型输入特征结合使用的张量时,您需要指定张量的实际具体维度。

在您的情况下,看起来您正在使用SqeezeNet。SqueezeNet的第一个参数对应于输入的批次维度,因此指的是您希望绑定和运行推理的图像数量。

将";unk_518";使用您希望在其上运行推理的批量大小:

int64_t batch_size = 1;
std::vector<int64_t> shape({ batch_size, 224, 224, 3 }); // Note: this doesn't compile since the first component is a string!
binding.Bind(L"Image:0", TensorFloat::Create(shape));

您可以看到,对于自由维度,Windows ML验证将允许任何维度,因为这是";免费的";尺寸:https://github.com/microsoft/onnxruntime/blob/f352d54743df1769de54d33264fcb7a2a469974d/winml/lib/Api/impl/FeatureCompatibility.h#L253

最新更新