avoroshilov / neural-style

Please see dev branch for latest improvements! TensorFlow version of improved "A Neural Algorithm of Artistic Style"
https://arxiv.org/abs/1508.06576
GNU General Public License v3.0
8 stars 2 forks source link

ValueError: Optimizer keyword arg 'callback' is set automatically and cannot be injected manually #3

Closed Yagun closed 5 years ago

Yagun commented 6 years ago

It works fine with Adam, but fails with L-BFGS and CG. The error message is:

Traceback (most recent call last): File "neural_style.py", line 327, in main() File "neural_style.py", line 279, in main checkpoint_iterations=options.checkpoint_iterations File "stylize.py", line 338, in stylize scipy_optimizer.minimize(sess) File "Python35\lib\site-packages\tensorflow\contrib\opt\python\training\external_optimizer.py", line 207, in minimize optimizer_kwargs=self.optimizer_kwargs) File "Python35\lib\site-packages\tensorflow\contrib\opt\python\training\external_optimizer.py", line 397, in _minimize 'automatically and cannot be injected manually'.format(kwarg)) ValueError: Optimizer keyword arg 'callback' is set automatically and cannot be injected manually

avoroshilov commented 6 years ago

Hm, that is interesting. Probably we have different versions of SciPy (or TF), and one of these packages have breaking changes w/o backwards compatibility - the manual callbacks work perfectly on my setup.

But generally, those callbacks are only for reporting progress, so the easiest solution for you would be to just remove callback in the SciPy optimizer setup (if I understood the problem correctly), to do that please see how this line (https://github.com/avoroshilov/neural-style/blob/master/stylize.py#L308) changes from:

scipy_optimizer = external_optimizer.ScipyOptimizerInterface(loss, method='L-BFGS-B', callback=iter_callback, options=

to

scipy_optimizer = external_optimizer.ScipyOptimizerInterface(loss, method='L-BFGS-B', options=

with this line, you won't get detailed per-iteration timing (or any optimization progress report within one optimization run), but you just need to wait couple of minutes until the optimization finishes, results of the optimization should not be affected.

After you remove the callback setting for the optimizer, everything else should work I assume.

On my side to properly fix things, I would need to update all the packages and check if callbacks are still possible to use, and if not - try to find a way around that; but I don't know exactly when I will have time to do that.

avoroshilov commented 6 years ago

Oh, and just in case it helps, here is the relevant package versions that I use currently (I know, a little bit outdated :) - but I switched to non-python projects a while back):

numpy                     1.13.1                   py35_0
scikit-learn              0.18.2              np113py35_0
scipy                     0.19.1              np113py35_0
tensorflow-gpu            1.2.1                     <pip>
Yagun commented 6 years ago

Thank you very much. Removing callback=iter_callback helps. Now this optimizer works.

Yagun commented 6 years ago

I have these versions:

numpy (1.14.0) scipy (1.0.0) tensorflow-gpu (1.4.0)

There is no scikit-learn, but there is: scikit-image (0.13.1)

Will install scikit-learn, maybe it will help.

avoroshilov commented 5 years ago

Got to look into updating this code and also stumbled upon the callback being deprecated in newer versions of TF, and fixed it in https://github.com/avoroshilov/neural-style/commit/47be52a3f4d3f05f82ce9db6c2c3b21545ae67b5 - not the fastest fix in the history of humankind, but late fix is better than no fix!