def image_regression_metrics(pred):
    """
    Calculate various regression metrics for image regression tasks.

    Args:
        pred (tuple): A tuple containing raw predictions and labels.
                      raw_predictions should be a list of lists or a list of numpy.float32 values.
                      labels should be a list of true values.

    Returns:
        dict: A dictionary containing the calculated metrics:
              - 'mse': Mean Squared Error
              - 'mae': Mean Absolute Error
              - 'r2': R^2 Score
              - 'rmse': Root Mean Squared Error
              - 'explained_variance': Explained Variance Score

              If an error occurs during the calculation of a metric, the value for that metric will be -999.
    """
    raw_predictions, labels = pred

    try:
        raw_predictions = [r for preds in raw_predictions for r in preds]
    except TypeError as err:
        if "numpy.float32" not in str(err):
            raise Exception(err)

    pred_dict = {}
    metrics_to_calculate = {
        "mse": metrics.mean_squared_error,
        "mae": metrics.mean_absolute_error,
        "r2": metrics.r2_score,
        "rmse": lambda y_true, y_pred: np.sqrt(metrics.mean_squared_error(y_true, y_pred)),
        "explained_variance": metrics.explained_variance_score,
    }

    for key, func in metrics_to_calculate.items():
        try:
            pred_dict[key] = float(func(labels, raw_predictions))
        except Exception:
            pred_dict[key] = -999

    return pred_dict

    Calculate various regression metrics for image regression tasks.

    Args:
        pred (tuple): A tuple containing raw predictions and labels.
                      raw_predictions should be a list of lists or a list of numpy.float32 values.
                      labels should be a list of true values.

    Returns:
        dict: A dictionary containing the calculated metrics:
              - 'mse': Mean Squared Error
              - 'mae': Mean Absolute Error
              - 'r2': R^2 Score
              - 'rmse': Root Mean Squared Error
              - 'explained_variance': Explained Variance Score

              If an error occurs during the calculation of a metric, the value for that metric will be -999.
    
src/autotrain/trainers/image_regression/utils.py