如何将 MapDataset 转换为张量

tik*_*tok 7 tensorflow tensorflow-datasets

我正在使用 tensorflow_io_bigquery_client 来从 bq 读取数据。每条记录有 4 个整数元素。

但我需要将其转换为张量(每个 4 个整数)。

所以我有类似的东西:

tensorflow_io_bigquery_client = BigQueryClient()
read_session = tensorflow_io_bigquery_client.read_session(..)

dataset = read_session.parallel_read_rows()
dataset = dataset.map (transofrom_row)
#todo convert it into tensor (but i guess it should be an iterator or something like this because the dataset is hugh?

k_means_estimator = tf.compat.v1.estimator.experimental.KMeans(num_clusters = num_clusters, use_mini_batch = False, relative_tolerance = 1)

fit = k_means_estimator.train(input_fn=lambda: to_tensor(dataset), steps=1000) 
# todo convert dataset into tensor
Run Code Online (Sandbox Code Playgroud)