Open teaglin opened 1 year ago
I'm seeing different behavior using tensorflow-macos==2.10.0
. With that the TensorFlow model does not appear to be valid. I get the following error when trying to call predict(np.zeros((1,16,16,512)))
on the TensorFlow model.
q = m.predict(np.zeros((1,16,16,512)))
File "/Users/toby/miniconda3/envs/prod/lib/python3.8/site-packages/keras/utils/traceback_utils.py", line 65, in error_handler
return fn(*args, **kwargs)
File "/Users/toby/miniconda3/envs/prod/lib/python3.8/site-packages/keras/engine/training.py", line 2253, in predict
tmp_batch_outputs = self.predict_function(iterator)
File "/Users/toby/miniconda3/envs/prod/lib/python3.8/site-packages/keras/engine/training.py", line 2041, in predict_function
return step_function(self, iterator)
File "/Users/toby/miniconda3/envs/prod/lib/python3.8/site-packages/keras/engine/training.py", line 2027, in step_function
outputs = model.distribute_strategy.run(run_step, args=(data,))
File "/Users/toby/miniconda3/envs/prod/lib/python3.8/site-packages/keras/engine/training.py", line 2015, in run_step
outputs = model.predict_step(data)
File "/Users/toby/miniconda3/envs/prod/lib/python3.8/site-packages/keras/engine/training.py", line 1983, in predict_step
return self(x, training=False)
File "/Users/toby/miniconda3/envs/prod/lib/python3.8/site-packages/keras/utils/traceback_utils.py", line 65, in error_handler
return fn(*args, **kwargs)
File "/Users/toby/miniconda3/envs/prod/lib/python3.8/site-packages/keras/engine/training.py", line 557, in __call__
return super().__call__(*args, **kwargs)
File "/Users/toby/miniconda3/envs/prod/lib/python3.8/site-packages/keras/utils/traceback_utils.py", line 65, in error_handler
return fn(*args, **kwargs)
File "/Users/toby/miniconda3/envs/prod/lib/python3.8/site-packages/keras/engine/base_layer.py", line 1097, in __call__
outputs = call_fn(inputs, *args, **kwargs)
File "/Users/toby/miniconda3/envs/prod/lib/python3.8/site-packages/keras/utils/traceback_utils.py", line 96, in error_handler
return fn(*args, **kwargs)
File "/Users/toby/miniconda3/envs/prod/lib/python3.8/site-packages/keras/engine/functional.py", line 510, in call
return self._run_internal_graph(inputs, training=training, mask=mask)
File "/Users/toby/miniconda3/envs/prod/lib/python3.8/site-packages/keras/engine/functional.py", line 667, in _run_internal_graph
outputs = node.layer(*args, **kwargs)
File "/Users/toby/miniconda3/envs/prod/lib/python3.8/site-packages/keras/utils/traceback_utils.py", line 65, in error_handler
return fn(*args, **kwargs)
File "/Users/toby/miniconda3/envs/prod/lib/python3.8/site-packages/keras/engine/base_layer.py", line 1097, in __call__
outputs = call_fn(inputs, *args, **kwargs)
File "/Users/toby/miniconda3/envs/prod/lib/python3.8/site-packages/keras/utils/traceback_utils.py", line 96, in error_handler
return fn(*args, **kwargs)
File "<ipython-input-1-068b912528e5>", line 44, in call
pos_bias = tf.gather(self.bb, self.bb_pos)
Node: 'model/multi_head_positional_embedding/Gather'
indices[3,496] = 514 is not in [0, 512)
@TobyRoseman this should produce the correct error.
t = layers.Input(
shape=(8, 64, 256)
)
x = MultiHeadPositionalEmbedding()(t)
m = models.Model([t], [x])
q = m.predict(np.zeros((1,8,64,256)))
print(m.summary(), q)
coreml_model = ct.convert(m,
minimum_deployment_target=ct.target.iOS16,
inputs=[],
source='tensorflow')
@teaglin - please all import statements needed to run your code.
@TobyRoseman updated the original code sample. Let me know if you have any issues.
I can now reproduce this issue using the original (updated) code.
🐞Describing the bug
Custom layer fails to export.
Stack Trace
To Reproduce
class MultiHeadPositionalEmbedding(keras.layers.Layer): def init(self, query_height=-1, key_height=-1, kwargs): super(MultiHeadPositionalEmbedding, self).init(kwargs) self.query_height, self.key_height = query_height, key_height
if name == "main": import coremltools as ct import numpy as np t = layers.Input( shape=(8, 64, 256) ) x = MultiHeadPositionalEmbedding()(t)
Model: "model"
Layer (type) Output Shape Param #
input_1 (InputLayer) [(None, 8, 64, 256)] 0
multi_head_positional_embed (None, 8, 64, 256) 2048
ding (MultiHeadPositionalEm
bedding)
================================================================= Total params: 2,048 Trainable params: 2,048 Non-trainable params: 0
None [[[[0. 0. 0. ... 0. 0. 0.] [0. 0. 0. ... 0. 0. 0.] [0. 0. 0. ... 0. 0. 0.] ... [0. 0. 0. ... 0. 0. 0.] [0. 0. 0. ... 0. 0. 0.] [0. 0. 0. ... 0. 0. 0.]]
[[0. 0. 0. ... 0. 0. 0.] [0. 0. 0. ... 0. 0. 0.] [0. 0. 0. ... 0. 0. 0.] ... [0. 0. 0. ... 0. 0. 0.] [0. 0. 0. ... 0. 0. 0.] [0. 0. 0. ... 0. 0. 0.]]
[[0. 0. 0. ... 0. 0. 0.] [0. 0. 0. ... 0. 0. 0.] [0. 0. 0. ... 0. 0. 0.] ... [0. 0. 0. ... 0. 0. 0.] [0. 0. 0. ... 0. 0. 0.] [0. 0. 0. ... 0. 0. 0.]]
...
[[0. 0. 0. ... 0. 0. 0.] [0. 0. 0. ... 0. 0. 0.] [0. 0. 0. ... 0. 0. 0.] ... [0. 0. 0. ... 0. 0. 0.] [0. 0. 0. ... 0. 0. 0.] [0. 0. 0. ... 0. 0. 0.]]
[[0. 0. 0. ... 0. 0. 0.] [0. 0. 0. ... 0. 0. 0.] [0. 0. 0. ... 0. 0. 0.] ... [0. 0. 0. ... 0. 0. 0.] [0. 0. 0. ... 0. 0. 0.] [0. 0. 0. ... 0. 0. 0.]]
[[0. 0. 0. ... 0. 0. 0.] [0. 0. 0. ... 0. 0. 0.] [0. 0. 0. ... 0. 0. 0.] ... [0. 0. 0. ... 0. 0. 0.] [0. 0. 0. ... 0. 0. 0.] [0. 0. 0. ... 0. 0. 0.]]]]