models icon indicating copy to clipboard operation
models copied to clipboard

AttributeError: module 'tensorflow._api.v1.io' has no attribute 'gfile'

Open Muguangfeng opened this issue 7 years ago • 9 comments

According to readme in the models/research/efficient-hrl folder, I run: python scripts/local_train.py test1 hiro_orig ant_maze base_uvf suite

but it tells the problem: "AttributeError: module 'tensorflow._api.v1.io' has no attribute 'gfile'' This is on tensorflow 1.12.0

if I change the version of tensorflow, it will be other questions : AttributeError: module 'tensorflow.io' has no attribute 'gfile' (tf1.11.0)

AttributeError: module 'tensorflow._api.v1.compat' has no attribute 'v2' (tf1.13.1)

AttributeError: module 'tensorflow' has no attribute 'io' (tf1.5.0) Does anyone know how to solve it? Thanks!

Muguangfeng avatar Apr 30 '19 13:04 Muguangfeng

Thank you for your post. We noticed you have not filled out the following field in the issue template. Could you update them if they are relevant in your case, or leave them as N/A? Thanks. What is the top-level directory of the model you are using Have I written custom code OS Platform and Distribution TensorFlow installed from TensorFlow version Bazel version CUDA/cuDNN version GPU model and memory Exact command to reproduce

tensorflowbutler avatar May 01 '19 12:05 tensorflowbutler

Thank you for your post. We noticed you have not filled out the following field in the issue template. Could you update them if they are relevant in your case, or leave them as N/A? Thanks. What is the top-level directory of the model you are using --/home Have I written custom code --no OS Platform and Distribution --ubuntu16.04 LTS TensorFlow installed from --pip or conda TensorFlow version --tensorflow 1.12.0 , other versions have also been tried. Bazel version --not clear CUDA/cuDNN version --CUDA9.0 , cuDNN7.1 GPU model and memory --Two TITAN Xp, 12196MiB,I use tensorflow(not tensorflow-gpu), If necessary, I can also use tensorflow-gpu Exact command to reproduce --Don't quite understand this.

https://github.com/tensorflow/models/tree/master/research/efficient-hrl Run command: python scripts/local_train.py test1 hiro_orig ant_maze base_uvf suite Then the above error will occur.

Muguangfeng avatar May 02 '19 09:05 Muguangfeng

Now, I installed tensorflow1.12.0 by running: pip install tensorflow==1.12.0 In this way, the code can run more, reach line 29 of run_train.py. But it still occurs error.

`

Traceback (most recent call last): File ".//run_train.py", line 49, in tf.app.run() File "/home/yang/.conda/envs/hiro/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 40, in run _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef) File "/home/yang/.conda/envs/hiro/lib/python3.6/site-packages/absl/app.py", line 300, in run _run_main(main, args) File "/home/yang/.conda/envs/hiro/lib/python3.6/site-packages/absl/app.py", line 251, in _run_main sys.exit(main(argv)) File ".//run_train.py", line 45, in main return train.train_uvf(FLAGS.train_dir) File "/home/yang/.conda/envs/hiro/lib/python3.6/site-packages/gin/config.py", line 979, in wrapper new_kwargs = copy.deepcopy(new_kwargs) File "/home/yang/.conda/envs/hiro/lib/python3.6/copy.py", line 150, in deepcopy y = copier(x, memo) File "/home/yang/.conda/envs/hiro/lib/python3.6/copy.py", line 240, in _deepcopy_dict y[deepcopy(key, memo)] = deepcopy(value, memo) File "/home/yang/.conda/envs/hiro/lib/python3.6/copy.py", line 161, in deepcopy y = copier(memo) File "/home/yang/.conda/envs/hiro/lib/python3.6/site-packages/gin/config.py", line 336, in deepcopy return self._scoped_configurable_fn() File "/home/yang/.conda/envs/hiro/lib/python3.6/site-packages/gin/config.py", line 261, in scoping_wrapper return fn(*args, **kwargs) File "/home/yang/.conda/envs/hiro/lib/python3.6/site-packages/gin/config.py", line 1032, in wrapper utils.augment_exception_message_and_reraise(e, err_str) File "/home/yang/.conda/envs/hiro/lib/python3.6/site-packages/gin/utils.py", line 49, in augment_exception_message_and_reraise six.raise_from(proxy.with_traceback(exception.traceback), None) File "", line 3, in raise_from File "/home/yang/.conda/envs/hiro/lib/python3.6/site-packages/gin/config.py", line 1009, in wrapper return fn(*new_args, **new_kwargs) File "/home/yang/models-master/research/efficient-hrl/agents/circular_buffer.py", line 50, in init self._num_adds_cs = tf.contrib.framework.CriticalSection(name='num_adds') AttributeError: module 'tensorflow.contrib.framework' has no attribute 'CriticalSection' In call to configurable 'CircularBuffer' (<function CircularBuffer.init at 0x7f025157f2f0>) in scope 'agent'

` Anyone know how to solve it?

