将 tf tf.data.Dataset 元组拆分为多个数据集
Split tf tf.data.Dataset tuple into several datasets
我有一个 tf.data.Dataset 形状如下:
<ConcatenateDataset shapes: ((None, None, 12), (None, 5)), types: (tf.float64, tf.float64)>
我可以拆分此数据集以获得如下所示的两个数据集吗:
<Dataset shapes: (None, None, 12), types: tf.float64>
<Dataset shapes: (None, 5), types: tf.float64>
您可以使用map
函数来拆分它们。
演示:
import tensorflow as tf
# Create a random tensorflow dataset.
dataset1 = tf.data.Dataset.from_tensor_slices((tf.random.uniform([40, 10, 12]), tf.random.uniform([40, 5]))).batch(16)
dataset2 = tf.data.Dataset.from_tensor_slices((tf.random.uniform([40, 12, 12]), tf.random.uniform([40, 5]))).batch(16)
dataset = dataset1.concatenate(dataset2)
dataset
>> <ConcatenateDataset shapes: ((None, None, 12), (None, 5)), types: (tf.float32, tf.float32)>
拆分顺序:
data = dataset.map(lambda x, y: x)
labels = dataset.map(lambda x, y: y)
我有一个 tf.data.Dataset 形状如下:
<ConcatenateDataset shapes: ((None, None, 12), (None, 5)), types: (tf.float64, tf.float64)>
我可以拆分此数据集以获得如下所示的两个数据集吗:
<Dataset shapes: (None, None, 12), types: tf.float64>
<Dataset shapes: (None, 5), types: tf.float64>
您可以使用map
函数来拆分它们。
演示:
import tensorflow as tf
# Create a random tensorflow dataset.
dataset1 = tf.data.Dataset.from_tensor_slices((tf.random.uniform([40, 10, 12]), tf.random.uniform([40, 5]))).batch(16)
dataset2 = tf.data.Dataset.from_tensor_slices((tf.random.uniform([40, 12, 12]), tf.random.uniform([40, 5]))).batch(16)
dataset = dataset1.concatenate(dataset2)
dataset
>> <ConcatenateDataset shapes: ((None, None, 12), (None, 5)), types: (tf.float32, tf.float32)>
拆分顺序:
data = dataset.map(lambda x, y: x)
labels = dataset.map(lambda x, y: y)