示例#1
0
def loading_data():
    mean_std = cfg_data.MEAN_STD
    log_para = cfg_data.LOG_PARA
    factor = cfg_data.LABEL_FACTOR
    train_main_transform = own_transforms.Compose(
        [own_transforms.RandomHorizontallyFlip()])
    img_transform = standard_transforms.Compose([
        standard_transforms.ToTensor(),
        standard_transforms.Normalize(*mean_std)
    ])
    gt_transform = standard_transforms.Compose([
        own_transforms.GTScaleDown(factor),
        own_transforms.LabelNormalize(log_para)
    ])
    restore_transform = standard_transforms.Compose([
        own_transforms.DeNormalize(*mean_std),
        standard_transforms.ToPILImage()
    ])

    train_set = SHHA(cfg_data.DATA_PATH + '/train_data',
                     mode='train',
                     preload=True,
                     main_transform=train_main_transform,
                     img_transform=img_transform,
                     gt_transform=gt_transform)

    train_loader = None

    if cfg_data.TRAIN_BATCH_SIZE == 1:
        train_loader = DataLoader(train_set,
                                  batch_size=1,
                                  num_workers=0,
                                  collate_fn=SHHA_raw_collate,
                                  shuffle=True,
                                  drop_last=True)

    elif cfg_data.TRAIN_BATCH_SIZE > 1:
        train_loader = DataLoader(train_set,
                                  batch_size=cfg_data.TRAIN_BATCH_SIZE,
                                  num_workers=8,
                                  collate_fn=SHHA_crop_collate,
                                  shuffle=True,
                                  drop_last=True)

    val_set = SHHA(cfg_data.DATA_PATH + '/test_data',
                   mode='test',
                   preload=True,
                   main_transform=None,
                   img_transform=img_transform,
                   gt_transform=gt_transform)
    val_loader = DataLoader(val_set,
                            batch_size=cfg_data.VAL_BATCH_SIZE,
                            num_workers=0,
                            collate_fn=SHHA_raw_collate,
                            shuffle=True,
                            drop_last=False)

    return train_loader, val_loader, restore_transform
示例#2
0
文件: utils.py 项目: maohule/adacrowd
def data_transforms(cfg_data):

    mean_std = cfg_data.MEAN_STD
    log_para = cfg_data.LOG_PARA

    # train and val main data transformations
    if cfg_data.DATASET == 'City':
        train_main_transform = own_transforms.Compose([
            own_transforms.RandomHorizontallyFlip()
        ])
        val_main_transform = None
    elif cfg_data.DATASET in ['FDST', 'PETS']:
        train_main_transform = standard_transforms.Compose([
            own_transforms.FreeScale(cfg_data.TRAIN_SIZE),
        ])
        val_main_transform = standard_transforms.Compose([
            own_transforms.FreeScale(cfg_data.TRAIN_SIZE),
        ])
    else:
        train_main_transform = own_transforms.Compose([
            own_transforms.RandomCrop(cfg_data.TRAIN_SIZE),
            own_transforms.RandomHorizontallyFlip()
        ])

        val_main_transform = None

    # image and gt transformations
    if cfg_data.DATASET == 'FDST':
        gt_transform = standard_transforms.Compose([
            own_transforms.GTScaleDown(cfg_data.TRAIN_DOWNRATE),
            own_transforms.LabelNormalize(log_para)
        ])
    else:
        gt_transform = standard_transforms.Compose([
            own_transforms.LabelNormalize(log_para)
        ])

    img_transform = standard_transforms.Compose([
        standard_transforms.ToTensor(),
        standard_transforms.Normalize(*mean_std)
    ])

    restore_transform = standard_transforms.Compose([
        own_transforms.DeNormalize(*mean_std),
        standard_transforms.ToPILImage()
    ])

    return train_main_transform, val_main_transform, img_transform, gt_transform, restore_transform
示例#3
0
def loading_data():
    # shanghai Tech A
    mean_std = cfg.DATA.MEAN_STD
    log_para = cfg.DATA.LOG_PARA
    factor = cfg.DATA.LABEL_FACTOR
    train_main_transform = own_transforms.Compose([
        own_transforms.RandomCrop(cfg.TRAIN.INPUT_SIZE),
        own_transforms.RandomHorizontallyFlip()
    ])
    val_main_transform = None
    img_transform = standard_transforms.Compose([
        standard_transforms.ToTensor(),
        standard_transforms.Normalize(*mean_std)
    ])
    gt_transform = standard_transforms.Compose([
        own_transforms.GTScaleDown(factor),
        own_transforms.LabelNormalize(log_para)
    ])
    restore_transform = standard_transforms.Compose([
        own_transforms.DeNormalize(*mean_std),
        standard_transforms.ToPILImage()
    ])

    train_set = UCF_QNRF(cfg.DATA.DATA_PATH + '/train',
                         'train',
                         main_transform=train_main_transform,
                         img_transform=img_transform,
                         gt_transform=gt_transform)
    train_loader = DataLoader(train_set,
                              batch_size=cfg.TRAIN.BATCH_SIZE,
                              num_workers=8,
                              shuffle=True,
                              drop_last=True)

    val_set = UCF_QNRF(cfg.DATA.DATA_PATH + '/test',
                       'test',
                       main_transform=val_main_transform,
                       img_transform=img_transform,
                       gt_transform=gt_transform)
    val_loader = DataLoader(val_set,
                            batch_size=cfg.VAL.BATCH_SIZE,
                            num_workers=8,
                            shuffle=True,
                            drop_last=False)

    return train_set, train_loader, val_set, val_loader, restore_transform
