问题1
if not tf.gfile.Exists(output_filename):
AttributeError: module 'tensorflow' has no attribute 'gfile'
在当前的版本中,gfile已经定义在io包的file_io.py中。
if not tf.io.gfile.exists(output_filename):
return False
问题2
if not tf.io.gfile.Exists(output_filename):
AttributeError: module 'tensorflow._api.v2.io.gfile' has no attribute 'Exists'
使用小写tf.io.gfile.exists()即可
if not tf.io.gfile.exists(output_filename):
return False
问题3
AttributeError: module 'tensorflow_core._api.v2.io.gfile' has no attribute 'get_filesystem'
环境的问题,由于python环境中同时安装了PyTorch和tensorflow,所以导致了在使用tensorboard时,是按tensorflow的api来查找的,因此导致了这个问题,也就是环境冲突了。
卸载一个即可
问题4
with tf.Session() as sess:
AttributeError: module 'tensorflow' has no attribute 'Session'
报错AttributeError: module 'tensorflow' has no attribute 'Session'。这其实不是安装错误,是因为在新的Tensorflow 2.0版本中已经移除了Session这一模块,改换运行代码
tf.compat.v1.Session()
就可以获得与原先相同的输出信息。如果觉得不方便,也可以改换低版本的Tensorflow,直接用pip即可安装
pip install tensorflow==1.14
问题5
AttributeError: module 'tensorflow' has no attribute 'python_io'
把TensorFlow2.0版本改为原来的1.xx版本,例如改为TensorFlow 1.14.0
TensorFlow 2.0 中使用 Python_io 暂时使用如下指令
tf.compat.v1.python_io.TFRecordWriter(filename)