tf-keras-skeleton.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:LIE 作者: EmbraceLife 项目源码 文件源码
def score(self, x, y, **kwargs):
            """Returns the mean accuracy on the given test data and labels.

            Arguments:
                x: array-like, shape `(n_samples, n_features)`
                    Test samples where n_samples in the number of samples
                    and n_features is the number of features.
                y: array-like, shape `(n_samples,)` or `(n_samples, n_outputs)`
                    True labels for x.
                **kwargs: dictionary arguments
                    Legal arguments are the arguments of `Sequential.evaluate`.

            Returns:
                score: float
                    Mean accuracy of predictions on X wrt. y.

            Raises:
                ValueError: If the underlying model isn't configured to
                    compute accuracy. You should pass `metrics=["accuracy"]` to
                    the `.compile()` method of the model.
            """
            y = np.searchsorted(self.classes_, y)
            kwargs = self.filter_sk_params(Sequential.evaluate, kwargs)

            loss_name = self.model.loss
            if hasattr(loss_name, '__name__'):
              loss_name = loss_name.__name__
            if loss_name == 'categorical_crossentropy' and len(y.shape) != 2:
              y = to_categorical(y)

            outputs = self.model.evaluate(x, y, **kwargs)
            if not isinstance(outputs, list):
              outputs = [outputs]
            for name, output in zip(self.model.metrics_names, outputs):
              if name == 'acc':
                return output
            raise ValueError('The model is not configured to compute accuracy. '
                             'You should pass `metrics=["accuracy"]` to '
                             'the `model.compile()` method.')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号