Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError from adding tf.Tensor and None when exporting model with dynamic shapes #36

Open
NathanielB123 opened this issue Apr 29, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@NathanielB123
Copy link

NathanielB123 commented Apr 29, 2024

When exporting a PyTorch model with dynamic shapes I hit

Traceback (most recent call last):
  File "/home/nathaniel/dev/hood/./TFExport.py", line 106, in <module>
    tf_model = nobuco.pytorch_to_keras(
  File "/home/nathaniel/miniconda3/envs/hood/lib/python3.10/site-packages/nobuco/convert.py", line 340, in pytorch_to_keras
    outputs_tf = keras_op(*args_tf, **kwargs_tf)
  File "/home/nathaniel/miniconda3/envs/hood/lib/python3.10/site-packages/nobuco/layers/container.py", line 69, in __call__
    outputs = op(*args, **kwargs)
  File "/home/nathaniel/miniconda3/envs/hood/lib/python3.10/site-packages/nobuco/layers/container.py", line 69, in __call__
    outputs = op(*args, **kwargs)
  File "/home/nathaniel/miniconda3/envs/hood/lib/python3.10/site-packages/nobuco/layers/channel_order.py", line 27, in __call__
    outputs = self.func(*args, **kwargs)
  File "/home/nathaniel/miniconda3/envs/hood/lib/python3.10/site-packages/nobuco/layers/channel_order.py", line 59, in __call__
    outputs = self.func(*args, **kwargs)
  File "/home/nathaniel/miniconda3/envs/hood/lib/python3.10/site-packages/nobuco/node_converters/slice.py", line 203, in func
    return slice_assign(sliced_tensor, slice_args, assigned_tensor)
  File "/home/nathaniel/miniconda3/envs/hood/lib/python3.10/site-packages/nobuco/node_converters/slice.py", line 101, in slice_assign
    idx = tf.where(idx < 0, idx + shape[real_index], idx)
  File "/home/nathaniel/miniconda3/envs/hood/lib/python3.10/site-packages/tensorflow/python/util/traceback_utils.py", line 153, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File "/home/nathaniel/miniconda3/envs/hood/lib/python3.10/site-packages/keras/src/layers/core/tf_op_layer.py", line 119, in handle
    return TFOpLambda(op)(*args, **kwargs)
  File "/home/nathaniel/miniconda3/envs/hood/lib/python3.10/site-packages/keras/src/utils/traceback_utils.py", line 70, in error_handler
    raise e.with_traceback(filtered_tb) from None
ValueError: Exception encountered when calling layer "tf.__operators__.add_18" (type TFOpLambda).

None values not supported.

Call arguments received by layer "tf.__operators__.add_18" (type TFOpLambda):
  • x=tf.Tensor(shape=(None,), dtype=int64)
  • y=None
  • name=None

The offending addition occurs in nobuco/node_converters/slice.py

...
idx = tf.convert_to_tensor(slice_spec)
idx = tf.where(idx < 0, idx + shape[real_index], idx) # Addition in second argument to `tf.where` raises the exception
corresponding_range = tf.cast(idx, dtype=tf.int32)
...

where shape[real_index] can be None if the shape of sliced_tensor is dynamic.

As far as I can tell, this line is only relevant if there are negative indices. In my model, the indices are always positive, so I just commented out this line and the export went smoothly, but a proper fix to take dynamic shapes into account here would probably be ideal.

@AlexanderLutsenko AlexanderLutsenko added the bug Something isn't working label May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants