apple / apple/coremltools

Conversion for TF op 'UnravelIndex' not implemented

Open
#1,195 0 comments 0 reactions 0 assignees View on GitHub
bug missing layer type tf2.x / tf.keras
Dominant language
Python
Stars
5.4k
Forks
850
Avg merge
4d 5h
Merged PRs (30d)
10

Description

Hello.
I am converting `tf.keras` model to coreml.
I added an operation of `tf.unravel_index` in a `Lambda` layer, and it seems to be not implemented.

I am using the following tensorflow & coreml versions:
```
tf.__version__
'2.4.1'
ct.__version__
'4.1'
```

That's the code:
```python
model_before_post = Model(inputs=base_model.input, outputs=base_model.output)
post_processed_layer = tf.keras.layers.Lambda(get_indices)
post_processed_output = post_processed_layer(model_before_post.outputs)
model = Model(inputs=model_before_post.input, outputs=post_processed_output)

def get_indices(h_flat):
h_argmax = tf.argmax(h_flat)
ind = tf.unravel_index(h_argmax, heat.shape)
return ind
```

That's the trace:
```python
WARNING:root:TensorFlow version 2.4.1 detected. Last version known to be fully compatible is 2.3.1 .
Running TensorFlow Graph Passes: 100%|██████████| 5/5 [00:00<00:00, 11.57 passes/s]
Converting Frontend ==> MIL Ops: 72%|███████▏ | 790/1102 [00:01<00:00, 601.74 ops/s]
Traceback (most recent call last):
return converter.convert()
raise NotImplementedError(msg)
...
NotImplementedError: Conversion for TF op 'UnravelIndex' not implemented.
name: "model_1/lambda/UnravelIndex"
op: "UnravelIndex"
input: "model_1/lambda/ArgMax"
input: "model_1/lambda/UnravelIndex/dims"
attr {
key: "Tidx"
value {
type: DT_INT64
}
}
```

How can I overcome this?

Thanks

Contributor guide

Open the contributing guide

Research direction

Reproduce the conversion using the provided tf.keras Lambda and tf.unravel_index example, then trace the TensorFlow frontend handling for the reported “UnravelIndex” op. Done means the model converts without the NotImplementedError and preserves the expected unravelled indices.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, tensorflow
Domain
machine-learning, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.