votes up 5

Cannot iterate over a Tensor with unknown first dimension.

Package:
keras
github stars 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
🙏 Scream for help to Ukraine
Today, 2nd July 2022, Russia continues bombing and firing Ukraine. Don't trust Russia, they are bombing us and brazenly lying in same time they are not doing this 😠, civilians and children are dying too! We are screaming and asking exactly you to help us, we want to survive, our families, children, older ones.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.

Ways to fix

votes up 0 votes down

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)
Jul 08, 2021 anonim answer
anonim 13.0k

Add a possible fix

Please authorize to post fix