Alcibiades
Alcibiades

Reputation: 435

How to specify model author of CoreML model?

I'm not able to set Author of model using coremltools.

To Reproduce

temp_model = ct.models.MLModel(current_model_path)

print(f'Original author: {temp_model.author}')
temp_model.author = 'Luka'
print(f'Modified author: {temp_model.author}')
temp_model.save('temp_model.mlpackage')
temp_model = ct.models.MLModel('temp_model.mlpackage')
print(f'After saving: {temp_model.author}')

enter image description here

System environment (please complete the following information):

Additional context

The model that I'm trying to modify the author is a pytorch model that I trained and converted to CoreML. It's not only the author, but anything in this image is also something I'm unable change through code: enter image description here

Edit 1: it's a bug that Apple acknowledged, and the fix is deployed in the latest beta release (7.0b1): https://github.com/apple/coremltools/issues/1908

Upvotes: 0

Views: 169

Answers (1)

asyncCollection
asyncCollection

Reputation: 51

There are a couple of ways to update the author name / metadata of the coreml model:

Method #1: Open the model with Xcode and tap on the "Edit" button from the upper right corner: Author and other metadata fields will become editable, once you finish editing, hit the "Save / Edit" button. You are good to go :)

Screenshot on how to update the model author / metadata info within Xcode

Method #2: My suggestion is to save the updated model with a different name on disk. Here is an example:

  1. Load the model from disk
  2. Update the model author property
  3. Save the model with a different name
    # Load the saved coreml model from disk.
    model = ct.models.MLModel('ImageBrightness.mlpackage')
    # Set the author name.
    model.author = "Sample Author Name Goes Here"
    # Save the model with a different name
    model.save("ImageBrightnessUpdated.mlpackage")
    print(model.author)

Finally, let's load the newly updated model and print its author:

    # Load the new updated model and print the author name.
    model = ct.models.MLModel('ImageBrightnessUpdated.mlpackage')
    print(model.author)

This should gives us "Sample Author Name Goes Here".

NOTE: While updating metadata / author name using code (method #2 works), it dose not seem to display the updated name when previewed with Xcode. I think it might be an issue / bug as I am using Xcode 15 Beta version now.

But you can still easily update model metadata within Xcode itself.

You can experiment with these methods using this sample CoreMl model from this Github link.

Upvotes: 0

Related Questions