How do I use Autograph and TensorArrays correctly?

The following python snippet

@tf.function def testfn(arr): if arr.size() == 0: raise ValueError('arr is empty') else: return tf.constant(True) arr = tf.TensorArray(tf.float32, 3) arr = arr.unstack([tf.constant(range(5), dtype=tf.float32) for i in range(3)]) tf.print('Size:', arr.size()) # "Size: 3" arrVal = testfn(arr) # Unexpected(?) ValueError: arr is empty 

produces the following output

Size: 3 --------------------------------------------------------------------------- ValueError Traceback (...) ValueError: in user code: <ipython-input-72-47c594b1a619>:4 testfn * if arr.size() == 0: raise ValueError('arr is empty') ValueError: arr is empty 

and I don’t understand why. When I print the size of the array I get 3. When I call testfn without the decorator, python also evaluates arr.size() to 3 in eager mode. But why does Autograph compile the array to something of size 0? And more importantly, how do I solve this problem? (I am very new to tensorflow)

submitted by /u/Dubmove
[visit reddit] [comments]

Leave a Reply

Your email address will not be published.