示例#4
0
def loading_data():
    mean_std = cfg_data.MEAN_STD
    log_para = cfg_data.LOG_PARA
    factor = cfg_data.LABEL_FACTOR
    train_main_transform = own_transforms.Compose([
        own_transforms.RandomHorizontallyFlip()
    ])
    img_transform = standard_transforms.Compose([
        standard_transforms.ToTensor(),
        standard_transforms.Normalize(*mean_std)
    ])
    gt_transform = standard_transforms.Compose([
        own_transforms.GTScaleDown(factor),
        own_transforms.LabelNormalize(log_para)
    ])
    restore_transform = standard_transforms.Compose([
        own_transforms.DeNormalize(*mean_std),
        standard_transforms.ToPILImage()
    ])

    if cfg_data.IS_CROSS_SCENE:
        train_set = AC(img_path=cfg_data.IMAGE_PATH, den_path=cfg_data.DENSITY_PATH + '/cross_scene_train',
                       aud_path=cfg_data.AUDIO_PATH,
                       mode='train', main_transform=train_main_transform, img_transform=img_transform,
                       gt_transform=gt_transform, is_noise=cfg_data.IS_NOISE, brightness_decay=cfg_data.BRIGHTNESS,
                       noise_sigma=cfg_data.NOISE_SIGMA, longest_side=cfg_data.LONGEST_SIDE
                       )
    else:
        train_set = AC(img_path=cfg_data.IMAGE_PATH, den_path=cfg_data.DENSITY_PATH + '/train',
                       aud_path=cfg_data.AUDIO_PATH,
                       mode='train', main_transform=train_main_transform, img_transform=img_transform,
                       gt_transform=gt_transform, is_noise=cfg_data.IS_NOISE, brightness_decay=cfg_data.BRIGHTNESS,
                       noise_sigma=cfg_data.NOISE_SIGMA, longest_side=cfg_data.LONGEST_SIDE,
                       black_area_ratio=cfg_data.BLACK_AREA_RATIO, is_random=cfg_data.IS_RANDOM, is_denoise=cfg_data.IS_DENOISE
                       )
    train_loader = None
    if cfg_data.TRAIN_BATCH_SIZE == 1:
        train_loader = DataLoader(train_set, batch_size=1, num_workers=8, shuffle=True, drop_last=True)
    elif cfg_data.TRAIN_BATCH_SIZE > 1:
        train_loader = DataLoader(train_set, batch_size=cfg_data.TRAIN_BATCH_SIZE, num_workers=8,
                                  collate_fn=AC_collate, shuffle=True, drop_last=True)

    if cfg_data.IS_CROSS_SCENE:
        val_set = AC(img_path=cfg_data.IMAGE_PATH, den_path=cfg_data.DENSITY_PATH + '/cross_scene_val',
                     aud_path=cfg_data.AUDIO_PATH,
                     mode='val', main_transform=None, img_transform=img_transform, gt_transform=gt_transform,
                     is_noise=cfg_data.IS_NOISE, brightness_decay=cfg_data.BRIGHTNESS,
                     noise_sigma=cfg_data.NOISE_SIGMA, longest_side=cfg_data.LONGEST_SIDE
                     )
    else:
        val_set = AC(img_path=cfg_data.IMAGE_PATH, den_path=cfg_data.DENSITY_PATH + '/val',
                     aud_path=cfg_data.AUDIO_PATH,
                     mode='val', main_transform=None, img_transform=img_transform, gt_transform=gt_transform,
                     is_noise=cfg_data.IS_NOISE, brightness_decay=cfg_data.BRIGHTNESS,
                     noise_sigma=cfg_data.NOISE_SIGMA, longest_side=cfg_data.LONGEST_SIDE,
                     black_area_ratio=cfg_data.BLACK_AREA_RATIO, is_random=cfg_data.IS_RANDOM, is_denoise=cfg_data.IS_DENOISE
                     )
    val_loader = DataLoader(val_set, batch_size=cfg_data.VAL_BATCH_SIZE, num_workers=1, shuffle=False, drop_last=False)

    if cfg_data.IS_CROSS_SCENE:
        test_set = AC(img_path=cfg_data.IMAGE_PATH, den_path=cfg_data.DENSITY_PATH + '/cross_scene_test',
                      aud_path=cfg_data.AUDIO_PATH,
                     mode='test', main_transform=None, img_transform=img_transform, gt_transform=gt_transform,
                     is_noise=cfg_data.IS_NOISE, brightness_decay=cfg_data.BRIGHTNESS,
                     noise_sigma=cfg_data.NOISE_SIGMA, longest_side=cfg_data.LONGEST_SIDE
                     )
    else:
        test_set = AC(img_path=cfg_data.IMAGE_PATH, den_path=cfg_data.DENSITY_PATH + '/test',
                      aud_path=cfg_data.AUDIO_PATH,
                      mode='test', main_transform=None, img_transform=img_transform, gt_transform=gt_transform,
                      is_noise=cfg_data.IS_NOISE, brightness_decay=cfg_data.BRIGHTNESS,
                      noise_sigma=cfg_data.NOISE_SIGMA, longest_side=cfg_data.LONGEST_SIDE,
                      black_area_ratio=cfg_data.BLACK_AREA_RATIO, is_random=cfg_data.IS_RANDOM, is_denoise=cfg_data.IS_DENOISE
                      )
    test_loader = DataLoader(test_set, batch_size=cfg_data.VAL_BATCH_SIZE, num_workers=1, shuffle=False, drop_last=False)

    return train_loader, val_loader, test_loader, restore_transform