tensorflow / benchmarks

A benchmark framework for Tensorflow
Apache License 2.0
1.14k stars 632 forks source link

ImportError: cannot import name 'variable_v1' from 'tensorflow.python.ops' #549

Closed baroai closed 11 months ago

baroai commented 11 months ago

I git this error with

GPU = 4090 RTX 2ea CPU = Intel OS = Ubuntu20.04 Tensorflow=2.7.0 Protobuf=3.20.0 python=3.9.0

run command is python tf_cnn_benchmakrs.py --model resnet50 --batch_size 200 --num_gpus 2 and i got this error

Traceback (most recent call last):
  File "tf_cnn_benchmarks.py", line 25, in <module>
    import benchmark_cnn
  File "/root/test/benchmarks/scripts/tf_cnn_benchmarks/benchmark_cnn.py", line 44, in <module>
    from models import model_config
  File "/root/test/benchmarks/scripts/tf_cnn_benchmarks/models/model_config.py", line 21, in <module>
    from models import alexnet_model
  File "/root/test/benchmarks/scripts/tf_cnn_benchmarks/models/alexnet_model.py", line 24, in <module>
    from models import model
  File "/root/test/benchmarks/scripts/tf_cnn_benchmarks/models/model.py", line 23, in <module>
    from tensorflow.python.ops import variable_v1  # pylint: disable=g-direct-tensorflow-import
ImportError: cannot import name 'variable_v1' from 'tensorflow.python.ops' (/usr/local/lib/python3.8/dist-packages/tensorflow/python/ops/__init__.py)

previeous tf_cnn_benchmark is running correctly but now it doesn't work...

what should i do?

baroai commented 11 months ago

When I checked the commit version 559f08f I was able to identify the error. The error was related to the inability to import 'variable_v1,' and it indicated that the model's library could not be found in TensorFlow versions 2.5 and above. I made the same changes to this part as I did in my previous work, for example, changing variable_v1 to variables and I confirmed that GPU operations work afterward. I would like to know why the variable name was changed to one that doesn't work like this.

reedwm commented 11 months ago

The master branch of this repo has been updated to work with the latest nightly version of TensorFlow, and so it no longer works with older versions like TF 2.7.0. You can try an older commit, such as one before 559f08f2cc76c9dbd30f25abc66acc516d1b4bd0.