Esempio n. 1
0
    def __init__(self, root, train=True, test=True, transform=None):
        # Data loading code

        std_value = 1.0 / 255.0
        mean_values = [104 / 255.0, 117 / 255.0, 128 / 255.0]

        if transform is None:
            transform = [
                transforms.Compose([
                    transforms.CovertBGR(),
                    transforms.Resize(256),
                    transforms.RandomResizedCrop(227),
                    transforms.RandomHorizontalFlip(),
                    transforms.ToTensor(),
                    transforms.Normalize(mean=mean_values,
                                         std=3 * [std_value]),
                ]),
                transforms.Compose([
                    transforms.CovertBGR(),
                    transforms.Resize(256),
                    transforms.CenterCrop(227),
                    transforms.ToTensor(),
                    transforms.Normalize(mean=mean_values,
                                         std=3 * [std_value]),
                ])
            ]
        if root is None:
            root = 'DataSet/Products'

        traindir = os.path.join(root, 'train')
        testdir = os.path.join(root, 'test')
        if train:
            self.train = datasets.ImageFolder(traindir, transform[0])
        if test:
            self.test = datasets.ImageFolder(testdir, transform[1])
Esempio n. 2
0
    def __init__(self, root, train=True, test=True, transform=None):
        # Data loading code
        mean_values = [0.485, 0.456, 0.406]
        std_values = [0.229, 0.224, 0.225]

        if transform is None:
            transform = [
                transforms.Compose([
                    # transforms.CovertBGR(),
                    transforms.Resize(256),
                    transforms.RandomResizedCrop(224),
                    transforms.RandomHorizontalFlip(),
                    transforms.ToTensor(),
                    transforms.Normalize(mean=mean_values, std=std_values),
                ]),
                transforms.Compose([
                    # transforms.CovertBGR(),
                    transforms.Resize(256),
                    transforms.CenterCrop(224),
                    transforms.ToTensor(),
                    transforms.Normalize(mean=mean_values, std=std_values),
                ])
            ]
        if root is None:
            root = 'DataSet/Products'

        traindir = os.path.join(root, 'train')
        testdir = os.path.join(root, 'test')
        if train:
            self.train = datasets.ImageFolder(traindir, transform[0])
        if test:
            self.test = datasets.ImageFolder(testdir, transform[1])
Esempio n. 3
0
def Generate_transform_Dict(origin_width=256, width=227, ratio=0.16):
    
    std_value = 1.0 / 255.0
    normalize = transforms.Normalize(mean=[104 / 255.0, 117 / 255.0, 128 / 255.0],
                                     std= [1.0/255, 1.0/255, 1.0/255])

    transform_dict = {}

    transform_dict['rand-crop'] = \
    transforms.Compose([
                transforms.CovertBGR(),
                transforms.Resize((origin_width)),
                transforms.RandomResizedCrop(scale=(ratio, 1), size=width),
                transforms.RandomHorizontalFlip(),
                transforms.ToTensor(),
                normalize,
               ])

    transform_dict['center-crop'] = \
    transforms.Compose([
                    transforms.CovertBGR(),
                    transforms.Resize((origin_width)),
                    transforms.CenterCrop(width),
                    transforms.ToTensor(),
                    normalize,
                ])
    
    transform_dict['resize'] = \
    transforms.Compose([
                    transforms.CovertBGR(),
                    transforms.Resize((width)),
                    transforms.ToTensor(),
                    normalize,
                ])
    return transform_dict
Esempio n. 4
0
    def __init__(self, root, train=True, test=True, transform=None):
        # Data loading code

        # std_values = [0.229, 0.224, 0.225]
        # mean_values = [104 / 255.0, 117 / 255.0, 128 / 255.0]
        normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406],
                                         std=[0.229, 0.224, 0.225])

        if transform is None:
            transform = [transforms.Compose([
                # transforms.CovertBGR(),
                transforms.Resize(256),
                transforms.RandomResizedCrop(scale=(0.16, 1), size=224),
                transforms.RandomHorizontalFlip(),
                transforms.ToTensor(),
                normalize,
            ]),
                transforms.Compose([
                    # transforms.CovertBGR(),
                    transforms.Resize(256),
                    transforms.CenterCrop(224),
                    transforms.ToTensor(),
                    normalize,
                ])]

        if root is None:
            root = '/opt/intern/users/xunwang/DataSet//Products'

        traindir = os.path.join(root, 'train')
        testdir = os.path.join(root, 'test')
        if train:
            self.train = datasets.ImageFolder(traindir, transform[0])
        if test:
            self.test = datasets.ImageFolder(testdir, transform[1])
Esempio n. 5
0
def Generate_transform_Dict(origin_width=256,
                            width=227,
                            ratio=0.16,
                            RAE='None'):

    std_value = 1.0 / 255.0
    normalize = transforms.Normalize(
        mean=[104 / 255.0, 117 / 255.0, 128 / 255.0],
        std=[1.0 / 255, 1.0 / 255, 1.0 / 255])

    transform_dict = {}

    if RAE == 'None':
        print("No RAE")
        transform_dict['rand-crop'] = \
        transforms.Compose([
                transforms.CovertBGR(),
                transforms.Resize((origin_width)),
                transforms.RandomResizedCrop(scale=(ratio, 1), size=width),
                transforms.RandomHorizontalFlip(),
                transforms.ToTensor(),
                normalize,
               ])

    else:
        print("RAE with", RAE, "mode")
        transform_dict['rand-crop'] = \
        transforms.Compose([
                transforms.CovertBGR(),
                transforms.Resize((origin_width)),
                transforms.RandomResizedCrop(scale=(ratio, 1), size=width),
                transforms.RandomHorizontalFlip(),
                transforms.ToTensor(),
                normalize,
                transforms.RandomErasing(mode=RAE, device='cpu')
               ])




    transform_dict['center-crop'] = \
    transforms.Compose([
                    transforms.CovertBGR(),
                    transforms.Resize((origin_width)),
                    transforms.CenterCrop(width),
                    transforms.ToTensor(),
                    normalize,
                ])

    transform_dict['resize'] = \
    transforms.Compose([
                    transforms.CovertBGR(),
                    transforms.Resize((width)),
                    transforms.ToTensor(),
                    normalize,
                ])
    return transform_dict