tf.data.experimental.choose_from_datasets
Stay organized with collections
Save and categorize content based on your preferences.
Creates a dataset that deterministically chooses elements from datasets
.
tf.data.experimental.choose_from_datasets(
datasets, choice_dataset
)
For example, given the following datasets:
datasets = [tf.data.Dataset.from_tensors("foo").repeat(),
tf.data.Dataset.from_tensors("bar").repeat(),
tf.data.Dataset.from_tensors("baz").repeat()]
# Define a dataset containing `[0, 1, 2, 0, 1, 2, 0, 1, 2]`.
choice_dataset = tf.data.Dataset.range(3).repeat(3)
result = tf.data.experimental.choose_from_datasets(datasets, choice_dataset)
The elements of result
will be:
"foo", "bar", "baz", "foo", "bar", "baz", "foo", "bar", "baz"
Returns |
A dataset that interleaves elements from datasets according to the values
of choice_dataset .
|
Raises |
TypeError
|
If the datasets or choice_dataset arguments have the wrong
type.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-10-01 UTC.
[null,null,["Last updated 2020-10-01 UTC."],[],[],null,["# tf.data.experimental.choose_from_datasets\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------|\n| [TensorFlow 2 version](/api_docs/python/tf/data/experimental/choose_from_datasets) | [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/data/experimental/ops/interleave_ops.py#L277-L280) |\n\nCreates a dataset that deterministically chooses elements from `datasets`.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.data.experimental.choose_from_datasets`](/api_docs/python/tf/compat/v1/data/experimental/choose_from_datasets)\n\n\u003cbr /\u003e\n\n tf.data.experimental.choose_from_datasets(\n datasets, choice_dataset\n )\n\nFor example, given the following datasets: \n\n datasets = [tf.data.Dataset.from_tensors(\"foo\").repeat(),\n tf.data.Dataset.from_tensors(\"bar\").repeat(),\n tf.data.Dataset.from_tensors(\"baz\").repeat()]\n\n # Define a dataset containing `[0, 1, 2, 0, 1, 2, 0, 1, 2]`.\n choice_dataset = tf.data.Dataset.range(3).repeat(3)\n\n result = tf.data.experimental.choose_from_datasets(datasets, choice_dataset)\n\nThe elements of `result` will be: \n\n \"foo\", \"bar\", \"baz\", \"foo\", \"bar\", \"baz\", \"foo\", \"bar\", \"baz\"\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|------------------|----------------------------------------------------------------------------------------------------------------------------------------|\n| `datasets` | A list of [`tf.data.Dataset`](../../../tf/data/Dataset) objects with compatible structure. |\n| `choice_dataset` | A [`tf.data.Dataset`](../../../tf/data/Dataset) of scalar [`tf.int64`](../../../tf#int64) tensors between `0` and `len(datasets) - 1`. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A dataset that interleaves elements from `datasets` according to the values of `choice_dataset`. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|-------------|----------------------------------------------------------------------|\n| `TypeError` | If the `datasets` or `choice_dataset` arguments have the wrong type. |\n\n\u003cbr /\u003e"]]