简体   繁体   中英

Can I convert a “.py” or “.ipynb” model/file created on Google Colab's Tensorflow to a coreML model/ file?

I created a CNN model on Google Colab's Tensorflow and downloaded the file as a ".py" file. How can I convert this file into a ".coreml" file?

Any advice is much appreciated!

Thank you!

Documentation on how to convert into Core ML's .mlmodel s: https://developer.apple.com/documentation/coreml/converting_trained_models_to_core_ml

For TensorFlow models, you need to convert it to frozen.pb model as an input for the convert function. Here are some examples: https://github.com/tf-coreml/tf-coreml/tree/master/examples

If you have downloaded a .py file you haven't downloaded the model, but the whole Python script.

When you have your model compiled, you can use the python package coremltools to convert the TensorFlow/Keras model into a .mlmodel file.

import coremltools

core_mlmodel = coremltools.converters.keras.convert(your_keras_model, respect_trainable=True)
core_mlmodel.save("YourModel.mlmodel")

Then you will find your model on the left in Files .

@ Sebastian J. Vogt. This is my conversion code. Is it correct? Thank you!

import coremltools

category_output_labels = ['dress', 'shirt', 'trousers']
color_output_labels = ['black', 'blue', 'green', 'pink', 'red', 
'white']

coreml_model = coremltools.converters.keras.convert('./fashion_multi_output_v02.h5',

input_names='image', image_input_names='image', class_labels=['category_output_labels', 'color_output_labels'])

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