# tf.data.experimental.get_single_element

<br />

|---|---|
| [![](https://www.tensorflow.org/images/tf_logo_32px.png) TensorFlow 2 version](https://www.tensorflow.org/api_docs/python/tf/data/experimental/get_single_element) | [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/data/experimental/ops/get_single_element.py#L26-L70) |

Returns the single element in `dataset` as a nested structure of tensors.

#### View aliases


**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

[`tf.compat.v1.data.experimental.get_single_element`](https://www.tensorflow.org/api_docs/python/tf/data/experimental/get_single_element), \`tf.compat.v2.data.experimental.get_single_element\`

<br />

    tf.data.experimental.get_single_element(
        dataset
    )

This function enables you to use a [`tf.data.Dataset`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/data/Dataset) in a stateless
"tensor-in tensor-out" expression, without creating a
[`tf.compat.v1.data.Iterator`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/data/Iterator).
This can be useful when your preprocessing transformations are expressed
as a `Dataset`, and you want to use the transformation at serving time.
For example:

    input_batch = tf.compat.v1.placeholder(tf.string, shape=[BATCH_SIZE])

    def preprocessing_fn(input_str):
      # ...
      return image, label

    dataset = (tf.data.Dataset.from_tensor_slices(input_batch)
               .map(preprocessing_fn, num_parallel_calls=BATCH_SIZE)
               .batch(BATCH_SIZE))

    image_batch, label_batch = tf.data.experimental.get_single_element(dataset)

<br />

<br />

<br />

| ## Args ||
|---|---|
| `dataset` | A [`tf.data.Dataset`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/data/Dataset) object containing a single element. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A nested structure of [`tf.Tensor`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/Tensor) objects, corresponding to the single element of `dataset`. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `TypeError` | if `dataset` is not a [`tf.data.Dataset`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/data/Dataset) object. InvalidArgumentError (at runtime): if `dataset` does not contain exactly one element. |

<br />