Fix prediction with structured output
@@ -1851,9 +1851,10 @@ class Model(base_layer.Layer, version_utils.ModelVersionSelector):
outputs = step_function(self, iterator)
for _ in tf.range(self._steps_per_execution - 1):
tf.autograph.experimental.set_loop_options(
- shape_invariants=[(
- t, tf_utils.get_tensor_spec(t, dynamic_batch=True).shape)
- for t in tf.nest.flatten(outputs)])
+ shape_invariants=[(outputs, tf.nest.map_structure(
+ lambda t: tf_utils.get_tensor_spec(
+ t, dynamic_batch=True).shape,
+ outputs))])
step_outputs = step_function(self, iterator)
outputs = tf.nest.map_structure(lambda t1, t2: concat([t1, t2]),
outputs, step_outputs)
