Is it possible to change the output type of the CoreML model ? My model takes images as inputs and images as outputs but when I convert my Keras model into a mlmodel, I get :
coreml_model = coremltools.converters.keras.convert('/Users/user/Desktop/model.h5',input_names='input_img',image_input_names='input_img',output_names='image')
coreml_model.save('/Users/user/Desktop/model.mlmodel')
The output is an MultiArray type but I want an Image type, how can I change it ?
Yes it's possible. However you would need to manually alter the converted Core ML model afterwards, since
coremltools
as of version 2.1 does not provide any conversion option for this.In a nutshell, here's what you need to do after converting the model to Core ML format. These should be done on the Python side by calling the lower-level APIs of
coremltools
.coremltools
ActivationLinear
layer at the end of the chain, just after your original model's output layer. You can also perform linear transformations using this layer, such as converting ranges from 0..1 to 0..255 and/or adding a bias.type
property.For Step 5 to work, you'll need to run the Python script on a Mac, since it uses the native Core ML libraries to run the model.
For details, you can read my post on getting Core ML to produce images as output.