apple / apple/coremltools

Create updatable model - Unsupported configuration": inner_product needs at least 2 inputs for gradients, got 1"

Open
#1,983 4 comments 0 reactions 1 assignee Claimed by @mrfarhadi View on GitHub
question triaged
Dominant language
Python
Stars
5.4k
Forks
850
Avg merge
4d 5h
Merged PRs (30d)
10

Description

## ❓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**

```python
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**

```python
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](https://stackoverflow.com/questions/77146267/create-undateable-coreml-model-from-keras)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.