Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# Convert TensorFlow model to Core ML format
# Input model definition
IMAGE_INPUT_NAME = ["input:0"]
IMAGE_INPUT_NAME_SHAPE = {'input:0':[1,224,224,3]}
IMAGE_INPUT_SCALE = 1.0/255.0
OUTPUT_NAME = ['MobilenetV2/Predictions/Reshape_1:0']
MODEL_LABELS = 'ImageNetLabels.txt'
# Output model
CORE_ML_MODEL = "mobilenet_v2_1.0_224.mlmodel"
# Convert model and save it as a file
coreml_model = tfcoreml.convert(
tf_model_path=TF_FROZEN_MODEL,
mlmodel_path=CORE_ML_MODEL,
output_feature_names=OUTPUT_NAME,
image_input_names=IMAGE_INPUT_NAME,
input_name_shape_dict = IMAGE_INPUT_NAME_SHAPE,
class_labels=MODEL_LABELS,
image_scale=IMAGE_INPUT_SCALE
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.