Beispiel #1
0
    def setup_losses_and_metrics(self):
        def selectL(loss):
            if type(loss) is dict:
                loss = {k: selectLoss(v) for k, v in loss.items()}
            else:
                loss = selectLoss(loss)
            return loss

        self.loss_metrics = selectL(self.config[a.loss_metric])
        self.loss_weights = self.config.get("loss_weights")
        self.class_weights = self.config.get("class_weights")

        if self.loss_weights is None and type(self.loss_metrics) is dict:
            self.loss_weights = [1.0 for _ in range(len(self.loss_metrics))]

        if type(self.config[a.metrics]) is list:
            self.metrics_name = [
                selectMetric(m) for m in self.config[a.metrics]
            ]
        else:

            def selectM(metric):
                if type(metric) is list:
                    return [selectMetric(m_i) for m_i in metric]
                else:
                    return selectMetric(metric)

            self.metrics_name = {
                n: selectM(m)
                for n, m in self.config[a.metrics].items()
            }
Beispiel #2
0
def apply_metric(metric_name, y_true, y_pred) -> float:
    """Perform the computation of provided metric.

    :meta private:

    Args:
        metric_name (str|callable): If ``str`` then it needs to be a metric available in ``deephyper.nas.metrics``.
        y_true (array): Array of true predictions.
        y_pred (array): Array of predicted predictions

    Returns:
        float: a scalar value of the computed metric.
    """
    metric_func = selectMetric(metric_name)
    metric = tf.reduce_mean(
        metric_func(
            tf.convert_to_tensor(y_true, dtype=np.float32),
            tf.convert_to_tensor(y_pred, dtype=np.float32),
        )).numpy()
    return metric
Beispiel #3
0
 def selectM(metric):
     if type(metric) is list:
         return [selectMetric(m_i) for m_i in metric]
     else:
         return selectMetric(metric)