Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coreml转换器在numpy 1.20上会报错 #95

Open
gemfield opened this issue May 13, 2021 · 1 comment
Open

coreml转换器在numpy 1.20上会报错 #95

gemfield opened this issue May 13, 2021 · 1 comment
Assignees

Comments

@gemfield
Copy link
Contributor

coreml转换器在numpy 1.20上会报错

@gemfield gemfield self-assigned this May 13, 2021
@MHGL
Copy link
Contributor

MHGL commented Jun 25, 2021

coreml转换问题

numpy版本问题

  • numpy == 1.21.0
  • coremltools == 0.4.1
  • error
File "/home/liyang/HomePod/deepvac/deepvac/cast/coreml.py", line 60, in process
    coreml_model = coremltools.convert(model=model, inputs=[input], 
  File "/home/liyang/.local/lib/python3.8/site-packages/coremltools/converters/_converters_entry.py", line 175, in convert
    mlmodel = mil_convert(
  File "/home/liyang/.local/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 "/home/liyang/.local/lib/python3.8/site-packages/coremltools/converters/mil/converter.py", line 171, in mil_convert_to_proto
    prog = frontend_converter(model, **kwargs)
  File "/home/liyang/.local/lib/python3.8/site-packages/coremltools/converters/mil/converter.py", line 85, in __call__
    return load(*args, **kwargs)
  File "/home/liyang/.local/lib/python3.8/site-packages/coremltools/converters/mil/frontend/torch/load.py", line 83, in load
    raise e
  File "/home/liyang/.local/lib/python3.8/site-packages/coremltools/converters/mil/frontend/torch/load.py", line 73, in load
    prog = converter.convert()
  File "/home/liyang/.local/lib/python3.8/site-packages/coremltools/converters/mil/frontend/torch/converter.py", line 227, in convert
    convert_nodes(self.context, self.graph)
  File "/home/liyang/.local/lib/python3.8/site-packages/coremltools/converters/mil/frontend/torch/ops.py", line 58, in convert_nodes
    _add_op(context, node)
  File "/home/liyang/.local/lib/python3.8/site-packages/coremltools/converters/mil/frontend/torch/ops.py", line 207, in constant
    const = _construct_constant(val, name)
  File "/home/liyang/.local/lib/python3.8/site-packages/coremltools/converters/mil/frontend/torch/ops.py", line 196, in _construct_constant
    return mb.const(mode=mode, val=val, name=name)
  File "/home/liyang/.local/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 "/home/liyang/.local/lib/python3.8/site-packages/coremltools/converters/mil/mil/builder.py", line 189, in _add_op
    new_op.type_value_inference()
  File "/home/liyang/.local/lib/python3.8/site-packages/coremltools/converters/mil/mil/operation.py", line 240, in type_value_inference
    output_types = self.type_inference()
  File "/home/liyang/.local/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 "/home/liyang/.local/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 "/home/liyang/.local/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 "/home/liyang/.local/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
  • workround
pip3 install numpy==1.19.5 pycocotools==2.0.0

pytorch版本问题

  • torch == 1.9.0 && numpy == 1.19.5
  • coremltools == 0.4.1
  • error:
File "/opt/public/airlock/deepvac/deepvac/cast/coreml.py", line 60, in process
    coreml_model = coremltools.convert(model=model, inputs=[input], 
  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 70, in load
    converter = TorchConverter(torchscript, inputs, outputs, cut_at_symbols)
  File "/opt/conda/lib/python3.8/site-packages/coremltools/converters/mil/frontend/torch/converter.py", line 146, in __init__
    self.graph = InternalTorchIRGraph(
  File "/opt/conda/lib/python3.8/site-packages/coremltools/converters/mil/frontend/torch/internal_graph.py", line 241, in __init__
    new_node = InternalTorchIRNode(raw_node, parent=self)
  File "/opt/conda/lib/python3.8/site-packages/coremltools/converters/mil/frontend/torch/internal_graph.py", line 140, in __init__
    self.attr = {
  File "/opt/conda/lib/python3.8/site-packages/coremltools/converters/mil/frontend/torch/internal_graph.py", line 141, in <dictcomp>
    name: getattr(node, node.kindOf(name))(name)
AttributeError: 'torch._C.Node' object has no attribute 'ival'
  • workround: pytorch降级

torch.jit.script导出模型转换coreml模型问题

  • error
    ···
    temporary: the only valid use of a module is looking up an attribute but found = prim::SetAttr[name="num_batches_tracked"]
    ···
  • workround
  1. 采用torch.jit.trace导出模型进行coreml转换
  2. 对conv和bn操作进行合并操作 fuse_conv_and_bn
  3. 利用coreml API对不支持操作进行注册
  4. 相关问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants