Split a tf.data.Dataset in to two distincts Input and Target tf.data.Dataset

Viewed 616

How can I create two distincts Input and Target tf.data.Dataset from a tf.data.Dataset containing both Input and Target data so that I can uses them as x and y parameters of the model.fit function?

I use the code below to load the dataset

    dataset = tf.data.TFRecordDataset(
        dataset_file_path, 
        compression_type='GZIP', 
        buffer_size=None, 
        num_parallel_reads=None
    )
1 Answers

How did you create this dataset?

If each element in the dataset is in the format (input_data, target_data) then you can do

input_dataset = dataset.map(lambda x,y: x)
target_dataset = dataset.map(lambda x,y: y)
Related