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 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
)
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
)
Return self==value.
__ne__
View source
__ne__(
other
)
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 2021-02-18 UTC.
[null,null,["Last updated 2021-02-18 UTC."],[],[],null,["# tf.data.IteratorSpec\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.4.0/tensorflow/python/data/ops/iterator_ops.py#L832-L883) |\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 `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.4.0/tensorflow/python/data/ops/iterator_ops.py#L881-L883) \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.4.0/tensorflow/python/framework/type_spec.py#L93-L108) \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.4.0/tensorflow/python/framework/type_spec.py#L110-L132) \n\n most_specific_compatible_type(\n other\n )\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.4.0/tensorflow/python/framework/type_spec.py#L293-L296) \n\n __eq__(\n other\n )\n\nReturn self==value.\n\n### `__ne__`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.4.0/tensorflow/python/framework/type_spec.py#L298-L299) \n\n __ne__(\n other\n )\n\nReturn self!=value."]]