tensorflow使用中的问题

问题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)

 

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值