Ejemplo n.º 1
0
def get_data(data_dir, source, target, height, width, batch_size, re=0, workers=8):

    dataset = DA(data_dir, source, target)

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

    num_classes = dataset.num_train_ids

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

    test_transformer = T.Compose([
        T.Resize((height, width), interpolation=3),
        T.ToTensor(),
        normalizer,
    ])

    source_train_loader = DataLoader(
        Preprocessor(dataset.source_train, root=osp.join(dataset.source_images_dir, dataset.source_train_path),
                     transform=train_transformer),
        batch_size=batch_size, num_workers=workers,
        shuffle=True, pin_memory=True, drop_last=True)

    target_train_loader = DataLoader(
        UnsupervisedCamStylePreprocessor(dataset.target_train,
                                         root=osp.join(dataset.target_images_dir, dataset.target_train_path),
                                         camstyle_root=osp.join(dataset.target_images_dir,
                                                                dataset.target_train_camstyle_path),
                                         num_cam=dataset.target_num_cam, transform=train_transformer),
        batch_size=batch_size, num_workers=workers,
        shuffle=True, pin_memory=True, drop_last=True)

    query_loader = DataLoader(
        Preprocessor(dataset.query,
                     root=osp.join(dataset.target_images_dir, dataset.query_path), transform=test_transformer),
        batch_size=batch_size, num_workers=workers,
        shuffle=False, pin_memory=True)

    gallery_loader = DataLoader(
        Preprocessor(dataset.gallery,
                     root=osp.join(dataset.target_images_dir, dataset.gallery_path), transform=test_transformer),
        batch_size=batch_size, num_workers=workers,
        shuffle=False, pin_memory=True)

    return dataset, num_classes, source_train_loader, target_train_loader, query_loader, gallery_loader
Ejemplo n.º 2
0
def get_data(data_dir, source, target, height, width, batch_size, num_instance=2, workers=8):

    dataset = DA(data_dir, source, target)

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

    num_classes = dataset.num_train_ids

    train_transformer = T.Compose([
        T.Resize((256, 128), interpolation=3),
        T.Pad(10),
        T.RandomCrop((256,128)),
        T.RandomHorizontalFlip(0.5),
        T.RandomRotation(5), 
        T.ToTensor(),
        normalizer,
    ])
    test_transformer = T.Compose([
        T.Resize((256, 128), interpolation=3),
        T.ToTensor(),
        normalizer,
    ])

    source_train_loader = DataLoader(
        Preprocessor_occluded(dataset.source_train, root=osp.join(dataset.source_images_dir, dataset.source_train_path),
                     transform=train_transformer, train=True),
        batch_size=batch_size, num_workers=workers,
        sampler=IdentitySampler(dataset.source_train, num_instance),
        pin_memory=True, drop_last=True)

    query_loader = DataLoader(
        Preprocessor_occluded(dataset.query,
                     root=osp.join(dataset.target_images_dir, dataset.query_path), transform=test_transformer),
        batch_size=42, num_workers=workers,
        shuffle=False, pin_memory=True)
    gallery_loader = DataLoader(
        Preprocessor_occluded(dataset.gallery,
                     root=osp.join(dataset.target_images_dir, dataset.gallery_path), transform=test_transformer),
        batch_size=42, num_workers=workers,
        shuffle=False, pin_memory=True)
    return dataset, num_classes, source_train_loader, query_loader, gallery_loader
Ejemplo n.º 3
0
def get_data(data_dir, height, width, batch_size, num_instances, re=0, workers=8):

    dataset = DA(data_dir)
    test_dataset = TotalData(data_dir)



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

    num_classes = dataset.num_source_ids

    train_transformer = T.Compose([
        T.Resize((256, 128), interpolation=3),
        T.Pad(10),
        T.RandomCrop((256,128)),
        T.RandomHorizontalFlip(0.5),
        T.RandomRotation(5), 
        T.ColorJitter(brightness=(0.5, 2.0), saturation=(0.5, 2.0), hue=(-0.1, 0.1)),
        T.ToTensor(),
        normalizer,
        # T.RandomErasing(EPSILON=re),
    ])

    test_transformer = T.Compose([
        T.Resize((256, 128), interpolation=3),
        T.ToTensor(),
        normalizer,
    ])
    
    # Train
    source_train_loader = DataLoader(
        Preprocessor(dataset.source_train,
                     transform=train_transformer),
        batch_size=batch_size, num_workers=workers,
        # shuffle=True, pin_memory=True, drop_last=True)
        sampler=RandomIdentitySampler(dataset.source_train, batch_size, num_instances),
        pin_memory=True, drop_last=True) 

    # Test
    grid_query_loader = DataLoader(
        Preprocessor(test_dataset.grid_query,
                     root=osp.join(test_dataset.grid_images_dir, test_dataset.query_path), transform=test_transformer),
        batch_size=64, num_workers=4,
        shuffle=False, pin_memory=True)
    grid_gallery_loader = DataLoader(
        Preprocessor(test_dataset.grid_gallery,
                     root=osp.join(test_dataset.grid_images_dir, test_dataset.gallery_path), transform=test_transformer),
        batch_size=64, num_workers=4,
        shuffle=False, pin_memory=True)
    prid_query_loader = DataLoader(
        Preprocessor(test_dataset.prid_query,
                     root=osp.join(test_dataset.prid_images_dir, test_dataset.query_path), transform=test_transformer),
        batch_size=64, num_workers=4,
        shuffle=False, pin_memory=True)
    prid_gallery_loader = DataLoader(
        Preprocessor(test_dataset.prid_gallery,
                     root=osp.join(test_dataset.prid_images_dir, test_dataset.gallery_path), transform=test_transformer),
        batch_size=64, num_workers=4,
        shuffle=False, pin_memory=True)
    viper_query_loader = DataLoader(
        Preprocessor(test_dataset.viper_query,
                     root=osp.join(test_dataset.viper_images_dir, test_dataset.query_path), transform=test_transformer),
        batch_size=64, num_workers=4,
        shuffle=False, pin_memory=True)
    viper_gallery_loader = DataLoader(
        Preprocessor(test_dataset.viper_gallery,
                     root=osp.join(test_dataset.viper_images_dir, test_dataset.gallery_path), transform=test_transformer),
        batch_size=64, num_workers=4,
        shuffle=False, pin_memory=True)
    ilid_query_loader = DataLoader(
        Preprocessor(test_dataset.ilid_query,
                     root=osp.join(test_dataset.ilid_images_dir, "images"), transform=test_transformer),
        batch_size=64, num_workers=4,
        shuffle=False, pin_memory=True)
    ilid_gallery_loader = DataLoader(
        Preprocessor(test_dataset.ilid_gallery,
                     root=osp.join(test_dataset.ilid_images_dir, "images"), transform=test_transformer),
        batch_size=64, num_workers=4,
        shuffle=False, pin_memory=True)


    return dataset, test_dataset, num_classes, source_train_loader, grid_query_loader, grid_gallery_loader,prid_query_loader, prid_gallery_loader,viper_query_loader, viper_gallery_loader, ilid_query_loader, ilid_gallery_loader
