1

I thought a callable is just a function from the tf-library that I call. This:

tensor = tf.while_loop(tf.less(tf.rank(tensor), ndims),        # cond
                       tf.append(tensor, axis=axis),           # body
                       loop_vars = [tensor])                   # loop_vars

errors to TypeError: cond must be callable.

What is a callable condition if not tf.less()?

Honeybear
  • 2,928
  • 2
  • 28
  • 47

2 Answers2

3

A callable is anything that can be called. See here.

The cond should be a function. You can use lambda (See here) to make your condition callable.

Here there is a minimal example of how to use tf.while_loop:

i = tf.constant(0)
c = lambda i: tf.less(i, 10)
b = lambda i: tf.add(i, 1)
r = tf.while_loop(c, b, [i])

And in the end, not a bad idea to post a minimal code that actually runs and generates your error.

Fariborz Ghavamian
  • 809
  • 2
  • 11
  • 23
1

tf.less is an Operation object. To make it callable, just use a lambda:

tensor = tf.while_loop(lambda tensor: tf.less(tf.rank(tensor), ndims), # cond
                       lambda tensor: tf.append(tensor, axis=axis),    # body
                       loop_vars = [tensor])                           # loop_vars
scrpy
  • 985
  • 6
  • 23