tensorflow: graph.get_operation() returns operations that are not from the respective name_scope

Please make sure that this is a bug. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:bug_template

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow):
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04):
  • Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device:
  • TensorFlow installed from (source or binary): conda
  • TensorFlow version (use command below): 1.14
  • Python version: 2.7
  • Bazel version (if compiling from source):
  • GCC/Compiler version (if compiling from source):
  • CUDA/cuDNN version:
  • GPU model and memory:

You can collect some of this information using our environment capture script You can also obtain the TensorFlow version with: 1. TF 1.0: python -c "import tensorflow as tf; print(tf.GIT_VERSION, tf.VERSION)" 2. TF 2.0: python -c "import tensorflow as tf; print(tf.version.GIT_VERSION, tf.version.VERSION)"

Describe the current behavior function get_operations() from class Graph() is not returning the operations from a namescope enclosing the tensorflow operations from respective namescope but is returning the operations for all the graph

Describe the expected behavior

Returns only the operations from name scope, and preferable shorted by construction just like in the original list.

Code to reproduce the issue

tf.reset_default_graph()
graph = tf.Graph()
with graph.as_default():
  with tf.variable_scope('aa'):
    c = tf.constant(10.0,name='const')
    a = tf.Variable(c,name='nomon')
  with tf.variable_scope('ab'):
    c = tf.constant(10.0,name='const')
    a = tf.Variable(c,name='nomon')  

with graph.as_default():    
  with tf.name_scope('aa/'):
    print(graph.get_operations()[-1].name)

Other info / logs

I know this seems to be a fairly trivial problem to be circumvented (a.k.a search for the operations by the name with if and elses). But this bug brings out a possible ugly spagethi code, and seems fairly easy to fiz in the api, without having to go to the backend.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 17 (8 by maintainers)

Most upvoted comments

graph.get_operations() is not intended to depend on the current thread-local name-scope, so this is working as intended.

Perhaps this can be a Feature Request since we already have get_operation_by_name

Was able to reproduce the issue with Tensorflow 1.14.0 on Colab. Please find the gist here. Thanks!