Search code examples
swiftcoremlcoremltools

How to access the model's description in CoreML?


I have a CoreML model and I've added information to the model using coremltools:

model.author = 'Vincent Garcia'
model.license = 'BSD'
model.short_description = 'The model is doing something.'

Is there a way to access this information from Swift?

On Apple's documentation, it's written:

Inspect your model’s metadata and MLFeatureDescription instances through modelDescription.

I tried this:

let model = try! MyModel(configuration: MLModelConfiguration())
let desc = model.modelDescription

but I got the following error:

Value of type 'MyModel' has no member 'modelDescription'

It seems that I'm not using the documentation properly. Thanks for your help!


Solution

  • MyModel is not an MLModel object but a class that is specifically generated for your model. However, it does have an MLModel object inside, in the model property.

    You can access the description like so:

    let model = try! MyModel(configuration: MLModelConfiguration())
    let desc = model.model.modelDescription