def process_data(train_data, valid_data, image_processor, config):
    """
    Processes training and validation data by applying image transformations.

    Args:
        train_data (Dataset): The training dataset.
        valid_data (Dataset or None): The validation dataset. If None, only training data is processed.
        image_processor (ImageProcessor): An object containing image processing parameters such as size, mean, and std.
        config (dict): Configuration dictionary containing additional parameters for the dataset.

    Returns:
        tuple: A tuple containing the processed training dataset and the processed validation dataset (or None if valid_data is None).
    """
    if "shortest_edge" in image_processor.size:
        size = image_processor.size["shortest_edge"]
    else:
        size = (image_processor.size["height"], image_processor.size["width"])
    try:
        height, width = size
    except TypeError:
        height = size
        width = size

    train_transforms = A.Compose(
        [
            A.RandomResizedCrop(height=height, width=width),
            A.RandomRotate90(),
            A.HorizontalFlip(p=0.5),
            A.RandomBrightnessContrast(p=0.2),
            A.Normalize(mean=image_processor.image_mean, std=image_processor.image_std),
        ]
    )

    val_transforms = A.Compose(
        [
            A.Resize(height=height, width=width),
            A.Normalize(mean=image_processor.image_mean, std=image_processor.image_std),
        ]
    )
    train_data = ImageRegressionDataset(train_data, train_transforms, config)
    if valid_data is not None:
        valid_data = ImageRegressionDataset(valid_data, val_transforms, config)
        return train_data, valid_data
    return train_data, None

    Processes training and validation data by applying image transformations.

    Args:
        train_data (Dataset): The training dataset.
        valid_data (Dataset or None): The validation dataset. If None, only training data is processed.
        image_processor (ImageProcessor): An object containing image processing parameters such as size, mean, and std.
        config (dict): Configuration dictionary containing additional parameters for the dataset.

    Returns:
        tuple: A tuple containing the processed training dataset and the processed validation dataset (or None if valid_data is None).
    
src/autotrain/trainers/image_regression/utils.py