tensorflow / probability

Probabilistic reasoning and statistical analysis in TensorFlow
https://www.tensorflow.org/probability/
Apache License 2.0
4.26k stars 1.1k forks source link

Error in tensorflow_probability.optimizer #653

Closed Karthikprabhu22 closed 4 years ago

Karthikprabhu22 commented 4 years ago

System information

OS Platform and Distribution: Ubuntu 18.04.3 LTS TensorFlow installed from : pip install from anaconda TensorFlow version : ''2.0.0'' TensorFlow Probability version : '0.8.0-rc0' Python version: 3.7.3

Describe the current behavior When trying to use the tfp.optimizer.lbfgs_minimize function, I get an error :

'then' must be at least a vector, but saw shape: [] [Op:Select]

Relevant part of the code: `"""generator is a previously trained model. map_vector is tensor with the same shape as the output of the generator. """

x = tf.random.normal((1,64))

def l2(x): with tf.GradientTape() as tape: tape.watch(x) loss_value = tf.linalg.norm(generator(x) - map_vector) jac = tape.gradient(loss_value,x) return loss_value, jac

opt = tfp.optimizer.lbfgs_minimize(l2,initial_position = x, tolerance=1e-5) `

Karthikprabhu22 commented 4 years ago

The issue has been resolved. The output of l2(x) was:

, )

The shape of the loss function was (). After adding a line in the definition of the function to reshape it, the optimization worked fine.