尝试解决后仍然遇到AttributeError: module ‘tensorflow’ has no attribute ‘gfile’

在运行使用tf.gfile.GFiletf.io.gfile.GFile的代码后,我仍然遇到这个错误。你能帮我吗?

Windows 10

tensorflow GPU版本: 2.1.0

代码

`import tensorflow.compat.v1 as tfdetection_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='') `  

以及这段代码:

`

 import tensorflow as tfdetection_graph = tf.Graph()with detection_graph.as_default():  od_graph_def = tf.GraphDef()  with tf.io.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='')

`


回答:

我通过卸载TensorFlow 2.xx解决了这个问题,请安装1x TensorFlow的最后一个版本,即1.15

如果你使用Google Colab,请使用命令安装tensorflow 1.15: !pip3 install tensorflow==1.15

此外,你可以在笔记本的顶部使用%tensorflow_version 1.x来确保只使用1x版本

从这里复制这两段代码:!pip3 install tensorflow==1.15%tensorflow_version 1.x

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注