Cannot iterate over a Tensor with unknown first dimension.
Package:
keras
52268

Exception Class:
TypeError
Raise code
shape = [dim.value for dim in self.shape.dims]
if shape is None:
raise TypeError('Cannot iterate over a Tensor with unknown shape.')
if not shape:
raise TypeError('Cannot iterate over a scalar.')
if shape[0] is None:
raise TypeError(
'Cannot iterate over a Tensor with unknown first dimension.')
return _KerasTensorIterator(self, shape[0])
@property
def name(self):
"""Returns the (non-unique, optional) name of this symbolic Keras value."""
return self._name
@cl
Links to the raise (1)
https://github.com/keras-team/keras/blob/4a978914d2298db2c79baa4012af5ceff4a4e203/keras/engine/keras_tensor.py#L342Ways to fix
KerasTensors are tensor-like objects that represent the symbolic inputs and outputs of Keras layers during Functional model construction
Error code:
from keras.engine import keras_tensor
import tensorflow as tf
kt = keras_tensor.KerasTensor(type_spec=tf.TensorSpec(shape=(None,1), dtype=tf.float32)) #<--shape first value is None
iteration = iter(kt)
print(iteration)
When we iterate Kerastensor with the shape Null or None or the first value None, it will pop an error.
Fix code:
from keras.engine import keras_tensor
import tensorflow as tf
kt = keras_tensor.KerasTensor(type_spec=tf.TensorSpec(shape=(1,2), dtype=tf.float32))
iteration = iter(kt)
print(iteration)
Add a possible fix
Please authorize to post fix