简体   繁体   中英

How to make a MLModel updatable in Swift CoreML?

I'm trying to implement the new CoreML 3 feature of updatable Models into my App, but I can't figure it out.

Im creating a Neural Network with 2 layers in Keras and convert it to a core ML Model. Then I include the model into my iOS Project. However self.testmodel.model.modelDescription.isUpdatable is always false, and I can't make sense of the apple docs.

model = Sequential([
    Dense(10, activation="sigmoid", input_shape=(2,)),
    Dense(2, activation="relu"),
])
core_mlmodel = coremltools.converters.keras.convert(model)
core_mlmodel.save("FirstNN.mlmodel")

Integrated in Swift I can now use the Model, but can't update it

let testmodel = FirstNN()
try testmodel.prediction(input: input) // works
testmodel.model.modelDescription.isUpdatable  // is false

Why isn't my model updatable and how can I change that?

You can pass the respect_trainable=True argument to coremltools.converters.keras.convert() .

Alternatively, you can change the mlmodel file after the conversion to make the model updatable. Official documentation in the form of examples is here: https://github.com/apple/coremltools/tree/master/examples/updatable_models

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM