eager模式
import tensorflow as tf
import tensorflow.contrib.eager as tfe
tfe.enable_eager_execution()
# 读hdfs
# file_base_path="hdfs:///****"
# files = tf.io.gfile.glob(file_base_path)
# 读本地文件
files = [os.path.join(path, f) for f in os.listdir(path)]
dataset = tf.data.TextLineDataset(files)
for ele in tfe.Iterator(dataset):
print(ele)
读取hdfs方法https://blog.csdn.net/ustbbsy/article/details/116529836?spm=1001.2014.3001.5501
非Eager模式
import tensorflow as tf
# 读hdfs
# file_base_path="hdfs:///****"
# files = tf.io.gfile.glob(file_base_path)
# 读本地文件
files = [os.path.join(path, f) for f in os.listdir(path)]
dataset = tf.data.TextLineDataset(files)
iterator = dataset.make_one_shot_iterator()
one_element = iterator.get_next()
with tf.Session() as sess:
print(sess.run(one_element))