Python pytorch模型的Coreml模型浮点输入

Python pytorch模型的Coreml模型浮点输入,python,ios,pytorch,coreml,onnx-coreml,Python,Ios,Pytorch,Coreml,Onnx Coreml,我有一个pytorch模型,它采用3xwidthxheight图像作为输入,像素值在0-1 例如,Pytork中的输入 img = io.imread(img_path) input_img = torch.from_numpy( np.transpose(img, (2,0,1)) ).contiguous().float()/255.0 我将此模型转换为coreml,并导出了一个mlmodel,它以正确的尺寸获取输入 Image (Color width x height) 但是,我的

我有一个pytorch模型,它采用
3xwidthxheight
图像作为输入,像素值在
0-1

例如,Pytork中的输入

img = io.imread(img_path)
input_img =  torch.from_numpy( np.transpose(img, (2,0,1)) ).contiguous().float()/255.0
我将此模型转换为coreml,并导出了一个mlmodel,它以正确的尺寸获取输入

Image (Color width x height)
但是,我的预测是错误的,因为模型期望浮点值介于
0-1
之间,而cvpixelbuffer是介于
0-255

我试着像这样规范化模型中的值

z = x.mul(1.0/255.0) # div op is not supported for export yet
preprocessing_args= {'image_scale' : (1.0/255.0)}
然而,当该操作在coreml级别的模型内部完成时,
int*float
被转换为
int
,并且所有值基本上都是
0

导出时不支持Cast op,例如
x=x.float()


我如何确保我的输入正确地用于预测?本质上,我想取
像素rgb和浮点除法255.0,并将其传递给模型进行推断

我用coreml onnx转换器的预处理参数解决了这个问题

z = x.mul(1.0/255.0) # div op is not supported for export yet
preprocessing_args= {'image_scale' : (1.0/255.0)}

希望这对其他人有所帮助

您能为您的问题提供更多代码吗?为什么“演员表演”不受支持?这似乎很奇怪。