tensorflow API中gfile是获取文本操作句柄,类似于python提供的文本操作open()函数,filename是要打开的文件名,mode是以何种方式去读写,将会返回一个文本操作句柄
报错原因:
gfile在tf中受版本影响
解决办法:
# Tensorflow 2.0 gfile 文件操作
Tensorflow 2.0在10月1号已经正式发布,也早就支持Python 3.7 了,tf.gfile 也改成 tf.io.gfile了.
label_map_util.py(源码文件)文件中是使用1.X版本写的 改成tf.io.gfile.Gfile就行了。
AttributeError: module 'tensorflow' has no attribute 'GraphDef'
报错原因:
受tf版本的影响
解决办法:
1.
graph = tf.Graph()
#替换成tf.compat.v1
graph_def = tf.compat.v1.GraphDef()
#或者在import中替换
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
#其余替换
tf.compat.v1.GraphDef() # -> instead of tf.GraphDef()
tf.compat.v2.io.gfile.GFile() # -> instead of tf.gfile.GFile()
2.
降低tensorflow的版本,将tensorflow2.X的降低为tensorflow1.X
#卸载tensorflow
pip uninstall tensorflow
conda uninstall tensorflow
#安装制定版本的tensorflow
pip install tensorflow=1.8.0
ERROR conda.core.link:_execute_actions(337): An error occurred while installing package 'defaults::tqdm-4.32.1-py_0'.
CondaError: Cannot link a source that does not exist. D:\Anaconda\Scripts\conda.exe
报错原因:
tf版本影响
解决办法:
将tensorflow版本变成1.12.0就ok了