コード例 #1
0
    def __init__(self):
        train_transform = transforms.Compose([
            transforms.Resize((384, 128), interpolation=3),
            transforms.RandomHorizontalFlip(),
            transforms.ToTensor(),
            transforms.Normalize(mean=[0.485, 0.456, 0.406],
                                 std=[0.229, 0.224, 0.225]),
            RandomErasing(probability=0.5, mean=[0.0, 0.0, 0.0])
        ])
        train_transform_woEr = transforms.Compose([
            transforms.Resize((384, 128), interpolation=3),
            transforms.RandomHorizontalFlip(),
            transforms.ToTensor(),
            transforms.Normalize(mean=[0.485, 0.456, 0.406],
                                 std=[0.229, 0.224, 0.225])
        ])

        test_transform = transforms.Compose([
            transforms.Resize((384, 128), interpolation=3),
            transforms.ToTensor(),
            transforms.Normalize(mean=[0.485, 0.456, 0.406],
                                 std=[0.229, 0.224, 0.225])
        ])

        self.trainset = Market1501(train_transform, 'train', opt.data_path)
        self.trainset_woEr = Market1501(train_transform_woEr, 'train',
                                        opt.data_path)
        self.testset = Market1501(test_transform, 'test', opt.data_path)
        self.queryset = Market1501(test_transform, 'query', opt.data_path)

        self.train_loader = dataloader.DataLoader(
            self.trainset,
            sampler=RandomSampler(self.trainset,
                                  batch_id=opt.batchid,
                                  batch_image=opt.batchimage),
            batch_size=opt.batchid * opt.batchimage,
            num_workers=8,
            pin_memory=True)

        self.train_loader_woEr = dataloader.DataLoader(
            self.trainset_woEr,
            sampler=RandomSampler(self.trainset_woEr,
                                  batch_id=opt.batchid,
                                  batch_image=opt.batchimage),
            batch_size=opt.batchid * opt.batchimage,
            num_workers=8,
            pin_memory=True)

        self.test_loader = dataloader.DataLoader(self.testset,
                                                 batch_size=opt.batchtest,
                                                 num_workers=8,
                                                 pin_memory=True)
        self.query_loader = dataloader.DataLoader(self.queryset,
                                                  batch_size=opt.batchtest,
                                                  num_workers=8,
                                                  pin_memory=True)
コード例 #2
0
    def __init__(self):
        # paper is (384, 128)
        train_transform = transforms.Compose([
            transforms.Resize((256, 256), interpolation=3),
            transforms.RandomHorizontalFlip(),
            transforms.ToTensor(),
            transforms.Normalize(mean=[0.485, 0.456, 0.406],
                                 std=[0.229, 0.224, 0.225]),
            RandomErasing(probability=0.5, mean=[0.0, 0.0, 0.0])
        ])
        test_transform = transforms.Compose([
            transforms.Resize((256, 256), interpolation=3),
            transforms.ToTensor(),
            transforms.Normalize(mean=[0.485, 0.456, 0.406],
                                 std=[0.229, 0.224, 0.225])
        ])

        self.trainset = Car(transforms=train_transform, root=opt.data_path)
        self.testset = Car(transforms=test_transform, root=opt.data_path)
        self.train_loader = dataloader.DataLoader(
            self.trainset,
            sampler=RandomSampler(self.trainset,
                                  batch_id=opt.batchid,
                                  batch_image=opt.batchimage),
            batch_size=opt.batchid * opt.batchimage,
            num_workers=8,
            pin_memory=True)
        self.test_loader = dataloader.DataLoader(self.testset,
                                                 batch_size=opt.batchtest,
                                                 num_workers=1,
                                                 pin_memory=True)
