Exemple #1
0
    def __init__(self, dataset, name, root=None, with_pose=False, pose_root=None, is_test=False, test_root = None,
                 pid_imgs=None, height=256, width=128, pose_aug='no', transform=None):
        super(Preprocessor, self).__init__()
        self.dataset = dataset
        self.root = root
        self.with_pose = with_pose
        self.pose_root = pose_root
        self.is_test = is_test
        self.test_root = test_root
        self.pid_imgs = pid_imgs
        self.height = height
        self.width = width
        self.pose_aug = pose_aug
        self.name = name

        normalizer = transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
        if transform==None:
            self.transform = transforms.Compose([
                                 transforms.RectScale(height, width),
                                 transforms.RandomSizedEarser(),
                                 #transforms.RandomHorizontalFlip(),
                                 transforms.ToTensor(),
                                 normalizer,
                             ])
        else:
            self.transform = transform
        self.transform_p = transforms.Compose([
                                 transforms.RectScale(height, width),
                                 transforms.ToTensor(),
                                 normalizer,
                             ])
Exemple #2
0
def get_data(name, data_dir, height, width, batch_size, workers, pose_aug,
             skip, rate, eraser):
    root = osp.join(data_dir, name)
    dataset = datasets.create(name, root)
    video_dict = None
    if osp.isfile(osp.join(root, 'video.json')):
        video_dict = read_json(osp.join(root, 'video.json'))

    if eraser:
        train_transformer = T.Compose([
            T.RectScale(height, width),
            T.RandomSizedEarser(),
            T.ToTensor(),
            T.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
        ])
    else:
        train_transformer = T.Compose([
            T.RectScale(height, width),
            T.ToTensor(),
            T.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
        ])

    # use combined trainval set for training as default
    train_loader = DataLoader(Preprocessor(dataset.trainval,
                                           name,
                                           root=dataset.images_dir,
                                           with_pose=True,
                                           pose_root=dataset.poses_dir,
                                           pid_imgs=dataset.trainval_query,
                                           height=height,
                                           width=width,
                                           pose_aug=pose_aug,
                                           transform=train_transformer),
                              sampler=RandomTripletSampler(
                                  dataset.trainval,
                                  video_dict=video_dict,
                                  skip_frames=skip,
                                  inter_rate=rate),
                              batch_size=batch_size,
                              num_workers=workers,
                              pin_memory=False)

    test_transformer = T.Compose([
        T.RectScale(height, width),
        T.ToTensor(),
        T.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
    ])

    test_loader = DataLoader(Preprocessor(
        list(set(dataset.query) | set(dataset.gallery)),
        name,
        root=dataset.images_dir,
        transform=test_transformer),
                             batch_size=batch_size,
                             num_workers=workers,
                             shuffle=False,
                             pin_memory=False)

    return dataset, train_loader, test_loader
Exemple #3
0
def get_data(name, split_id, data_dir, height, width, batch_size,
             num_instances, workers, combine_trainval):
    root = osp.join(data_dir, name)

    dataset = datasets.create(name, root, split_id=split_id)

    normalizer = T.Normalize(mean=[0.485, 0.456, 0.406],
                             std=[0.229, 0.224, 0.225])

    train_set = dataset.trainval if combine_trainval else dataset.train
    num_classes = (dataset.num_trainval_ids
                   if combine_trainval else dataset.num_train_ids)

    train_transformer = T.Compose([
        T.RectScale(height, width),
        T.RandomSizedEarser(),
        T.RandomHorizontalFlip(),
        T.ToTensor(),
        normalizer,
    ])

    test_transformer = T.Compose([
        T.RectScale(height, width),
        T.ToTensor(),
        normalizer,
    ])

    train_loader = DataLoader(Preprocessor(train_set,
                                           root=dataset.images_dir,
                                           transform=train_transformer),
                              batch_size=batch_size,
                              num_workers=workers,
                              sampler=RandomMultipleGallerySampler(
                                  train_set, num_instances),
                              pin_memory=True,
                              drop_last=True)

    val_loader = DataLoader(Preprocessor(dataset.val,
                                         root=dataset.images_dir,
                                         transform=test_transformer),
                            batch_size=batch_size,
                            num_workers=workers,
                            shuffle=False,
                            pin_memory=True)

    test_loader = DataLoader(Preprocessor(
        list(set(dataset.query) | set(dataset.gallery)),
        root=dataset.images_dir,
        transform=test_transformer),
                             batch_size=batch_size,
                             num_workers=workers,
                             shuffle=False,
                             pin_memory=True)

    return dataset, num_classes, train_loader, val_loader, test_loader