Muguangfeng avatar May 05 '19 04:05 Muguangfeng

Hello, I got same error when I run tensorflow 1.9.0. I am trying to run tensorflow object detection api, but it is not loading graph.

OS Platform and Distribution : Windows 10 TensorFlow installed from : Tensorflow 1.9.0 ( pip install tensorflow==1.9.0) TensorFlow version : 1.9.0 Bazel version : not sure CUDA/cuDNN version : CPU GPU model and memory : I don't use GPU. Exact command to reproduce There is the code:

    with detection_graph_below.as_default():
        od_graph_def = tf.GraphDef()
        with tf.io.gfile.GFile(PATH_TO_CKPT_BELOW, 'rb') as fid:
            serialized_graph = fid.read()
            od_graph_def.ParseFromString(serialized_graph)
            tf.import_graph_def(od_graph_def, name='')

And the error message:

with tf.io.gfile.GFile(PATH_TO_CKPT_BELOW, 'rb') as fid:
AttributeError: module 'tensorflow' has no attribute 'io'

What is the solution? Thank you

albingit70 avatar Nov 24 '19 17:11 albingit70

hello, I am getting the same error when I run the tensorflow 2.0. I am trying to load the inception model, but it is not loading.

OS platform and distribution: macOS catalina v0.15.2 Tensorflow installed from: pip3 tensorflow version: 2.0 bazel version: unclear CUDA/cuDNN version: CPU GPU: NA code snippet: with tf.io.gfile.FastGFile(path, 'rb') as file: and the error message: AttributeError: module 'tensorflow_core._api.v2.io.gfile' has no attribute 'FastGFile' how to solve this? Thank you regards jayesh

0tist avatar Dec 17 '19 05:12 0tist

same error as above. Haven't found resolution yet

rbtirumala avatar Jan 30 '20 14:01 rbtirumala

Maybe using tf.compat.v1.gfile.FastGFile instead of tf.gfile.FastGFile resolves your issue. It's just a guess :)

The attribute was resolvable for me in 2.2.0rc4:

$ pip list | grep tensorflow
tensorflow               2.2.0rc4
tensorflow-estimator     2.2.0

https://www.tensorflow.org/api_docs/python/tf/compat/v1/gfile/FastGFile

ellcs avatar Apr 30 '20 20:04 ellcs

I will respond to the original query from Muguangfeng (the other issues I am not sure on and may be best created as separate issues). It seems the underlying issue is with CriticalSection, and the fact that the alias for it has changed in tf1.12. Try replacing that call with tf.CriticalSection and see what happens.

ofirnachum avatar Jun 25 '20 14:06 ofirnachum

GUYS! For tensorflow-gpu=2.2

I replaced this: { detection_graph = tf.Graph() with detection_graph.as_default(): od_graph_def = tf.GraphDef() with tf.gfile.GFile(PATH_TO_CKPT, 'rb') as fid: serialized_graph = fid.read() od_graph_def.ParseFromString(serialized_graph) tf.import_graph_def(od_graph_def, name='') } with: { detection_graph = tf.compat.v1.Graph() with detection_graph.as_default(): od_graph_def = tf.compat.v1.GraphDef() with tf.gfile.GFile(PATH_TO_CKPT, 'rb') as fid: serialized_graph = fid.read() od_graph_def.ParseFromString(serialized_graph) tf.import_graph_def(od_graph_def, name='') }

And it is working perfect!

sanaz-rasti avatar May 08 '21 10:05 sanaz-rasti