コード例 #3
0
    def __init__(self,
                 data="veri",
                 size=(288, 288),
                 sampler="triple",
                 mean=[0.485, 0.456, 0.406],
                 std=[0.229, 0.224, 0.225]):
        train_transform = transforms.Compose([
            transforms.Resize(size, interpolation=3),
            transforms.RandomHorizontalFlip(),
            transforms.ToTensor(),
            transforms.Normalize(mean=mean, std=std),
            RandomErasing(probability=0.5, mean=mean)
        ])

        test_transform = transforms.Compose([
            transforms.Resize(size, interpolation=3),
            transforms.ToTensor(),
            transforms.Normalize(mean=mean, std=std)
        ])
        Dataset = {
            'veri': VeRi,
            "vehicleid": VehicleID,
            'market': Market1501,
            'msmt': MSMT17
        }

        self.trainset = Dataset[data](train_transform, 'train', opt.data_path)
        self.testset = Dataset[data](test_transform, 'test', opt.data_path)
        self.queryset = Dataset[data](test_transform, 'query', opt.data_path)
        self.nums = self.trainset.len

        if sampler == None:
            self.train_loader = dataloader.DataLoader(self.trainset,
                                                      batch_size=opt.batchsize,
                                                      shuffle=True,
                                                      num_workers=4,
                                                      pin_memory=True)
        elif sampler == "triple":
            self.train_loader = dataloader.DataLoader(
                self.trainset,
                sampler=RandomSampler(self.trainset,
                                      batch_id=opt.batchid,
                                      batch_image=opt.batchimage),
                batch_size=opt.batchid * opt.batchimage,
                num_workers=4,
                pin_memory=True)
        self.test_loader = dataloader.DataLoader(self.testset,
                                                 batch_size=opt.batchtest,
                                                 shuffle=False,
                                                 num_workers=4,
                                                 pin_memory=True)
        self.query_loader = dataloader.DataLoader(self.queryset,
                                                  batch_size=opt.batchtest,
                                                  shuffle=False,
                                                  num_workers=4,
                                                  pin_memory=True)
コード例 #4
0
ファイル: data.py プロジェクト: hanhsienhuang/ML_project
    def __init__(self):
        transform_list = [
            transforms.Resize((384, 128), interpolation=3),
            transforms.RandomHorizontalFlip(),
            transforms.ToTensor(),
            transforms.Normalize(mean=[0.485, 0.456, 0.406],
                                 std=[0.229, 0.224, 0.225]),
        ]
        if opt.random_erasing:
            transform_list.append(
                RandomErasing(probability=0.5, mean=[0.0, 0.0, 0.0]))
        train_transform = transforms.Compose(transform_list)

        test_transform = transforms.Compose([
            transforms.Resize((384, 128), interpolation=3),
            transforms.ToTensor(),
            transforms.Normalize(mean=[0.485, 0.456, 0.406],
                                 std=[0.229, 0.224, 0.225])
        ])

        self.trainset = Market1501(train_transform, 'train', opt.data_path,
                                   opt.augment)
        self.testset = Market1501(test_transform, 'test', opt.data_path)
        self.queryset = Market1501(test_transform, 'query', opt.data_path)

        self.train_loader = dataloader.DataLoader(
            self.trainset,
            sampler=RandomSampler(self.trainset,
                                  batch_id=opt.batchid,
                                  batch_image=opt.batchimage),
            batch_size=opt.batchid * opt.batchimage,
            num_workers=8,
            pin_memory=True)
        self.test_loader = dataloader.DataLoader(self.testset,
                                                 batch_size=opt.batchtest,
                                                 num_workers=8,
                                                 pin_memory=True)
        self.query_loader = dataloader.DataLoader(self.queryset,
                                                  batch_size=opt.batchtest,
                                                  num_workers=8,
                                                  pin_memory=True)

        if opt.mode == 'vis':
            self.query_image = test_transform(default_loader(opt.query_image))
コード例 #5
0
    def __init__(self):
        train_transform = transforms.Compose([
            transforms.Resize((128, 288), interpolation=3),
            transforms.RandomHorizontalFlip(),
            transforms.ColorJitter(),
            transforms.ToTensor(),
            transforms.Normalize(mean=[0.485, 0.456, 0.406],
                                 std=[0.229, 0.224, 0.225]),
            RandomErasing(probability=0.5, mean=[0.0, 0.0, 0.0])
        ])

        test_transform = transforms.Compose([
            transforms.Resize((128, 288), interpolation=3),
            transforms.ToTensor(),
            transforms.Normalize(mean=[0.485, 0.456, 0.406],
                                 std=[0.229, 0.224, 0.225])
        ])

        self.trainset = CVWC(train_transform, 'train', opt.data_path)
        self.testset = CVWC(test_transform, 'test', opt.data_path)
        self.queryset = CVWC(test_transform, 'query', opt.data_path)

        self.train_loader = dataloader.DataLoader(
            self.trainset,
            sampler=RandomSampler(self.trainset,
                                  batch_id=opt.batchid,
                                  batch_image=opt.batchimage),
            batch_size=opt.batchid * opt.batchimage,
            num_workers=24,
            pin_memory=True,
            drop_last=True)
        self.test_loader = dataloader.DataLoader(self.testset,
                                                 batch_size=opt.batchtest,
                                                 num_workers=24,
                                                 pin_memory=True)
        self.query_loader = dataloader.DataLoader(self.queryset,
                                                  batch_size=opt.batchtest,
                                                  num_workers=24,
                                                  pin_memory=True)

        if opt.mode == 'vis':
            self.query_image = test_transform(default_loader(opt.query_image))
