src/vision/data_process.py
def loadImageNet(root='../..', split='train'):
    """
    Loads and preprocesses the ImageNet dataset.
    Params:
        - root (str): root directory where the data directory is located.
        - split (str): takes values 'train' and 'val'.
    """
    data_path = os.path.join(root, 'data/ImageNet')
    if split == 'train':
        transform = T.Compose([
            T.RandomResizedCrop(224),
            T.RandomHorizontalFlip(),
            T.ToTensor(),
            T.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
        ])
        train = True
    elif split == 'val':
        transform = T.Compose([
            T.Resize(256),
            T.CenterCrop(224),
            T.ToTensor(),
            T.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
        ])
        train = False
    else:
        msg = f"Split must be train or val, not {split}."
        raise RuntimeError(msg)

    data_path = os.path.join(data_path, split)
    dataset = datasets.ImageFolder(data_path, transform=transform)
    print(f"Loaded ImageNet {split} set from {data_path}")
    return dataset

    Loads and preprocesses the ImageNet dataset.
    Params:
        - root (str): root directory where the data directory is located.
        - split (str): takes values 'train' and 'val'.
    
Loads and preprocesses the ImageNet dataset.
Loads and preprocesses the ImageNet dataset .
def loadImageNet(root='../..', split='train'):
    data_path = os.path.join(root, 'data/ImageNet')
    if split == 'train':
        transform = T.Compose([
            T.RandomResizedCrop(224),
            T.RandomHorizontalFlip(),
            T.ToTensor(),
            T.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
        ])
        train = True
    elif split == 'val':
        transform = T.Compose([
            T.Resize(256),
            T.CenterCrop(224),
            T.ToTensor(),
            T.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
        ])
        train = False
    else:
        msg = f"Split must be train or val, not {split}."
        raise RuntimeError(msg)
    data_path = os.path.join(data_path, split)
    dataset = datasets.ImageFolder(data_path, transform=transform)
    print(f"Loaded ImageNet {split} set from {data_path}")
    return dataset
def loadImageNet ( root = '../..' , split = 'train' ) : data_path = os . path . join ( root , 'data/ImageNet' ) if split == 'train' : transform = T . Compose ( [ T . RandomResizedCrop ( 224 ) , T . RandomHorizontalFlip ( ) , T . ToTensor ( ) , T . Normalize ( mean = [ 0.485 , 0.456 , 0.406 ] , std = [ 0.229 , 0.224 , 0.225 ] ) , ] ) train = True elif split == 'val' : transform = T . Compose ( [ T . Resize ( 256 ) , T . CenterCrop ( 224 ) , T . ToTensor ( ) , T . Normalize ( mean = [ 0.485 , 0.456 , 0.406 ] , std = [ 0.229 , 0.224 , 0.225 ] ) , ] ) train = False else : msg = f"Split must be train or val, not {split}." raise RuntimeError ( msg ) data_path = os . path . join ( data_path , split ) dataset = datasets . ImageFolder ( data_path , transform = transform ) print ( f"Loaded ImageNet {split} set from {data_path}" ) return dataset
Loads and preprocesses the ImageNet dataset.
Loads and preprocesses the ImageNet dataset .
"""
    Loads and preprocesses the ImageNet dataset.
    Params:
        - root (str): root directory where the data directory is located.
        - split (str): takes values 'train' and 'val'.
    """
root
split
- root
root directory where the data directory is located.
root directory where the data directory is located .
- split
takes values 'train' and 'val'.
takes values ' train ' and ' val ' .