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

How convert to coreML ? #19

Open
LONGDDSF opened this issue Oct 29, 2024 · 0 comments
Open

How convert to coreML ? #19

LONGDDSF opened this issue Oct 29, 2024 · 0 comments

Comments

@LONGDDSF
Copy link

LONGDDSF commented Oct 29, 2024

I copied this project and wrote a python script to coreml, but encountered an error
https://github.com/mallman/CoreMLaMa.git
my code is below :

import coremltools as ct
import torch

from iopaint.model.mi_gan import MIGAN
from CoreMLMiGan import CoreMLMiGan

model_manager = MIGAN("cpu")
size = (512, 512) # pixel width x height

image_shape=(1, 3, size[1], size[0])

model_path = '/Users/DD/.cache/torch/hub/checkpoints/migan_traced.pt'
model = torch.jit.load(model_path, map_location="cpu").to(torch.device("mps"))
model.eval()
jit_model = model.eval()

print("Converting model")

coreml_model = ct.convert(
	jit_model,
	convert_to="mlprogram",
	compute_precision=ct.precision.FLOAT16,
	compute_units=ct.ComputeUnit.CPU_AND_GPU,
	inputs=[
		ct.ImageType(name="image",
					 shape=image_shape,
					 scale=1/255.0)
	],
	outputs=[ct.ImageType(name="output")],
	skip_model_load=True
)

coreml_model_file_name = "MiGan32.mlpackage"
print(f"Saving model to {coreml_model_file_name}")
coreml_model.save(coreml_model_file_name)
print("Done!")

I got err:

Converting model
Support for converting Torch Script Models is experimental. If possible you should use a traced model for conversion.
Converting PyTorch Frontend ==> MIL Ops:   0%|                                                                                        | 0/929 [00:00<?, ? ops/s]

ERROR - converting '_convolution' op (located at: 'encoder/b512/fromrgb'):

Converting PyTorch Frontend ==> MIL Ops:   2%|█▎                                                                           | 16/929 [00:00<00:00, 2970.21 ops/s]
Traceback (most recent call last):
  File "/Users/DD/Documents/JiaXi/ForDev/拍摄杆去除/CoreMLaMa/convert_MiGan.py", line 36, in <module>
    coreml_model = ct.convert(
  File "/Users/DD/.pyenv/versions/3.10.14/lib/python3.10/site-packages/coremltools/converters/_converters_entry.py", line 581, in convert
    mlmodel = mil_convert(
  File "/Users/DD/.pyenv/versions/3.10.14/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/DD/.pyenv/versions/3.10.14/lib/python3.10/site-packages/coremltools/converters/mil/converter.py", line 212, in _mil_convert
    proto, mil_program = mil_convert_to_proto(
  File "/Users/DD/.pyenv/versions/3.10.14/lib/python3.10/site-packages/coremltools/converters/mil/converter.py", line 288, in mil_convert_to_proto
    prog = frontend_converter(model, **kwargs)
  File "/Users/DD/.pyenv/versions/3.10.14/lib/python3.10/site-packages/coremltools/converters/mil/converter.py", line 108, in __call__
    return load(*args, **kwargs)
  File "/Users/DD/.pyenv/versions/3.10.14/lib/python3.10/site-packages/coremltools/converters/mil/frontend/torch/load.py", line 82, in load
    return _perform_torch_convert(converter, debug)
  File "/Users/DD/.pyenv/versions/3.10.14/lib/python3.10/site-packages/coremltools/converters/mil/frontend/torch/load.py", line 116, in _perform_torch_convert
    prog = converter.convert()
  File "/Users/DD/.pyenv/versions/3.10.14/lib/python3.10/site-packages/coremltools/converters/mil/frontend/torch/converter.py", line 581, in convert
    convert_nodes(self.context, self.graph)
  File "/Users/DD/.pyenv/versions/3.10.14/lib/python3.10/site-packages/coremltools/converters/mil/frontend/torch/ops.py", line 86, in convert_nodes
    raise e     # re-raise exception
  File "/Users/DD/.pyenv/versions/3.10.14/lib/python3.10/site-packages/coremltools/converters/mil/frontend/torch/ops.py", line 81, in convert_nodes
    convert_single_node(context, node)
  File "/Users/DD/.pyenv/versions/3.10.14/lib/python3.10/site-packages/coremltools/converters/mil/frontend/torch/ops.py", line 134, in convert_single_node
    add_op(context, node)
  File "/Users/DD/.pyenv/versions/3.10.14/lib/python3.10/site-packages/coremltools/converters/mil/frontend/torch/ops.py", line 1088, in _convolution
    conv = mb.conv(**kwargs)
  File "/Users/DD/.pyenv/versions/3.10.14/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/DD/.pyenv/versions/3.10.14/lib/python3.10/site-packages/coremltools/converters/mil/mil/builder.py", line 202, in _add_op
    new_op.type_value_inference()
  File "/Users/DD/.pyenv/versions/3.10.14/lib/python3.10/site-packages/coremltools/converters/mil/mil/operation.py", line 258, in type_value_inference
    output_types = self.type_inference()
  File "/Users/DD/.pyenv/versions/3.10.14/lib/python3.10/site-packages/coremltools/converters/mil/mil/ops/defs/iOS15/conv.py", line 168, in type_inference
    raise ValueError(msg.format(C_in, groups, self.weight.shape[1]))
ValueError: C_in / groups = 3/1 != weight[1] (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

1 participant