Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error on tf.contrib.opt.ScipyOptimizerInterface #45

Open
AmirNoori68 opened this issue Dec 31, 2022 · 4 comments
Open

error on tf.contrib.opt.ScipyOptimizerInterface #45

AmirNoori68 opened this issue Dec 31, 2022 · 4 comments

Comments

@AmirNoori68
Copy link

AmirNoori68 commented Dec 31, 2022

Hi,
This code is based on the "TF1.X".
There is no way to get "TF1.X" anymore on either Google colab or Jupyter.
Just the "TF1.X" parts can be updated to "TF2.X" by two following lines:
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

But I still get error in "self.optimizer = tf.contrib.opt.ScipyOptimizerInterface()."
It says, "AttributeError: module 'tensorflow.compat.v1' has no attribute 'contrib' ."
The reason is that "tf.contrib" is not changed, but moved from tensorflow!
Can anyone help to solve this problem?

@vl-dud
Copy link

vl-dud commented Mar 17, 2023

@AmirNoori68 you can just add ScipyOptimizerInterface to helper.py file from external_optimizer.py
Then import from helper import ScipyOptimizerInterface and replace tf.contrib.opt.ScipyOptimizerInterface to ScipyOptimizerInterface

@AmirNoori68
Copy link
Author

@vldud-off Works fine. Thanks!

@RoboticAutonomy
Copy link

where is helper.py and how to add ScipyOptimizerInterface ?

@AmirNoori68
Copy link
Author

where is helper.py and how to add ScipyOptimizerInterface ?

First, download https://github.com/tensorflow/tensorflow/blob/876fc8dc4f40c75914dbfcb0a809feaf81be7412/tensorflow/contrib/opt/python/training/external_optimizer.py, give it a name like "helper.py" and put it in the main folder.

next, add "from helper import ScipyOptimizerInterface" to the main code.

Finally, replace the current Scipy optimizer ("tf.contrib.opt.ScipyOptimizerInterface") with the following code:
self.optimizer = ScipyOptimizerInterface(self.loss,
method = 'L-BFGS-B',
options = {'maxiter': 50000,
'maxfun': 50000,
'maxcor': 50,
'maxls': 50,
'ftol' : 1.0 * np.finfo(float).eps})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants