打开 Google colab 笔记本并运行以下语句
#
import tensorflow as tf
import pathlib
import os
dataset = tf.data.TextLineDataset('/content/sample_data/california_housing_test.csv')
dataset ## output is <TextLineDatasetV2 shapes: (), types: tf.string>
然后在下面运行
import tensorflow as tf
import pathlib
import os
dataset = tf.data.experimental.make_csv_dataset('/content/sample_data/california_housing_test.csv',batch_size=5)
dataset ## output is <PrefetchDataset shapes: OrderedDict([(longitude, (5,)), (latitude, (5,)), (housing_median_age, (5,)), (total_rooms, (5,)), (total_bedrooms, (5,)), (population, (5,)), (households, (5,)), (median_income, (5,)), (median_house_value, (5,))]), types: OrderedDict([(longitude, tf.float32), (latitude, tf.float32), (housing_median_age, tf.float32), (total_rooms, tf.float32), (total_bedrooms, tf.float32), (population, tf.float32), (households, tf.float32), (median_income, tf.float32), (median_house_value, tf.float32)])>
显然 tf.data.TextLineDataset 和 tf.data.experimental.make_csv_dataset 处理文本文件的方式存在巨大差异。为什么tensorflow有这两个在实验中,另一个在外面。