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

How to make combined mlmodel based on seperate mlmodels? adding if-else control flow #2392

Open xueyingxin opened 2 days ago

xueyingxin commented 2 days ago

❓Question

I want to use coremltools to help accomplish combining some separate coreml models to form a bigger one. For example, I have models: main.mlmodel, if_branch.mlmodel, else_branch.mlmodel, each have so many layers. I want to make another mlmodel based on those three. And the flow should be like this: Inputs include input to "main" and a condition input "cond". Input feed to "main", then output of it will go to either "if_branch" or "else_branch" based on the other input "cond".

I tried using "NeuralNetworkBuilder" to construct the bigger model. But when constructing the if layer, what kind of method(api) should I use to move all layers in "if_branch.mlmodel" to the "ifbranch" of the if layer instead of rewriting each layer into "ifbranch"?

image
TobyRoseman commented 2 days ago

It sounds like you should be using more than one model. It sounds like you want to create a model pipeline.

Model pipelines allow you to create an MLModel that consists of other MLModels. Models in the pipeline can take as input earlier Model's output.

Model Pipeline Resources