Se usó la API de Cloud Translation para traducir esta página.
Switch to English

tf.compat.v1.enable_v2_tensorshape

Ver código fuente en GitHub

En TensorFlow 2,0, iterar sobre una instancia TensorShape valores devoluciones.

Esto permite que el nuevo comportamiento.

Concretamente, tensor_shape[i] devuelve una instancia de dimensión en V1, V2 pero vuelve ya sea un número entero, o Ninguno.

Ejemplos:

 #######################
# If you had this in V1:
value = tensor_shape[i].value

# Do this in V2 instead:
value = tensor_shape[i]

#######################
# If you had this in V1:
for dim in tensor_shape:
  value = dim.value
  print(value)

# Do this in V2 instead:
for value in tensor_shape:
  print(value)

#######################
# If you had this in V1:
dim = tensor_shape[i]
dim.assert_is_compatible_with(other_shape)  # or using any other shape method

# Do this in V2 instead:
if tensor_shape.rank is None:
  dim = Dimension(None)
else:
  dim = tensor_shape.dims[i]
dim.assert_is_compatible_with(other_shape)  # or using any other shape method

# The V2 suggestion above is more explicit, which will save you from
# the following trap (present in V1):
# you might do in-place modifications to `dim` and expect them to be reflected
# in `tensor_shape[i]`, but they would not be.