Check for _metrics in case sublayer is resetting _metrics property.

PiperOrigin-RevId: 311767501
Change-Id: I1f97904314a0f1912c918b89f461edd1183f4604
This commit is contained in:
Pavithra Vijay 2020-05-15 11:20:09 -07:00 committed by TensorFlower Gardener
parent 77245d07d1
commit ff17316b19
2 changed files with 2 additions and 2 deletions

View File

@ -2588,7 +2588,7 @@ class Layer(module.Module, version_utils.LayerVersionSelector):
# Keep track of metric instance created in subclassed layer.
from tensorflow.python.keras import metrics as metrics_module # pylint: disable=g-import-not-at-top
for val in nest.flatten(value):
if isinstance(val, metrics_module.Metric):
if isinstance(val, metrics_module.Metric) and hasattr(self, '_metrics'):
self._metrics.append(val)
# TODO(scottzhu): Need to track Module object as well for weight tracking.

View File

@ -2226,7 +2226,7 @@ class Layer(base_layer.Layer):
# Keep track of metric instance created in subclassed layer.
from tensorflow.python.keras import metrics as metrics_module # pylint: disable=g-import-not-at-top
for val in nest.flatten(value):
if isinstance(val, metrics_module.Metric):
if isinstance(val, metrics_module.Metric) and hasattr(self, '_metrics'):
self._metrics.append(val)
# TODO(scottzhu): Need to track Module object as well for weight tracking.