def prepare_datasets(dataset: str, T_train: Callable, T_val: Callable, data_dir: Optional[Union[(str, Path)]]=None, train_dir: Optional[Union[(str, Path)]]=None, val_dir: Optional[Union[(str, Path)]]=None) -> Tuple[(Dataset, Dataset)]:
    'Prepares train and val datasets.\n\n    Args:\n        dataset (str): dataset name.\n        T_train (Callable): pipeline of transformations for training dataset.\n        T_val (Callable): pipeline of transformations for validation dataset.\n        data_dir Optional[Union[str, Path]]: path where to download/locate the dataset.\n        train_dir Optional[Union[str, Path]]: subpath where the training data is located.\n        val_dir Optional[Union[str, Path]]: subpath where the validation data is located.\n\n    Returns:\n        Tuple[Dataset, Dataset]: training dataset and validation dataset.\n    '
    if (data_dir is None):
        sandbox_dir = Path(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
        data_dir = (sandbox_dir / 'datasets')
    else:
        data_dir = Path(data_dir)
    if (train_dir is None):
        train_dir = Path(f'{dataset}/train')
    else:
        train_dir = Path(train_dir)
    if (val_dir is None):
        val_dir = Path(f'{dataset}/val')
    else:
        val_dir = Path(val_dir)
    assert (dataset in ['cifar10', 'cifar100', 'stl10', 'imagenet', 'imagenet100', 'custom'])
    if (dataset in ['cifar10', 'cifar100']):
        DatasetClass = vars(torchvision.datasets)[dataset.upper()]
        train_dataset = DatasetClass((data_dir / train_dir), train=True, download=True, transform=T_train)
        val_dataset = DatasetClass((data_dir / val_dir), train=False, download=True, transform=T_val)
    elif (dataset == 'stl10'):
        train_dataset = STL10((data_dir / train_dir), split='train', download=True, transform=T_train)
        val_dataset = STL10((data_dir / val_dir), split='test', download=True, transform=T_val)
    elif (dataset in ['imagenet', 'imagenet100', 'custom']):
        train_dir = (data_dir / train_dir)
        val_dir = (data_dir / val_dir)
        train_dataset = ImageFolder(train_dir, T_train)
        val_dataset = ImageFolder(val_dir, T_val)
    return (train_dataset, val_dataset)
Prepares train and val datasets.

Args:
    dataset (str): dataset name.
    T_train (Callable): pipeline of transformations for training dataset.
    T_val (Callable): pipeline of transformations for validation dataset.
    data_dir Optional[Union[str, Path]]: path where to download/locate the dataset.
    train_dir Optional[Union[str, Path]]: subpath where the training data is located.
    val_dir Optional[Union[str, Path]]: subpath where the validation data is located.

Returns:
    Tuple[Dataset, Dataset]: training dataset and validation dataset.
def prepare_datasets(dataset: str, T_train: Callable, T_val: Callable, data_dir: Optional[Union[(str, Path)]]=None, train_dir: Optional[Union[(str, Path)]]=None, val_dir: Optional[Union[(str, Path)]]=None) -> Tuple[(Dataset, Dataset)]:
    'Prepares train and val datasets.\n\n    Args:\n        dataset (str): dataset name.\n        T_train (Callable): pipeline of transformations for training dataset.\n        T_val (Callable): pipeline of transformations for validation dataset.\n        data_dir Optional[Union[str, Path]]: path where to download/locate the dataset.\n        train_dir Optional[Union[str, Path]]: subpath where the training data is located.\n        val_dir Optional[Union[str, Path]]: subpath where the validation data is located.\n\n    Returns:\n        Tuple[Dataset, Dataset]: training dataset and validation dataset.\n    '
    if (data_dir is None):
        sandbox_dir = Path(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
        data_dir = (sandbox_dir / 'datasets')
    else:
        data_dir = Path(data_dir)
    if (train_dir is None):
        train_dir = Path(f'{dataset}/train')
    else:
        train_dir = Path(train_dir)
    if (val_dir is None):
        val_dir = Path(f'{dataset}/val')
    else:
        val_dir = Path(val_dir)
    assert (dataset in ['cifar10', 'cifar100', 'stl10', 'imagenet', 'imagenet100', 'custom'])
    if (dataset in ['cifar10', 'cifar100']):
        DatasetClass = vars(torchvision.datasets)[dataset.upper()]
        train_dataset = DatasetClass((data_dir / train_dir), train=True, download=True, transform=T_train)
        val_dataset = DatasetClass((data_dir / val_dir), train=False, download=True, transform=T_val)
    elif (dataset == 'stl10'):
        train_dataset = STL10((data_dir / train_dir), split='train', download=True, transform=T_train)
        val_dataset = STL10((data_dir / val_dir), split='test', download=True, transform=T_val)
    elif (dataset in ['imagenet', 'imagenet100', 'custom']):
        train_dir = (data_dir / train_dir)
        val_dir = (data_dir / val_dir)
        train_dataset = ImageFolder(train_dir, T_train)
        val_dataset = ImageFolder(val_dir, T_val)
    return (train_dataset, val_dataset)