choose_from_datasets: Creates a dataset that deterministically chooses elements...

View source: R/sample_from_datasets.R

choose_from_datasetsR Documentation

Creates a dataset that deterministically chooses elements from datasets.


Creates a dataset that deterministically chooses elements from datasets.


choose_from_datasets(datasets, choice_dataset, stop_on_empty_dataset = TRUE)



A non-empty list of objects with compatible structure.


A of scalar tf.int64 tensors between 0 and length(datasets) - 1.


If TRUE, selection stops if it encounters an empty dataset. If FALSE, it skips empty datasets. It is recommended to set it to TRUE. Otherwise, the selected elements start off as the user intends, but may change as input datasets become empty. This can be difficult to detect since the dataset starts off looking correct. Defaults to TRUE.


Returns a dataset that interleaves elements from datasets according to the values of choice_dataset.


## Not run: 
datasets <- list(tensors_dataset("foo") %>% dataset_repeat(),
                 tensors_dataset("bar") %>% dataset_repeat(),
                 tensors_dataset("baz") %>% dataset_repeat())

# Define a dataset containing `[0, 1, 2, 0, 1, 2, 0, 1, 2]`.
choice_dataset <- range_dataset(0, 3) %>% dataset_repeat(3)
result <- choose_from_datasets(datasets, choice_dataset)
result %>% as_array_iterator() %>% iterate(function(s) s$decode()) %>% print()
# [1] "foo" "bar" "baz" "foo" "bar" "baz" "foo" "bar" "baz"

## End(Not run)

tfdatasets documentation built on June 30, 2022, 1:04 a.m.