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.22k stars 609 forks source link

Util to expose intermediate tensors as outputs #2254

Open smpanaro opened 2 weeks ago

smpanaro commented 2 weeks ago

🌱 Describe your Feature Request

Sometimes when debugging a CoreML model it can be difficult to know where exactly inside of the model it is failing. I wrote a script for myself to expose intermediate tensors as model outputs without having to reconvert the model. It saved me a bunch of time, so was curious if it's the sort of thing that would be useful in the utils package.

How can this feature be used?

Any time your model outputs look wrong, you can trace through and compare with a source (e.g. PyTorch) model to see where they started to drift apart.

Describe alternatives you've considered

In the past I've manually de-composed my PyTorch model and re-converted each piece. It works but it's tedious.

Additional context

My script is here.

DawerG commented 1 week ago

Thanks @smpanaro for this utility. Looks very useful.

Can you please create a PR to merge your script somewhere here in the debugging utils?

smpanaro commented 1 day ago

Thanks for the pointer! Looking a little closer, I think the extract_submodels util can actually handle this. I put up two small fixes to make it work for my model: https://github.com/apple/coremltools/pull/2267 and https://github.com/apple/coremltools/pull/2270