Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/keras/src/saving/legacy/saved_model/metric_serialization.py: 59%
17 statements
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-03 07:57 +0000
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-03 07:57 +0000
1# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14# ==============================================================================
15"""Classes and functions implementing Metrics SavedModel serialization."""
17import tensorflow.compat.v2 as tf
19from keras.src.saving import object_registration
20from keras.src.saving.legacy.saved_model import constants
21from keras.src.saving.legacy.saved_model import layer_serialization
24class MetricSavedModelSaver(layer_serialization.LayerSavedModelSaver):
25 """Metric serialization."""
27 @property
28 def object_identifier(self):
29 return constants.METRIC_IDENTIFIER
31 def _python_properties_internal(self):
32 metadata = dict(
33 class_name=object_registration.get_registered_name(type(self.obj)),
34 name=self.obj.name,
35 dtype=self.obj.dtype,
36 )
37 metadata.update(layer_serialization.get_serialized(self.obj))
38 if self.obj._build_input_shape is not None:
39 metadata["build_input_shape"] = self.obj._build_input_shape
40 return metadata
42 def _get_serialized_attributes_internal(self, unused_serialization_cache):
43 return (
44 dict(variables=tf.__internal__.tracking.wrap(self.obj.variables)),
45 # TODO(b/135550038): save functions to enable saving custom metrics.
46 {},
47 )