Problem: CoreMLTools reName_feature does not update feature name in model, only in "spec" of model!
I have created a sequential Tensorflow model for an image classification problem. Initially, upon conversion (per Apple docs):
# https://coremltools.readme.io/docs/tensorflow-2
mlmodel2 = ct.convert(model,
inputs=[ct.ImageType()],
input_names=['image'],
image_input_names='image')
produced an MLModel which had an input named "conv2d_3_input" and was a MultiArray (Float33. 1x299x299x1) and an output named "Identity" which was also a MultiArray of Float32
Fortunately, the Quickstart Doc at: https://coremltools.readme.io/docs/introductory-quickstart#download-the-model elucidated the fix for input type requires adding a shape arg to ImageType:
# Define the input type as image,
# set pre-processing parameters to normalize the image
# to have its values in the interval [0,1]
image_input = ct.ImageType(shape=(1, 299, 299, 1,))
mlmodel3 = ct.convert(model,
inputs=[image_input],
input_names=['image'],
image_input_names='image')
So now the resulting MLModel has an input type of Image (Grayscale 299 x 299) (Great!), but it is still called "conv2d_3_input"
For style points, I want to rename the input feature to "image". The name arguments to the convert function (above) had no effect. I next tried directly changing the spec of the model:
spec = mlmodel.get_spec()
#spec.description.input
ct.utils.rename_feature(spec, 'conv2d_3_input', 'image')
#rename change spec but does not push new spec into model
spec.description.input
This correctly changes the input name in the spec:
[name: "image"
type {
imageType {
width: 299
height: 299
colorSpace: GRAYSCALE
}
}
]
However, this apparently does not push the change into the model! Here is the listing for mlmodel:
input {
name: "conv2d_3_input"
type {
imageType {
width: 299
height: 299
colorSpace: GRAYSCALE
}
}
}
output {
name: "Identity"
shortDescription: "Most likely ....."
type {
multiArrayType {
dataType: FLOAT32
}
}
}
metadata {
shortDescription: "Converts image ........."
How can one push the change in the feature name into the actual mlmodel?