I got this error when convert coremlmodel in numpy >= 1.20
Trace
Traceback (most recent call last):
File "mini_code.py", line 14, in <module>
model = ct.convert(
File "/opt/conda/lib/python3.8/site-packages/coremltools/converters/_converters_entry.py", line 175, in convert
mlmodel = mil_convert(
File "/opt/conda/lib/python3.8/site-packages/coremltools/converters/mil/converter.py", line 128, in mil_convert
proto = mil_convert_to_proto(model, convert_from, convert_to,
File "/opt/conda/lib/python3.8/site-packages/coremltools/converters/mil/converter.py", line 171, in mil_convert_to_proto
prog = frontend_converter(model, **kwargs)
File "/opt/conda/lib/python3.8/site-packages/coremltools/converters/mil/converter.py", line 85, in __call__
return load(*args, **kwargs)
File "/opt/conda/lib/python3.8/site-packages/coremltools/converters/mil/frontend/torch/load.py", line 83, in load
raise e
File "/opt/conda/lib/python3.8/site-packages/coremltools/converters/mil/frontend/torch/load.py", line 73, in load
prog = converter.convert()
File "/opt/conda/lib/python3.8/site-packages/coremltools/converters/mil/frontend/torch/converter.py", line 223, in convert
const = mb.const(val=val, mode=mode, name=name)
File "/opt/conda/lib/python3.8/site-packages/coremltools/converters/mil/mil/ops/registry.py", line 62, in add_op
return cls._add_op(op_cls, **kwargs)
File "/opt/conda/lib/python3.8/site-packages/coremltools/converters/mil/mil/builder.py", line 189, in _add_op
new_op.type_value_inference()
File "/opt/conda/lib/python3.8/site-packages/coremltools/converters/mil/mil/operation.py", line 240, in type_value_inference
output_types = self.type_inference()
File "/opt/conda/lib/python3.8/site-packages/coremltools/converters/mil/mil/ops/defs/control_flow.py", line 140, in type_inference
builtin_type, _ = self._get_type_val(self.val.val)
File "/opt/conda/lib/python3.8/site-packages/coremltools/converters/mil/mil/ops/defs/control_flow.py", line 180, in _get_type_val
_, builtin_type = numpy_val_to_builtin_val(value)
File "/opt/conda/lib/python3.8/site-packages/coremltools/converters/mil/mil/types/type_mapping.py", line 262, in numpy_val_to_builtin_val
builtintype = numpy_type_to_builtin_type(npval.dtype)
File "/opt/conda/lib/python3.8/site-packages/coremltools/converters/mil/mil/types/type_mapping.py", line 232, in numpy_type_to_builtin_type
raise TypeError("Unsupported numpy type: %s" % (nptype))
TypeError: Unsupported numpy type: float32
To Reproduce
import torch
import coremltools as ct
# init maxpool module
torch_model = torch.nn.Conv2d(3, 3, 1, 1)
# Trace with random data
example_input = torch.rand(1, 3, 224, 224)
trace_model = torch.jit.trace(torch_model, example_input).eval()
# Convert to Core ML using the Unified Conversion API
model = ct.convert(
trace_model,
inputs=[ct.ImageType(name="input", shape=example_input.shape)],
)
System environment (please complete the following information):
coremltools version (e.g., 3.0b5): 4.1
OS (e.g., MacOS, Linux): Ubuntu20.04 LTS
How you install python (anaconda, virtualenv, system): miniconda
🐞Describe the bug
I got this error when convert coremlmodel in numpy >= 1.20
Trace
To Reproduce
System environment (please complete the following information):