TensorFlow报错AttributeError: module 'tensorflow' has no attribute 'read_file'求助
解决TensorFlow中
read_file的AttributeError问题 你的代码里导入read_file的路径已经过时,导致触发以下错误:
AttributeError: module 'tensorflow' has no attribute 'read_file'.
正如你所说,read_file函数已经迁移到tensorflow.io模块下,只需修改导入语句即可解决问题:
修正后的代码示例
from pandas.io.parsers.readers import read_table from tensorflow.io import read_file t_x, t_y = next(valid_gen)
或者也可以先导入TensorFlow主模块,再通过模块路径调用函数:
from pandas.io.parsers.readers import read_table import tensorflow as tf # 后续使用时用 tf.io.read_file() 调用函数 t_x, t_y = next(valid_gen)
补充说明
TensorFlow在版本迭代中,将IO相关工具函数统一整合到tensorflow.io公共模块下,原有的tensorflow.python.ops.gen_io_ops属于内部实现模块,不仅不推荐直接导入,而且其中的read_file函数已经被迁移,所以会出现找不到属性的错误。
内容的提问来源于stack exchange,提问作者sarra guefrachi
相关产品推荐
相关产品推荐

