Skip to content

AttributeError: 'ExponentialMovingAverage' object has no attribute 'variables_to_restore' #802

Closed

Description

@carlos-argueta

I am running the code provided with the tutorial Convolutional Neural Networks https://www.tensorflow.org/versions/master/tutorials/deep_cnn/index.html

The training works fine, but when I run the evaluation I get the following error. I have not modified in any way the code, I am running it as is.

Code snippet:
...

Restore the moving average version of the learned variables for eval.

variable_averages = tf.train.ExponentialMovingAverage(
    cifar10.MOVING_AVERAGE_DECAY)
variables_to_restore = variable_averages.variables_to_restore()
saver = tf.train.Saver(variables_to_restore)

...

Error:

Traceback (most recent call last):
File "cifar10_eval.py", line 161, in
tf.app.run()
File "/Library/Python/2.7/site-packages/tensorflow/python/platform/default/_app.py", line 30, in run
sys.exit(main(sys.argv))
File "cifar10_eval.py", line 157, in main
evaluate()
File "cifar10_eval.py", line 135, in evaluate
variables_to_restore = variable_averages.variables_to_restore()
AttributeError: 'ExponentialMovingAverage' object has no attribute 'variables_to_restore'

Please help,

Activity

  1. manuvector commented on Jan 18, 2016

    @manuvector

    I get the same error, I think that they have changed something on the code moving_averages.py code

  2. aymericdamien commented on Jan 18, 2016

    @aymericdamien
    Contributor

    What is your tensorflow version? You might need master branch version of tensorflow to make that script running. (In 0.6.0, ExponentialMovingAverage has no attributes variables_to_restore, but master version has it.)

  3. manuvector commented on Jan 18, 2016

    @manuvector

    Yes it was version 0.6 as it says in the download section of tensorflow,
    but i don't know how to install the master version as a package, should I
    download the github repository on the library folder (
    /Library/Python/2.7/site-packages/tensorflow/...) ?
    Thanks a lot,
    Manu

    On Mon, Jan 18, 2016 at 3:30 PM, Aymeric Damien [email protected]
    wrote:

    What is your tensorflow version? You might need master branch version of
    tensorflow to make that script running. (In 0.6.0, ExponentialMovingAverage
    has no attributes variables_to_restore, but master version has it.)

    —
    Reply to this email directly or view it on GitHub
    #802 (comment)
    .

  4. manuvector commented on Jan 18, 2016

    @manuvector

    After @aymericdamien recommendation I have copied the tensorflow folder with all the training scripts from master version (downloaded from github) into 0.6 (installed version, which is different) and now cifar10_eval goes a bit further, it doesn't say that 'ExponentialMovingAverage' object has no attribute 'variables_to_restore' but once in the variables to restore called function it says

    ...
    File "/Library/Python/2.7/site-packages/tensorflow/python/training/moving_averages.py", line 307, in variables_to_restore
    moving_avg_variables = list(set(variables.moving_average_variables() +
    AttributeError: 'module' object has no attribute 'moving_average_variables'
    ...

    Any ideas?

  5. josh11b commented on Jan 19, 2016

    @josh11b
    Contributor

    Sherry, this looks related to 110808120 or 110781462.

  6. vrv commented on Jan 20, 2016

    @vrv

    If you're using the 0.6.0 pip installation, you should check out the code at the 0.6.0 branch. There's no guarantee that the scripts at HEAD will work with the old binaries, since we add features to HEAD and then update our examples.

  7. carlos-argueta commented on Jan 20, 2016

    @carlos-argueta
    Author

    I have downloaded the master version from github just like @manucarbonell did. I am using a virtualenv called tf. If I don't activate the tf I keep on getting the original error. If I activate tf I get the following. Please advice.

    (tf)Carloss-MacBook-Pro:~ Carlos$ python ~/../../Volumes/Transcend/Dropbox/workspace/TensorFlow/CIFAR10/tensorflow-master-tensorflow-models-image-cifar10/cifar10_train.py
    Traceback (most recent call last):
    File "/Users/Carlos/../../Volumes/Transcend/Dropbox/workspace/TensorFlow/CIFAR10/tensorflow-master-tensorflow-models-image-cifar10/cifar10_train.py", line 43, in
    import tensorflow.python.platform
    File "/Users/Carlos/.virtualenvs/tf/lib/python2.7/site-packages/tensorflow/init.py", line 23, in
    from tensorflow.python import *
    File "/Users/Carlos/.virtualenvs/tf/lib/python2.7/site-packages/tensorflow/python/init.py", line 43, in
    raise ImportError(msg)
    ImportError: Traceback (most recent call last):
    File "/Users/Carlos/.virtualenvs/tf/lib/python2.7/site-packages/tensorflow/python/init.py", line 37, in
    from tensorflow.core.framework.graph_pb2 import *
    ImportError: No module named core.framework.graph_pb2

    Error importing tensorflow. Unless you are using bazel,
    you should not try to import tensorflow from its source directory;
    please exit the tensorflow source tree, and relaunch your python interpreter
    from there.

  8. manuvector commented on Jan 22, 2016

    @manuvector

    I managed to run the example successfully again after using the version 0.6.0, which doesn't have the line
    "variables_to_restore = variable_averages.variables_to_restore()"
    in cifar10_eval

    Thanks to the moderators!

  9. amisios commented on Feb 3, 2016

    @amisios

    Manu or Carlos, could you elaborate a bit on how you solved this problem?
    Or rather how this tutorial can work for tensorflow 0.6.0.

  10. jguiraudet commented on Feb 4, 2016

    @jguiraudet

    The commit 64f8a3b introduced a change in the API by adding the variables_to_restore() function.

    You need to get the source code 0.6.0 of the example to run this example:

    git clone https://github.com/tensorflow/tensorflow.git
    git checkout 0.6.0
    cd tensorflow/tensorflow/models/image/cifar10/
    python cifar10_train.py --max_steps=20                   # Just a few steps to check the script
    python cifar10_eval.py --num_examples 1000 --run_once 1  # Just once to check the script
  11. amisios commented on Feb 4, 2016

    @amisios

    Thanks for the answer. I found the 0.6.0 tutorial and it works. (while still producing the big number of warnings and errors about the queues. Same as in #389 . It is something related to the threads but it takes place after the computation is complete).

  12. sherrym commented on Apr 5, 2016

    @sherrym
    Contributor

    This should have long been fixed now that both the code and pip package containing this change has been available for several months.

  13. added a commit that references this issue on Jan 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions