问题:AttributeError: module 'tensorflow' has no attribute 'gfile'

问题

运行如下代码

    if not tf.gfile.exists(DATA_DIRECTORY):
        tf.gfile.makedirs(DATA_DIRECTORY)
    with tf.gfile.GFile(filepath) as f:

会出现如下问题:
AttributeError: module ‘tensorflow’ has no attribute ‘gfile’

原因与解决方案

问题产生的原因:在当前的版本中,gfile已经定义在io包的file_io.py中。

解决方案1

所以只要改为下面的即可:

    if not tf.io.gfile.exists(DATA_DIRECTORY):
        tf.io.gfile.makedirs(DATA_DIRECTORY)
    with tf.io.gfile.GFile(filepath) as f:

解决方案2

上面代码其实就是判断给定路径下的文件夹是否存在,如果不存在则创建文件夹。
所以可以用python的os.path来处理。

评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

脑机接口社区

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值