Check for _metrics
in case sublayer is resetting _metrics
property.
PiperOrigin-RevId: 311767501 Change-Id: I1f97904314a0f1912c918b89f461edd1183f4604
This commit is contained in:
parent
77245d07d1
commit
ff17316b19
@ -2588,7 +2588,7 @@ class Layer(module.Module, version_utils.LayerVersionSelector):
|
|||||||
# Keep track of metric instance created in subclassed 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
|
from tensorflow.python.keras import metrics as metrics_module # pylint: disable=g-import-not-at-top
|
||||||
for val in nest.flatten(value):
|
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)
|
self._metrics.append(val)
|
||||||
|
|
||||||
# TODO(scottzhu): Need to track Module object as well for weight tracking.
|
# TODO(scottzhu): Need to track Module object as well for weight tracking.
|
||||||
|
@ -2226,7 +2226,7 @@ class Layer(base_layer.Layer):
|
|||||||
# Keep track of metric instance created in subclassed 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
|
from tensorflow.python.keras import metrics as metrics_module # pylint: disable=g-import-not-at-top
|
||||||
for val in nest.flatten(value):
|
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)
|
self._metrics.append(val)
|
||||||
|
|
||||||
# TODO(scottzhu): Need to track Module object as well for weight tracking.
|
# TODO(scottzhu): Need to track Module object as well for weight tracking.
|
||||||
|
Loading…
Reference in New Issue
Block a user