onnxmltools icon indicating copy to clipboard operation
onnxmltools copied to clipboard

Cant use model converted to float16

Open Gaploid opened this issue 6 years ago • 6 comments

Hi, I`ve converted the model using that code:

from winmltools.utils import convert_float_to_float16
from winmltools.utils import load_model, save_model
import struct
onnx_model = load_model('10.onnx')
new_onnx_model = convert_float_to_float16(onnx_model)
save_model(new_onnx_model, '10_fp16.onnx')

from that documentation.

Ive tryed to pass images in float16 format like this:

ximg = (ximg).astype(numpy.float16) 
input_name = sess.get_inputs()[0].name
res = sess.run(None, {input_name: ximg})

but I keep getting this error: "Numpy_type 23 can't be converted to MLDataType."

Can anybody know how to pass data to "float16" onnx models?

Gaploid avatar Feb 24 '19 20:02 Gaploid

Hello @Gaploid, thank you for reporting your experience! This seems to pertain to the float_to_float16 operator in WinML and WinMLtools, as opposed to the converters in ONNXMLTools.

@ryanlai2, @youngkim93, thoughts?

vinitra-zz avatar Feb 27 '19 20:02 vinitra-zz

Thanks. WinMLTools actually reroutes that function call to onnxmltool's implementation of float_to_float16. So same issue must persist on onnxmltools as well.

yskim1501 avatar Feb 27 '19 21:02 yskim1501

Any ideas on how to work around that?

Gaploid avatar Feb 28 '19 15:02 Gaploid

@Gaploid, the issue is caused the lack of float16 support in onnxruntime python API. https://github.com/Microsoft/onnxruntime/blob/master/onnxruntime/python/onnxruntime_pybind_mlvalue.cc

wenbingl avatar Mar 08 '19 01:03 wenbingl

@wenbingl any plans to add support of that?

Gaploid avatar Mar 08 '19 11:03 Gaploid

Hi, Do you have any updates on that float16 support for python onnx runtime?

Gaploid avatar Aug 22 '20 17:08 Gaploid