onnx 模型中的 PyTorch 标准化
我正在 pytorch 中进行图像分类,其中我使用了这个变换
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
并完成了训练。之后,我将 .pth 模型文件转换为 .onnx 文件
现在,在推理中,我应该如何在 numpy 数组中应用此转换,因为 onnx 处理 numpy 数组中的输入
I am doing image classification in pytorch, in that, I used this transforms
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
and completed the training. After, I converted the .pth model file to .onnx file
Now, in inference, how should I apply this transforms in numpy array, because the onnx handles input in numpy array
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你有几个选择。
由于自己编写标准化非常简单,
因此您可以完全不需要 pytorch 或 torchvision 库。
如果您仍在使用 pytorch 数据集,您可以使用以下转换
,该转换只会将归一化应用于张量,然后将其转换为 numpy 数组。
You have a couple options.
Since normalize is pretty trivial to write yourself you could just do
which doesn't require the pytorch or torchvision libraries at all.
If you are still using your pytorch dataset you could use the following transform
which will just apply the normalization to the tensor then convert it to a numpy array.
您可以将相同的
转换
应用于np.array,例如示例。You can apply the same
transforms
to np.array, for example.