Add an additional `NoneType` check when converting a traced tensor to a `KerasTensor`.
PiperOrigin-RevId: 336694750
Change-Id: Ic79bc3b46b81d4816a7108ed9b1aa426e7f4d3d5
diff --git a/tensorflow/python/keras/engine/keras_tensor.py b/tensorflow/python/keras/engine/keras_tensor.py
index 0c2c8bf..0557520 100644
--- a/tensorflow/python/keras/engine/keras_tensor.py
+++ b/tensorflow/python/keras/engine/keras_tensor.py
@@ -170,7 +170,8 @@
name = getattr(tensor, 'name', None)
type_spec = type_spec_module.type_spec_from_value(tensor)
inferred_value = None
- if (type_spec.dtype == dtypes.int32 and type_spec.shape.rank < 2):
+ if (type_spec.dtype == dtypes.int32 and type_spec.shape.rank is not None
+ and type_spec.shape.rank < 2):
# If this tensor might be representing shape information,
# (dtype=int32, rank of 0 or 1, not too large to represent a shape)
# we attempt to capture any value information tensorflow's