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

Iterating over a symbolic tf.Tensor is not allowed: AutoGraph did convert this function #67323

Closed
saturn-drm opened this issue May 10, 2024 · 3 comments
Assignees
Labels
TF 2.9 Issues found in the TF 2.9 release (or RCs) type:bug Bug

Comments

@saturn-drm
Copy link

Issue type

Bug

Have you reproduced the bug with TensorFlow Nightly?

No

Source

source

TensorFlow version

tf 2.9

Custom code

Yes

OS platform and distribution

Linux Ubuntu 22.04

Mobile device

No response

Python version

No response

Bazel version

No response

GCC/compiler version

No response

CUDA/cuDNN version

No response

GPU model and memory

No response

Current behavior?

I have a function as below. I have N = tf.shape(y_true)[0] where y_ture is <tf.Tensor 'y_true:0' shape=(None, 8, 6) dtype=float32>. I later iterate over N as for i in tf.range(N), but get an error.

def transform_targets_for_output(y_true, grid_size, anchor_idxs):
    # y_true: (N, boxes, (x1, y1, x2, y2, class, best_anchor))
    print('y-true',y_true)
    N = tf.shape(y_true)[0]
    print('%%%',N)

    # y_true_out: (N, grid, grid, anchors, [x1, y1, x2, y2, obj, class])
    y_true_out = tf.zeros(
        (N, grid_size, grid_size, tf.shape(anchor_idxs)[0], 6))

    anchor_idxs = tf.cast(anchor_idxs, tf.int32)

    indexes = tf.TensorArray(tf.int32, 1, dynamic_size=True)
    updates = tf.TensorArray(tf.float32, 1, dynamic_size=True)
    idx = 0
    for i in tf.range(N):
        for j in tf.range(tf.shape(y_true)[1]):
            if tf.equal(y_true[i][j][2], 0):
                continue
            anchor_eq = tf.equal(
                anchor_idxs, tf.cast(y_true[i][j][5], tf.int32))

            if tf.reduce_any(anchor_eq):
                box = y_true[i][j][0:4]
                box_xy = (y_true[i][j][0:2] + y_true[i][j][2:4]) / 2

                anchor_idx = tf.cast(tf.where(anchor_eq), tf.int32)
                grid_xy = tf.cast(box_xy // (1/grid_size), tf.int32)

                # grid[y][x][anchor] = (tx, ty, bw, bh, obj, class)
                indexes = indexes.write(
                    idx, [i, grid_xy[1], grid_xy[0], anchor_idx[0][0]])
                updates = updates.write(
                    idx, [box[0], box[1], box[2], box[3], 1, y_true[i][j][4]])
                idx += 1

    # tf.print(indexes.stack())
    # tf.print(updates.stack())

    return tf.tensor_scatter_nd_update(
        y_true_out, indexes.stack(), updates.stack())

But I get error like this:

raise e.with_traceback(filtered_tb) from None
  File "/home/shakey/yolov3-tf2/yolov3_tf2/dataset.py", line 42, in transform_targets_for_output
    for i in tf.range(N):
tensorflow.python.framework.errors_impl.OperatorNotAllowedInGraphError: Iterating over a symbolic `tf.Tensor` is not allowed: AutoGraph did convert this function. This might indicate you are trying to use an unsupported feature.

How can I solve that?

Standalone code to reproduce the issue

nothing.

Relevant log output

No response

@google-ml-butler google-ml-butler bot added the type:bug Bug label May 10, 2024
@Venkat6871 Venkat6871 added the TF 2.9 Issues found in the TF 2.9 release (or RCs) label May 15, 2024
@Venkat6871
Copy link

Hi @saturn-drm ,

  • Sorry for the delay, I tried to run your code on colab using TF v2.9, 2.16.1 and i am not facing any issue. Please find the gist here for reference.
  • And it looks like you are using an older Version of Tensorflow (2.9). Many bugs have been fixed in the latest version. Can you please execute your code using Latest Version (2.16.1) and let us know if the issue still persists?

Thank you!

@Venkat6871 Venkat6871 added the stat:awaiting response Status - Awaiting response from author label May 15, 2024
@saturn-drm
Copy link
Author

Thank you for the reply. I will try it out as you recommended.

@google-ml-butler google-ml-butler bot removed the stat:awaiting response Status - Awaiting response from author label May 16, 2024
Copy link

Are you satisfied with the resolution of your issue?
Yes
No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TF 2.9 Issues found in the TF 2.9 release (or RCs) type:bug Bug
Projects
None yet
Development

No branches or pull requests

2 participants