apple / coremltools

Core ML tools contain supporting tools for Core ML model conversion, editing, and validation.
https://coremltools.readme.io
BSD 3-Clause "New" or "Revised" License
4.44k stars 641 forks source link

validator error: Layer 'input' produces an output named 'input' which is also an output produced by the layer '__input' #1275

Open oki5656 opened 3 years ago

oki5656 commented 3 years ago

❓Question

When I tried to watch the preview of .mlmodel file using Xcode, an error occurred and I could not watch it. The program was created from this repository's ESPNetv2.

error image

image

System Information

<watch .mlmodel below information> macOS Catalina 10.15.7 xcode==12.4

<built .mlmodel below information> python==3.7.10 torch==1.8.0 torchvision==0.9.0 numpy==1.19.5 coremltools==4.1

Part of the code that created .mlmodel

model = espnetv2_seg(args)
model.eval()
example = torch.rand(1, 3, 640, 480)
traced_script_module = torch.jit.trace(model, example)

mlmodel = ct.convert(
    traced_script_module,
    inputs=[ct.TensorType(name="input", shape=example.shape)],
)
mlmodel.save('./espnetv2_640_480.mlmodel')

# load the model
mlmodel = ct.models.MLModel("espnetv2_640_480.mlmodel")

labels_json = {"labels": ["obstacle", "background"]}

mlmodel.user_defined_metadata["com.apple.coreml.model.preview.type"] = "imageSegmenter"
mlmodel.user_defined_metadata['com.apple.coreml.model.preview.params'] = json.dumps(labels_json)

mlmodel.save("espnet_640_480_with_metadata.mlmodel")
TobyRoseman commented 3 years ago

Looking at your code sample, I'm not able to reproduce this issue.

Could you attach your torch model (i.e. model from your code)? Or tell us how to reproduce it (complete with the value of args, all import statement, and any other necessary code)?

oki5656 commented 3 years ago

Thank you for commenting ! I made the repo (including making .mlmodel file and network file, etc.), please use it. If you have any questions, please feel free to ask.

franva commented 2 years ago

any update? I have the same issue.