def get_data(name, split_id, data_dir, height, width, batch_size, workers,
             combine_trainval, np_ratio):
    root = osp.join(data_dir, name)

    dataset = datasets.create(name, root, split_id=split_id)

    normalizer = T.Normalize(mean=[0.485, 0.456, 0.406],
                             std=[0.229, 0.224, 0.225])

    train_set = dataset.trainval if combine_trainval else dataset.train

    train_transformer = T.Compose([
        T.RandomSizedRectCrop(height, width),
        T.RandomSizedEarser(),
        T.RandomHorizontalFlip(),
        T.ToTensor(),
        normalizer,
    ])

    test_transformer = T.Compose([
        T.RectScale(height, width),
        T.ToTensor(),
        normalizer,
    ])

    train_loader = DataLoader(Preprocessor(train_set,
                                           root=dataset.images_dir,
                                           transform=train_transformer),
                              sampler=RandomPairSampler(
                                  train_set, neg_pos_ratio=np_ratio),
                              batch_size=batch_size,
                              num_workers=workers,
                              pin_memory=False)

    val_loader = DataLoader(Preprocessor(dataset.val,
                                         root=dataset.images_dir,
                                         transform=test_transformer),
                            batch_size=batch_size,
                            num_workers=0,
                            shuffle=False,
                            pin_memory=False)

    test_loader = DataLoader(Preprocessor(
        list(set(dataset.query) | set(dataset.gallery)),
        root=dataset.images_dir,
        transform=test_transformer),
                             batch_size=batch_size,
                             num_workers=0,
                             shuffle=False,
                             pin_memory=False)

    return dataset, train_loader, val_loader, test_loader
Exemple #5
0
def get_data(name, split_id, data_dir, height, width, batch_size, workers,
             combine_trainval, np_ratio, model, instance_mode, eraser):
    root = osp.join(data_dir, name)

    dataset = datasets.create(name, root, split_id=split_id)

    normalizer = T.Normalize(mean=[0.485, 0.456, 0.406],
                             std=[0.229, 0.224, 0.225])

    train_set = dataset.trainval if combine_trainval else dataset.train

    if eraser:
        train_transformer = T.Compose([
            T.RandomSizedRectCrop(height, width),
            T.RandomSizedEarser(),
            T.RandomHorizontalFlip(),
            T.ToTensor(),
            normalizer,
        ])
    else:
        train_transformer = T.Compose([
            T.RandomSizedRectCrop(height, width),
            T.RandomHorizontalFlip(),
            T.ToTensor(),
            normalizer,
        ])

    test_transformer = T.Compose([
        T.RectScale(height, width),
        T.ToTensor(),
        normalizer,
    ])

    if (model == 'Single'):
        video_dict = None
        if osp.isfile(osp.join(root, 'video.json')):
            video_dict = read_json(osp.join(root, 'video.json'))
        sampler = RandomTripletSampler(train_set,
                                       video_dict=None,
                                       skip_frames=10,
                                       inter_rate=0.9,
                                       inst_sample=instance_mode)
    elif (model == 'Siamese'):
        sampler = RandomPairSampler(train_set, neg_pos_ratio=np_ratio)
    else:
        raise ValueError('unrecognized mode')

    train_loader = DataLoader(Preprocessor(train_set,
                                           name,
                                           root=dataset.images_dir,
                                           transform=train_transformer),
                              sampler=sampler,
                              batch_size=batch_size,
                              num_workers=workers,
                              pin_memory=False)

    val_loader = DataLoader(Preprocessor(dataset.val,
                                         name,
                                         root=dataset.images_dir,
                                         transform=test_transformer),
                            batch_size=batch_size,
                            num_workers=workers,
                            shuffle=False,
                            pin_memory=False)

    test_loader = DataLoader(Preprocessor(
        list(set(dataset.query) | set(dataset.gallery)),
        name,
        root=dataset.images_dir,
        transform=test_transformer),
                             batch_size=batch_size,
                             num_workers=workers,
                             shuffle=False,
                             pin_memory=False)

    return dataset, train_loader, val_loader, test_loader