moonl1ght / HessianFreeOptimization

Hessian Free Optimization with Tensorflow
https://moonl1ght.github.io/HessianFreeOptimization/
28 stars 6 forks source link

Some thing was wrong ? can U help? #1

Open joyivan opened 5 years ago

joyivan commented 5 years ago

when I run the test.py , the code get this , I think there is something wrong in the line 299. Can u help ?

Traceback (most recent call last): File "test.py", line 152, in <module> example_MNIST() File "test.py", line 110, in example_MNIST hf_optimizer = HFOptimizer(sess, loss, y_out, dtype=tf.float64, batch_size=batch_size, prec_loss=None) File "/Users/joyivan/Downloads/HessianFreeOptimization/hfoptimizer.py", line 144, in __init__ cg_op, res_norm, dl = self.__conjugate_gradient(gradients) File "/Users/joyivan/Downloads/HessianFreeOptimization/hfoptimizer.py", line 300, in __conjugate_gradient **residual_norm = tf.reduce_sum([tf.reduce_sum(r**2) for r in r])** ------- File "/Users/joyivan/anaconda3/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 400, in __iter__ "Tensorobjects are not iterable when eager execution is not " TypeError:Tensorobjects are not iterable when eager execution is not enabled. To iterate over this tensor usetf.map_fn.

moonl1ght commented 5 years ago

Have you run on MNIST or XOR dataset? Have you changed test.py file? maybe you've changed some setup parameters. I've just tested it with no changes and got no bugs and crashes. While testing I've used tensorflow v 1.12.0 (when i published this, i used tensorflow v1.5.0) and it works well. I can suppose that you've changed some parameters, maybe set up to use preconditioner? And it can be that in the newest version of tensorflow they changed some function and their behaviour, in this case it can cause such bugs.

So check yor versions of tensorflow lib. And as error message suggests you: Tensorobjects are not iterable when eager execution is not " TypeError:Tensorobjects are not iterable when eager execution is not enabled. To iterate over this tensor usetf.map_fn. Try to enable eager execution in tf:

import tensorflow as tf

tf.enable_eager_execution()

More info about tf eager execution

Or if it doesn't help the only option left is to rewrite conjugate_grad method and use map_fn to unpack tensors: residual_norm = tf.reduce_sum([tf.reduce_sum(r**2) for r in r])

P.S. My current versions: python v3.6.5, tensorflow v 1.12.0, numpy v1.15.4

joyivan commented 5 years ago

Have you run on MNIST or XOR dataset? Have you changed test.py file? maybe you've changed some setup parameters. I've just tested it with no changes and got no bugs and crashes. While testing I've used tensorflow v 1.12.0 (when i published this, i used tensorflow v1.5.0) and it works well. I can suppose that you've changed some parameters, maybe set up to use preconditioner? And it can be that in the newest version of tensorflow they changed some function and their behaviour, in this case it can cause such bugs.

So check yor versions of tensorflow lib. And as error message suggests you: Tensorobjects are not iterable when eager execution is not " TypeError:Tensorobjects are not iterable when eager execution is not enabled. To iterate over this tensor usetf.map_fn. Try to enable eager execution in tf:

import tensorflow as tf

tf.enable_eager_execution()

More info about tf eager execution

Or if it doesn't help the only option left is to rewrite conjugate_grad method and use map_fn to unpack tensors: residual_norm = tf.reduce_sum([tf.reduce_sum(r**2) for r in r])

P.S. My current versions: python v3.6.5, tensorflow v 1.12.0, numpy v1.15.4

Thank a lot , I will try and check the parameters, and the version of the tools.

waverlyharden commented 5 years ago

Hi, I tried to include the eager execution, but now it is saying that that isn't compatible with tf.placeholder(). If I were to use map_fn, would that fix it? And also how would you implement map_fn for the residual_norm line above.

Thank you!

appleyuchi commented 5 years ago

@waverlyharden @moonl1ght could anyone tell we where is the $\lambda$ mentioned in this code? because the articlehave mentioned $\lambda$,so I want to know where it is in this code. Thanks~!