coremltools
coremltools copied to clipboard
Create updatable model - Unsupported configuration": inner_product needs at least 2 inputs for gradients, got 1"
❓Question
I have a simple Keras model. After training I would like to export it as a coreml model using coremltools with the dense layer set to updatable so that it can be refined on device. However, when I try to export the model I get this runtime error
RuntimeWarning: You will not be able to run predict() on this Core ML model. Underlying exception message was: Error compiling model: "compiler error: Encountered an error while compiling a neural network model: Espresso exception: "Unsupported configuration": inner_product needs at least 2 inputs for gradients, got 1"
If I change the activation function of the output layer to sigmoid
the error goes away, but I'd like to keep it linear. I'd like to understand the error and get a sense of how to resolve it without changing the activation function
Network
model = tf.keras.Sequential([
tf.keras.layers.Dense(2, input_shape=(2,), name="xy"),
tf.keras.layers.Dense(256, name="dense_1"),
tf.keras.layers.Dense(2)
])
model.compile(loss='mean_squared_error', optimizer='adam')
...
model.fit(input_tensor, label_tensor, epochs=epochs)
Conversion code
model_spec = builder.spec
builder.make_updatable(['sequential/dense_1/BiasAdd'])
feature = ('Identity', datatypes.Array(1, 2))
builder.set_mean_squared_error_loss(name='lossLayer', input_feature=feature)
builder.make_updatable(['sequential/dense_1/BiasAdd'])
model_spec.description.input[
0].shortDescription = 'The XY coordinate indicating where the system thinks a point is located'
model_spec.description.output[0].shortDescription = 'The XY coordinate of the corrected output'
builder.set_adam_optimizer(AdamParams(lr=0.01, batch=32))
CoreML model inspection
[Id: 2], Name: Identity (Type: innerProduct)
Updatable: False
Input blobs: ['sequential/dense_1/BiasAdd']
Output blobs: ['Identity']
[Id: 1], Name: sequential/dense_1/BiasAdd (Type: innerProduct)
Updatable: True
Input blobs: ['sequential/xy/BiasAdd']
Output blobs: ['sequential/dense_1/BiasAdd']
[Id: 0], Name: sequential/xy/BiasAdd (Type: innerProduct)
Updatable: False
Input blobs: ['xy_input']
Output blobs: ['sequential/xy/BiasAdd']
X-post Stack Overflow
Hey @FreakTheMighty, I cannot reproduce your issue. Could you please share:
- A full (but minimal) tunable script?
- Your tensorflow and coremltools version?
Also, please try our Create ML as a workaround while we look into this issue, thanks!
@YifanShenSZ here's a repo that duplicates the issue for me. It includes a requirements.txt
https://github.com/Sitelink-Spatial/CoreMLConvertIssue
With regards to Create ML, I look at that, but I couldn't see how to model my exact model. The model is supposed to learn to predict a mapping of a 2D point into a new 2D point. Any thoughts on how I would do that in Create ML?
@YifanShenSZ any update on this? Were ya'll able to reproduce this?