Ejemplo n.º 4
0
def get_data(data_dir, source, target, height, width, batch_size, re=0, workers=8):

    dataset = DA(data_dir, source, target)
    dataset_2 = DA(data_dir, target, source)

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

    num_classes = dataset.num_train_ids

    train_transformer = T.Compose([
        T.Resize((height, width), interpolation=3),
             T.RandomHorizontalFlip(p=0.5),
             T.Pad(10),
             T.RandomCrop((height, width)),
             T.ToTensor(),
        normalizer,
       # T.RandomErasing(EPSILON=re),
        T.RandomErasing(probability=0.4, mean=[0.485, 0.456, 0.406])
    ])

    train_transformer_2 = T.Compose([
        T.Resize((height, width), interpolation=3),
             T.RandomHorizontalFlip(p=0.5),
             T.Pad(10),
             T.RandomCrop((height, width)),
             T.ToTensor(),
        normalizer,
       # T.RandomErasing(EPSILON=re),
        T.RandomErasing(probability=0.4, mean=[0.485, 0.456, 0.406])
    ])

    test_transformer = T.Compose([
        T.Resize((height, width), interpolation=3),
        T.ToTensor(),
        normalizer,
    ])

    '''
    num_instances=4

    rmgs_flag = num_instances > 0
    if rmgs_flag:
        sampler = RandomIdentitySampler(dataset.target_train, num_instances)
    else:
        sampler = None
    '''
    source_train_loader = DataLoader(
        Preprocessor(dataset.source_train, root=osp.join(dataset.source_images_dir, dataset.source_train_path),
                     transform=train_transformer),
        batch_size=batch_size, num_workers=workers,
        shuffle=True, pin_memory=True, drop_last=True)

    num_instances=0

    rmgs_flag = num_instances > 0
    if rmgs_flag:
        sampler = RandomIdentitySampler(dataset.target_train, num_instances)
    else:
        sampler = None



    target_train_loader = DataLoader(
        UnsupervisedCamStylePreprocessor(dataset.target_train,
                                         root=osp.join(dataset.target_images_dir, dataset.target_train_path),
                                         camstyle_root=osp.join(dataset.target_images_dir,
                                                                dataset.target_train_camstyle_path),
                                         num_cam=dataset.target_num_cam, transform=train_transformer),
        batch_size=batch_size, num_workers=workers,
        shuffle=True, pin_memory=True, drop_last=True)

    query_loader = DataLoader(
        Preprocessor(dataset.query,
                     root=osp.join(dataset.target_images_dir, dataset.query_path), transform=test_transformer),
        batch_size=batch_size, num_workers=workers,
        shuffle=False, pin_memory=True)

    query_loader_2 = DataLoader(
        Preprocessor(dataset_2.query,
                     root=osp.join(dataset_2.target_images_dir, dataset_2.query_path), transform=test_transformer),
        batch_size=batch_size, num_workers=workers,
        shuffle=False, pin_memory=True)

    gallery_loader = DataLoader(
        Preprocessor(dataset.gallery,
                     root=osp.join(dataset.target_images_dir, dataset.gallery_path), transform=test_transformer),
        batch_size=batch_size, num_workers=workers,
        shuffle=False, pin_memory=True)

    gallery_loader_2 = DataLoader(
        Preprocessor(dataset_2.gallery,
                     root=osp.join(dataset_2.target_images_dir, dataset_2.gallery_path), transform=test_transformer),
        batch_size=batch_size, num_workers=workers,
        shuffle=False, pin_memory=True)

    return dataset,dataset_2, num_classes, source_train_loader, target_train_loader, query_loader, gallery_loader, query_loader_2, gallery_loader_2