コード例 #6
0
ファイル: data_al.py プロジェクト: 11610309GZL/MGN-AL
    def __init__(self):
        train_transform = transforms.Compose([
            transforms.Resize((384, 128), interpolation=3),
            transforms.RandomHorizontalFlip(),
            transforms.ToTensor(),
            transforms.Normalize(mean=[0.485, 0.456, 0.406],
                                 std=[0.229, 0.224, 0.225]),
            RandomErasing(probability=0.5, mean=[0.0, 0.0, 0.0])
        ])

        test_transform = transforms.Compose([
            transforms.Resize((384, 128), interpolation=3),
            transforms.ToTensor(),
            transforms.Normalize(mean=[0.485, 0.456, 0.406],
                                 std=[0.229, 0.224, 0.225])
        ])

        # self.trainset = Market1501(train_transform, 'train', opt.data_path)

        # 分割训练集

        train_set_path = get_path(opt.data_path, 'train')

        self.all_imgs_path = get_all_imgs_path(train_set_path)

        self.unique_ids = get_unique_ids(self.all_imgs_path)

        self.labeled_path, self.unlabeled_path = divide_trainset(
            self.unique_ids, self.all_imgs_path)

        self.trainset = AlMarket1501(train_transform, self.labeled_path,
                                     self.unique_ids)
        self.unlabeledset = AlMarket1501(train_transform, self.unlabeled_path,
                                         self.unique_ids)
        self.testset = Market1501(test_transform, 'test', opt.data_path)
        self.queryset = Market1501(test_transform, 'query', opt.data_path)

        self.train_loader = dataloader.DataLoader(
            self.trainset,
            sampler=RandomSampler(self.trainset,
                                  batch_id=opt.batchid,
                                  batch_image=opt.batchimage),
            batch_size=opt.batchid * opt.batchimage,
            num_workers=8,
            pin_memory=True)

        self.unlabeled_loader = dataloader.DataLoader(self.unlabeledset,
                                                      batch_size=opt.batchtest,
                                                      num_workers=8,
                                                      pin_memory=True)

        self.test_loader = dataloader.DataLoader(self.testset,
                                                 batch_size=opt.batchtest,
                                                 num_workers=8,
                                                 pin_memory=True)
        self.query_loader = dataloader.DataLoader(self.queryset,
                                                  batch_size=opt.batchtest,
                                                  num_workers=8,
                                                  pin_memory=True)

        if opt.mode == 'vis':
            self.query_image = test_transform(default_loader(opt.query_image))
