tf.data.IteratorSpec
Stay organized with collections
Save and categorize content based on your preferences.
Type specification for tf.data.Iterator
.
Inherits From: TypeSpec
tf.data.IteratorSpec(
element_spec
)
For instance, tf.data.IteratorSpec
can be used to define a tf.function that
takes tf.data.Iterator
as an input argument:
@tf.function(input_signature=[tf.data.IteratorSpec(
tf.TensorSpec(shape=(), dtype=tf.int32, name=None))])
def square(iterator):
x = iterator.get_next()
return x * x
dataset = tf.data.Dataset.from_tensors(5)
iterator = iter(dataset)
print(square(iterator))
tf.Tensor(25, shape=(), dtype=int32)
Attributes |
element_spec
|
A (nested) structure of tf.TypeSpec objects that represents
the type specification of the iterator elements.
|
value_type
|
The Python type for values that are compatible with this TypeSpec.
In particular, all values that are compatible with this TypeSpec must be an
instance of this type.
|
Methods
from_value
View source
@staticmethod
from_value(
value
)
is_compatible_with
View source
is_compatible_with(
spec_or_value
)
Returns true if spec_or_value
is compatible with this TypeSpec.
most_specific_compatible_type
View source
most_specific_compatible_type(
other: 'TypeSpec'
) -> 'TypeSpec'
Returns the most specific TypeSpec compatible with self
and other
.
Raises |
ValueError
|
If there is no TypeSpec that is compatible with both self
and other .
|
__eq__
View source
__eq__(
other
) -> bool
Return self==value.
__ne__
View source
__ne__(
other
) -> bool
Return self!=value.
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. Some content is licensed under the numpy license.
Last updated 2022-11-04 UTC.
[null,null,["Last updated 2022-11-04 UTC."],[],[],null,["# tf.data.IteratorSpec\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.7.4/tensorflow/python/data/ops/iterator_ops.py#L884-L936) |\n\nType specification for [`tf.data.Iterator`](../../tf/data/Iterator).\n\nInherits From: [`TypeSpec`](../../tf/TypeSpec) \n\n tf.data.IteratorSpec(\n element_spec\n )\n\nFor instance, [`tf.data.IteratorSpec`](../../tf/data/IteratorSpec) can be used to define a tf.function that\ntakes [`tf.data.Iterator`](../../tf/data/Iterator) as an input argument: \n\n @tf.function(input_signature=[tf.data.IteratorSpec(\n tf.TensorSpec(shape=(), dtype=tf.int32, name=None))])\n def square(iterator):\n x = iterator.get_next()\n return x * x\n dataset = tf.data.Dataset.from_tensors(5)\n iterator = iter(dataset)\n print(square(iterator))\n tf.Tensor(25, shape=(), dtype=int32)\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Attributes ---------- ||\n|----------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `element_spec` | A (nested) structure of [`tf.TypeSpec`](../../tf/TypeSpec) objects that represents the type specification of the iterator elements. |\n| `value_type` | The Python type for values that are compatible with this TypeSpec. \u003cbr /\u003e In particular, all values that are compatible with this TypeSpec must be an instance of this type. |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `from_value`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.7.4/tensorflow/python/data/ops/iterator_ops.py#L934-L936) \n\n @staticmethod\n from_value(\n value\n )\n\n### `is_compatible_with`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.7.4/tensorflow/python/framework/type_spec.py#L103-L117) \n\n is_compatible_with(\n spec_or_value\n )\n\nReturns true if `spec_or_value` is compatible with this TypeSpec.\n\n### `most_specific_compatible_type`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.7.4/tensorflow/python/framework/type_spec.py#L119-L141) \n\n most_specific_compatible_type(\n other: 'TypeSpec'\n ) -\u003e 'TypeSpec'\n\nReturns the most specific TypeSpec compatible with `self` and `other`.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|---------|---------------|\n| `other` | A `TypeSpec`. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ||\n|--------------|--------------------------------------------------------------------------|\n| `ValueError` | If there is no TypeSpec that is compatible with both `self` and `other`. |\n\n\u003cbr /\u003e\n\n### `__eq__`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.7.4/tensorflow/python/framework/type_spec.py#L321-L324) \n\n __eq__(\n other\n ) -\u003e bool\n\nReturn self==value.\n\n### `__ne__`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.7.4/tensorflow/python/framework/type_spec.py#L326-L327) \n\n __ne__(\n other\n ) -\u003e bool\n\nReturn self!=value."]]