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

export RTDETR as coreML #463

Open
keisan1231 opened this issue Sep 29, 2024 · 0 comments
Open

export RTDETR as coreML #463

keisan1231 opened this issue Sep 29, 2024 · 0 comments
Assignees

Comments

@keisan1231
Copy link

Question

How can I use RTDETR coreML??

Additional

I am trying to use RTDETR in an iOS application.
Following this comment, I attempted to export the model in CoreML format, but I encountered the following error:

ValueError: In op, of type linear, named out_w, the named input `weight` must have the same data type as the named input `x`. However, weight has dtype fp32 whereas x has dtype int32.

code

from ultralytics import RTDETR

# Load your model
model = RTDETR('rtdetr-l.pt')

# Ensure model and inputs are in the same data type (e.g., float32)
model = model.float()

# Now try exporting again
model.export(format="coreml")
All detail log ``` [W NNPACK.cpp:64] Could not initialize NNPACK! Reason: Unsupported hardware. rt-detr-l summary: 494 layers, 32148140 parameters, 0 gradients, 103.8 GFLOPs

PyTorch: starting from 'rtdetr-l.pt' with input shape (1, 3, 640, 640) BCHW and output shape(s) (1, 300, 84) (63.4 MB)
scikit-learn version 1.5.1 is not supported. Minimum required version: 0.17. Maximum required version: 1.1.2. Disabling scikit-learn conversion API.
Torch version 2.2.2 has not been tested with coremltools. You may run into unexpected errors. Torch 2.2.0 is the most recent version that has been tested.

CoreML: starting export with coremltools 7.2...
Converting PyTorch Frontend ==> MIL Ops: 0%| | 0/2329 [00:00<?, ? ops/s]Saving value type of int64 into a builtin type of int32, might lose precision!
Saving value type of int64 into a builtin type of int32, might lose precision!
Converting PyTorch Frontend ==> MIL Ops: 25%|█████████▊ | 574/2329 [00:00<00:00, 5716.50 ops/s]Saving value type of float64 into a builtin type of fp32, might lose precision!

ERROR - converting 'matmul' op (located at: '11'):

Converting PyTorch Frontend ==> MIL Ops: 25%|██████████ | 584/2329 [00:00<00:00, 5540.22 ops/s]
CoreML: export failure ❌ 20.0s: In op, of type linear, named out_w, the named input weight must have the same data type as the named input x. However, weight has dtype fp32 whereas x has dtype int32.
Traceback (most recent call last):
File "/Users/yamaguchikeiichi/Downloads/smart-judge/ball_detect_coreml_create/ml_xcode_create.py", line 10, in
model.export(format="coreml")
File "/Users/yamaguchikeiichi/Downloads/smart-judge/ball_detect_coreml_create/testEnv/lib/python3.10/site-packages/ultralytics/engine/model.py", line 591, in export
return Exporter(overrides=args, _callbacks=self.callbacks)(model=self.model)
File "/Users/yamaguchikeiichi/Downloads/smart-judge/ball_detect_coreml_create/testEnv/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
return func(*args, **kwargs)
File "/Users/yamaguchikeiichi/Downloads/smart-judge/ball_detect_coreml_create/testEnv/lib/python3.10/site-packages/ultralytics/engine/exporter.py", line 310, in call
f[4], _ = self.export_coreml()
File "/Users/yamaguchikeiichi/Downloads/smart-judge/ball_detect_coreml_create/testEnv/lib/python3.10/site-packages/ultralytics/engine/exporter.py", line 142, in outer_func
raise e
File "/Users/yamaguchikeiichi/Downloads/smart-judge/ball_detect_coreml_create/testEnv/lib/python3.10/site-packages/ultralytics/engine/exporter.py", line 137, in outer_func
f, model = inner_func(*args, **kwargs)
File "/Users/yamaguchikeiichi/Downloads/smart-judge/ball_detect_coreml_create/testEnv/lib/python3.10/site-packages/ultralytics/engine/exporter.py", line 633, in export_coreml
ct_model = ct.convert(
File "/Users/yamaguchikeiichi/Downloads/smart-judge/ball_detect_coreml_create/testEnv/lib/python3.10/site-packages/coremltools/converters/_converters_entry.py", line 581, in convert
mlmodel = mil_convert(
File "/Users/yamaguchikeiichi/Downloads/smart-judge/ball_detect_coreml_create/testEnv/lib/python3.10/site-packages/coremltools/converters/mil/converter.py", line 188, in mil_convert
return _mil_convert(model, convert_from, convert_to, ConverterRegistry, MLModel, compute_units, **kwargs)
File "/Users/yamaguchikeiichi/Downloads/smart-judge/ball_detect_coreml_create/testEnv/lib/python3.10/site-packages/coremltools/converters/mil/converter.py", line 212, in _mil_convert
proto, mil_program = mil_convert_to_proto(
File "/Users/yamaguchikeiichi/Downloads/smart-judge/ball_detect_coreml_create/testEnv/lib/python3.10/site-packages/coremltools/converters/mil/converter.py", line 288, in mil_convert_to_proto
prog = frontend_converter(model, **kwargs)
File "/Users/yamaguchikeiichi/Downloads/smart-judge/ball_detect_coreml_create/testEnv/lib/python3.10/site-packages/coremltools/converters/mil/converter.py", line 108, in call
return load(*args, **kwargs)
File "/Users/yamaguchikeiichi/Downloads/smart-judge/ball_detect_coreml_create/testEnv/lib/python3.10/site-packages/coremltools/converters/mil/frontend/torch/load.py", line 82, in load
return _perform_torch_convert(converter, debug)
File "/Users/yamaguchikeiichi/Downloads/smart-judge/ball_detect_coreml_create/testEnv/lib/python3.10/site-packages/coremltools/converters/mil/frontend/torch/load.py", line 116, in _perform_torch_convert
prog = converter.convert()
File "/Users/yamaguchikeiichi/Downloads/smart-judge/ball_detect_coreml_create/testEnv/lib/python3.10/site-packages/coremltools/converters/mil/frontend/torch/converter.py", line 581, in convert
convert_nodes(self.context, self.graph)
File "/Users/yamaguchikeiichi/Downloads/smart-judge/ball_detect_coreml_create/testEnv/lib/python3.10/site-packages/coremltools/converters/mil/frontend/torch/ops.py", line 86, in convert_nodes
raise e # re-raise exception
File "/Users/yamaguchikeiichi/Downloads/smart-judge/ball_detect_coreml_create/testEnv/lib/python3.10/site-packages/coremltools/converters/mil/frontend/torch/ops.py", line 81, in convert_nodes
convert_single_node(context, node)
File "/Users/yamaguchikeiichi/Downloads/smart-judge/ball_detect_coreml_create/testEnv/lib/python3.10/site-packages/coremltools/converters/mil/frontend/torch/ops.py", line 134, in convert_single_node
add_op(context, node)
File "/Users/yamaguchikeiichi/Downloads/smart-judge/ball_detect_coreml_create/testEnv/lib/python3.10/site-packages/coremltools/converters/mil/frontend/torch/ops.py", line 879, in matmul
res = mb.linear(x=linear_x, weight=transposed_weight, name=node.name)
File "/Users/yamaguchikeiichi/Downloads/smart-judge/ball_detect_coreml_create/testEnv/lib/python3.10/site-packages/coremltools/converters/mil/mil/ops/registry.py", line 182, in add_op
return cls._add_op(op_cls_to_add, **kwargs)
File "/Users/yamaguchikeiichi/Downloads/smart-judge/ball_detect_coreml_create/testEnv/lib/python3.10/site-packages/coremltools/converters/mil/mil/builder.py", line 182, in _add_op
new_op = op_cls(**kwargs)
File "/Users/yamaguchikeiichi/Downloads/smart-judge/ball_detect_coreml_create/testEnv/lib/python3.10/site-packages/coremltools/converters/mil/mil/operation.py", line 191, in init
self._validate_and_set_inputs(input_kv)
File "/Users/yamaguchikeiichi/Downloads/smart-judge/ball_detect_coreml_create/testEnv/lib/python3.10/site-packages/coremltools/converters/mil/mil/operation.py", line 504, in _validate_and_set_inputs
self.input_spec.validate_inputs(self.name, self.op_type, input_kvs)
File "/Users/yamaguchikeiichi/Downloads/smart-judge/ball_detect_coreml_create/testEnv/lib/python3.10/site-packages/coremltools/converters/mil/mil/input_type.py", line 137, in validate_inputs
raise ValueError(msg)
ValueError: In op, of type linear, named out_w, the named input weight must have the same data type as the named input x. However, weight has dtype fp32 whereas x has dtype int32.

</details>
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