我正在尝试用 C++ 运行 ONNX 对象检测模型。所以,我已将自己的模型加载到 C++ 代码中,并且检查了输出尺寸,它是 [-1, 4]
所以,当我得到输出张量大小时,大小很奇怪。
我不知道为什么尺寸很奇怪。
std::vector<int64_t> outputDims = outputTensorInfo.GetShape();
std::cout << "Output Dimensions: " << outputDims << std::endl;
形状可以有一个设置为
-1
的位置,因为这意味着“所有其他数据都放在此处”。
这是一个小型的 pytorch 示例,可帮助您理解张量形状中的
-1
表示法。
tensor = torch.random((4,4,4)) # random values of shape (4, 4, 4)
tensor.reshape((-1, 4)) # has for values in last dimension, all others are placed into first dimension -> (16, 4)