Check if layer has _metrics_lock attribute
@@ -1561,6 +1561,8 @@ class Layer(tf.Module, version_utils.LayerVersionSelector):
"""
collected_metrics = []
for layer in self._flatten_layers():
+ if not hasattr(layer, '_metrics_lock'):
+ continue
with layer._metrics_lock:
collected_metrics.extend(layer._metrics)
return collected_metrics
