如何在 CoreML 中访问模型的描述?

How to access the model's description in CoreML?

我有一个 CoreML 模型,我已经使用 coremltools 向模型添加了信息:

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

有没有办法从 Swift 访问此信息?

Apple 的文档上写着:

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

我试过这个:

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

但我收到以下错误:

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

看来我没有正确使用文档。 感谢您的帮助!

MyModel 不是 MLModel 对象,而是专门为您的模型生成的 class。但是,它内部确实有一个 MLModel 对象,在 model 属性.

您可以这样访问描述:

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