问题描述: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来处理。