コード例 #7
0
ファイル: data.py プロジェクト: Pantheona/ISGANWithPRCC
    def __init__(self, test=None):
        rgb_transform = transforms.Compose(
            [transforms.Resize((384, 128), interpolation=3)])
        gray_transform = transforms.Compose([
            transforms.Resize((384, 128), interpolation=3),
            transforms.Grayscale(3)
        ])
        test_transform = transforms.Compose([
            transforms.Resize((384, 128), interpolation=3),
            transforms.ToTensor(),
            transforms.Normalize(mean=[0.485, 0.456, 0.406],
                                 std=[0.229, 0.224, 0.225])
        ])
        process_transform = transforms.Compose([
            transforms.RandomHorizontalFlip(),
            transforms.ToTensor(),
            transforms.Normalize(mean=[0.485, 0.456, 0.406],
                                 std=[0.229, 0.224, 0.225]),
            RandomErasing(probability=0.5, mean=[0.0, 0.0, 0.0])
        ])
        woEr_process_transform = transforms.Compose([
            transforms.RandomHorizontalFlip(),
            transforms.ToTensor(),
            transforms.Normalize(mean=[0.485, 0.456, 0.406],
                                 std=[0.229, 0.224, 0.225])
        ])

        self.trainset = Market1501(data_path=opt.data_path,
                                   dtype="train",
                                   rgb_trans=rgb_transform,
                                   gray_trans=gray_transform,
                                   process_trans=process_transform)
        self.trainset_woEr = Market1501(data_path=opt.data_path,
                                        dtype="train",
                                        rgb_trans=rgb_transform,
                                        gray_trans=gray_transform,
                                        process_trans=woEr_process_transform)
        if test is None:
            self.testset = Market1501(data_path=opt.data_path,
                                      dtype="test",
                                      test_trans=test_transform)
        else:
            self.testset = Market1501(data_path=opt.data_path + '/' +
                                      str(test),
                                      dtype="test",
                                      test_trans=test_transform)
        self.queryset = Market1501(data_path=opt.data_path,
                                   dtype="query",
                                   test_trans=test_transform)

        self.train_loader = dataloader.DataLoader(
            self.trainset,
            sampler=RandomSampler(self.trainset,
                                  batch_id=opt.batchid,
                                  batch_image=opt.batchimage),
            batch_size=opt.batchid * opt.batchimage,
            num_workers=0,
            pin_memory=True)  # 8
        self.train_loader_woEr = dataloader.DataLoader(
            self.trainset_woEr,
            sampler=RandomSampler(self.trainset_woEr,
                                  batch_id=opt.batchid,
                                  batch_image=opt.batchimage),
            batch_size=opt.batchid * opt.batchimage,
            num_workers=0,
            pin_memory=True)  # 8

        self.test_loader = dataloader.DataLoader(self.testset,
                                                 batch_size=opt.batchtest,
                                                 num_workers=0,
                                                 pin_memory=True)  # 8
        self.query_loader = dataloader.DataLoader(self.queryset,
                                                  batch_size=opt.batchtest,
                                                  num_workers=0,
                                                  pin_memory=True)  # 8
コード例 #8
0
ファイル: data.py プロジェクト: stephng3/ReID-MGN
    def __init__(self,
                 rand_erasing=True,
                 dataset='Market1501',
                 data_path='./datasets/market_1501',
                 batchid=16,
                 batchimage=4,
                 batchtest=16,
                 num_workers=0,
                 query_image=None,
                 mode='train',
                 input_height=384,
                 input_width=128,
                 **kwargs):
        train_transforms = [
            transforms.Resize((input_height, input_width), interpolation=3),
            transforms.RandomHorizontalFlip(),
            transforms.ToTensor(),
            transforms.Normalize(mean=[0.485, 0.456, 0.406],
                                 std=[0.229, 0.224, 0.225]),
        ]
        if rand_erasing:
            train_transforms.append(
                RandomErasing(probability=0.5, mean=[0.0, 0.0, 0.0]))
        train_transform = transforms.Compose(train_transforms)

        test_transform = transforms.Compose([
            transforms.Resize((input_height, input_width), interpolation=3),
            transforms.ToTensor(),
            transforms.Normalize(mean=[0.485, 0.456, 0.406],
                                 std=[0.229, 0.224, 0.225])
        ])

        if dataset == 'Market1501':
            self.trainset = Market1501(train_transform, 'train', data_path)
            self.testset = Market1501(test_transform, 'test', data_path)
            self.queryset = Market1501(test_transform, 'query', data_path)
        elif dataset == 'DeepFashion':
            self.trainset = DeepFashion(train_transform, 'train', data_path)
            self.testset = DeepFashion(test_transform, 'test', data_path)
            self.queryset = DeepFashion(test_transform, 'query', data_path)
        else:
            raise Exception('Dataset not implemented: %s' % dataset)

        self.train_loader = dataloader.DataLoader(
            self.trainset,
            sampler=RandomSampler(self.trainset,
                                  batch_id=batchid,
                                  batch_image=batchimage),
            batch_size=batchid * batchimage,
            num_workers=num_workers,
            pin_memory=True)
        self.test_loader = dataloader.DataLoader(self.testset,
                                                 batch_size=batchtest,
                                                 num_workers=num_workers,
                                                 pin_memory=True)
        self.query_loader = dataloader.DataLoader(self.queryset,
                                                  batch_size=batchtest,
                                                  num_workers=num_workers,
                                                  pin_memory=True)

        if mode == 'vis':
            self.query_image = test_transform(default_loader(query_image))