(self, value, aggregation=None, name=None)
| 1893 | self._metrics.append(metric_obj) |
| 1894 | |
| 1895 | def _symbolic_add_metric(self, value, aggregation=None, name=None): |
| 1896 | base_layer_utils.check_graph_consistency(value, method='add_metric') |
| 1897 | match = self._get_existing_metric(name) |
| 1898 | if aggregation is None: |
| 1899 | # Iterate over the metrics and check if the given metric exists already. |
| 1900 | # This can happen when a metric instance is created in subclassed model |
| 1901 | # layer `__init__` and we have tracked that instance already in |
| 1902 | # model.__setattr__. |
| 1903 | if match: |
| 1904 | result_tensor = value |
| 1905 | metric_obj = match |
| 1906 | elif hasattr(value, '_metric_obj'): |
| 1907 | # We track the instance using the metadata on the result tensor. |
| 1908 | result_tensor = value |
| 1909 | metric_obj = result_tensor._metric_obj |
| 1910 | self._metrics.append(metric_obj) |
| 1911 | else: |
| 1912 | raise ValueError( |
| 1913 | 'We do not support adding an aggregated metric result tensor that ' |
| 1914 | 'is not the output of a `tf.keras.metrics.Metric` metric instance. ' |
| 1915 | 'Without having access to the metric instance we cannot reset the ' |
| 1916 | 'state of a metric after every epoch during training. You can ' |
| 1917 | 'create a `tf.keras.metrics.Metric` instance and pass the result ' |
| 1918 | 'here or pass an un-aggregated result with `aggregation` parameter ' |
| 1919 | 'set as `mean`. For example: `self.add_metric(tf.reduce_sum(inputs)' |
| 1920 | ', name=\'mean_activation\', aggregation=\'mean\')`') |
| 1921 | else: |
| 1922 | # If a non-aggregated tensor is given as input (ie. `aggregation` is |
| 1923 | # explicitly set to `mean`), we wrap the tensor in `Mean` metric. |
| 1924 | if match: |
| 1925 | result_tensor = match(value) |
| 1926 | metric_obj = match |
| 1927 | else: |
| 1928 | metric_obj, result_tensor = base_layer_utils.create_mean_metric( |
| 1929 | value, name) |
| 1930 | self._metrics.append(metric_obj) |
| 1931 | |
| 1932 | def _handle_weight_regularization(self, name, variable, regularizer): |
| 1933 | """Create lambdas which compute regularization losses.""" |
no test coverage detected