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.38k stars 631 forks source link

A model that concats two inputs is not converted correctly. #1725

Open john-rocky opened 1 year ago

john-rocky commented 1 year ago

❓Question

I want to convert an inpainting model with two inputs.

https://github.com/researchmm/AOT-GAN-for-Inpainting

One input is the masked original image (x) and the other input is the mask image (mask). When converted to torchscript, the model concats the two inputs as intended, as shown in the attached image.

x = torch.rand(1, 3, 512, 512)
mask = torch.rand(1, 1, 512, 512)

ts = torch.jit.trace(model, (x,mask))
スクリーンショット 2023-01-10 18 10 32

However, when I convert to coreml model with the code below, the conversion itself completes correctly, but the converted mlmodel double joins one input (mask) and ignores the other input (x).

import coremltools as ct
mlmodel = ct.convert(ts, inputs=[ct.ImageType(shape=x.shape),ct.ImageType(shape=mask.shape)])
mlmodel.save("inpainting.mlmodel")
スクリーンショット 2023-01-10 18 11 49

concat receives x:1 and mask. The output of the ignored input (x) is x:0, and the mask input (mask) outputs x:1 and mask and is concat.

Is there a way to concat the two inputs as intended by the original model?

Thank you for your work. Best,

TobyRoseman commented 1 year ago

I do not have enough information to diagnose this problem. Can you give us steps to reproduce this issue?