示例#1
0
def test_transform(args, image):

    input_size1 = 512
    input_size2 = 448

    if int(args.subset) == 0 or int(args.subset) == 192:
        transform = transforms.Compose([
            transforms.Resize(input_size1),
            transforms.CenterCrop(input_size2),
            transforms.Upscale(upscale_factor=2),
            transforms.TransformUpscaledDCT(),
            transforms.ToTensorDCT(),
            transforms.Aggregate(),
            transforms.NormalizeDCT(
                train_upscaled_static_mean,
                train_upscaled_static_std,
            )
        ])
    else:
        transform = transforms.Compose([
            transforms.Resize(input_size1),
            transforms.CenterCrop(input_size2),
            transforms.Upscale(upscale_factor=2),
            transforms.TransformUpscaledDCT(),
            transforms.ToTensorDCT(),
            transforms.SubsetDCT(channels=args.subset),
            transforms.Aggregate(),
            transforms.NormalizeDCT(train_upscaled_static_mean,
                                    train_upscaled_static_std,
                                    channels=args.subset)
        ])

    return transform
示例#2
0
def trainloader_upscaled_static(args, model='mobilenet'):
    valdir = os.path.join(args.data, 'train')

    if model == 'mobilenet':
        input_size1 = 1024
        input_size2 = 896
    elif model == 'resnet':
        input_size1 = 512
        input_size2 = 448
    else:
        raise NotImplementedError
    if int(args.subset) == 0 or int(args.subset) == 192:
        transform = transforms.Compose([
            enhance.random_crop(),
            enhance.horizontal_flip(),
            enhance.vertical_flip(),
            enhance.random_rotation(),
            enhance.tocv2(),
            transforms.Resize(input_size1),
            transforms.CenterCrop(input_size2),
            transforms.Upscale(upscale_factor=2),
            transforms.TransformUpscaledDCT(),
            transforms.ToTensorDCT(),
            transforms.Aggregate(),
            transforms.NormalizeDCT(
                train_upscaled_static_mean,
                train_upscaled_static_std,
            )
        ])
    else:
        transform = transforms.Compose([
            enhance.random_crop(),
            enhance.horizontal_flip(),
            enhance.vertical_flip(),
            enhance.random_rotation(),
            enhance.tocv2(),
            transforms.Resize(input_size1),
            transforms.CenterCrop(input_size2),
            transforms.Upscale(upscale_factor=2),
            transforms.TransformUpscaledDCT(),
            transforms.ToTensorDCT(),
            transforms.SubsetDCT(channels=args.subset),
            transforms.Aggregate(),
            transforms.NormalizeDCT(train_upscaled_static_mean,
                                    train_upscaled_static_std,
                                    channels=args.subset)
        ])
    dset = ImageFolderDCT(valdir, transform, backend='pil')
    val_loader = torch.utils.data.DataLoader(dset,
                                             batch_size=args.train_batch,
                                             shuffle=True,
                                             num_workers=args.workers,
                                             pin_memory=True)

    return val_loader, len(dset), dset.get_clsnum()
示例#3
0
def valloader_upscaled_dct_direct(args, model='mobilenet'):
    if model == 'mobilenet':
        input_size1 = 128
        input_size2 = 112
    elif model == 'resnet':
        input_size1 = 64
        input_size2 = 56
    else:
        raise NotImplementedError

    valdir = os.path.join(args.data, 'val')
    transform = transforms.Compose([
        transforms.UpsampleCbCr(),
        transforms.SubsetDCT2(channels=args.subset, pattern=args.pattern),
        transforms.Aggregate2(),
        transforms.Resize(input_size1),
        transforms.CenterCrop(input_size2),
        transforms.ToTensorDCT2(),
        transforms.NormalizeDCT(
            train_upscaled_static_dct_direct_mean_interp,
            train_upscaled_static_dct_direct_std_interp,
            channels=args.subset,
            pattern=args.pattern
        )
    ])
    val_loader = torch.utils.data.DataLoader(
        ImageFolderDCT(valdir, transform, backend='dct'),
        batch_size=args.test_batch, shuffle=False,
        num_workers=args.workers, pin_memory=True
    )

    return val_loader
示例#4
0
def valloader_upscaled_static(args, model='mobilenet'):
    valdir = os.path.join(args.data, 'val')

    if model == 'mobilenet':
        input_size1 = 1024
        input_size2 = 896
    elif model == 'resnet':
        input_size1 = 512
        input_size2 = 448
    else:
        raise NotImplementedError

    transform = transforms.Compose([
            transforms.Resize(input_size1),
            transforms.CenterCrop(input_size2),
            transforms.Upscale(upscale_factor=2),
            transforms.TransformUpscaledDCT(),
            transforms.ToTensorDCT(),
            transforms.SubsetDCT(channels=args.subset, pattern=args.pattern),
            transforms.Aggregate(),
            transforms.NormalizeDCT(
                train_upscaled_static_mean,
                train_upscaled_static_std,
                channels=args.subset,
                pattern=args.pattern
            )
        ])

    val_loader = torch.utils.data.DataLoader(
        ImageFolderDCT(valdir, transform),
        batch_size=args.test_batch, shuffle=False,
        num_workers=args.workers, pin_memory=True)

    return val_loader
示例#5
0
def test(model):
    # bar = Bar('Processing', max=len(val_loader))

    # batch_time = AverageMeter()
    # data_time = AverageMeter()
    # losses = AverageMeter()
    # top1 = AverageMeter()
    # top5 = AverageMeter()

    # switch to evaluate mode
    model.eval()

    csvfile = open('./csv.csv', 'w')
    writer = csv.writer(csvfile)
    test_root = './data/test/'
    img_test = os.listdir(test_root)
    img_test.sort(key=lambda x: int(x[:-4]))

    input_size1 = 512
    input_size2 = 448

    transform = transforms.Compose([
        transforms.Resize(input_size1),
        transforms.CenterCrop(input_size2),
        transforms.Upscale(upscale_factor=2),
        transforms.TransformUpscaledDCT(),
        transforms.ToTensorDCT(),
        transforms.SubsetDCT(channels=args.subset),
        transforms.Aggregate(),
        transforms.NormalizeDCT(train_upscaled_static_mean,
                                train_upscaled_static_std,
                                channels=args.subset)
    ])

    with torch.no_grad():
        # end = time.time()
        for i in range(len(img_test)):
            model.eval()
            # measure data loading time
            # data_time.update(time.time() - end)

            # image, target = image.cuda(non_blocking=True), target.cuda(
            #     non_blocking=True)

            image = cv2.imread(str(test_root + img_test[i]))
            image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
            # print(transform(image)[0])
            # print(type(transform(image)[0]))
            # compute output
            output = model(transform(image)[0].unsqueeze(dim=0))
            #print(output)
            _, pred = torch.max(output.data, 1)
            print(i, pred.tolist()[0])
            writer.writerow([i, pred.tolist()[0]])
示例#6
0
def valloader_dct(args):
    valdir = os.path.join(args.data, 'val')

    val_loader = torch.utils.data.DataLoader(
        ImageFolderDCT(valdir, transforms.Compose([
            transforms.Resize(256),
            transforms.CenterCrop(224),
            transforms.TransformDCT(),
            transforms.ToTensorDCT(),
            transforms.NormalizeDCT(
                train_y_mean, train_y_std,
                train_cb_mean, train_cb_std,
                train_cr_mean, train_cr_std),
        ])),
        batch_size=args.test_batch, shuffle=False,
        num_workers=args.workers, pin_memory=True)

    return val_loader
示例#7
0
 def get_composed_transform_dct(self, aug=False, filter_size=8):
     # print("aug: ", aug)
     # print("filter size,", filter_size)
     if aug == False:
         transform = transforms_dct.Compose([  #transform_funcs,
             transforms_dct.Resize(int(filter_size * 56 * 1.15)),
             transforms_dct.CenterCrop(filter_size * 56),
             transforms_dct.GetDCT(filter_size),
             transforms_dct.UpScaleDCT(size=56),
             transforms_dct.ToTensorDCT(),
             transforms_dct.SubsetDCT(channels=24),
             transforms_dct.Aggregate(),
             transforms_dct.NormalizeDCT(
                 #  train_y_mean_resized,  train_y_std_resized,
                 #  train_cb_mean_resized, train_cb_std_resized,
                 #  train_cr_mean_resized, train_cr_std_resized),
                 train_upscaled_static_mean,
                 train_upscaled_static_std,
                 channels=24)
             #transforms_dct.Aggregate()
         ])
     else:
         transform = transforms_dct.Compose([  #transform_funcs,
             transforms_dct.RandomResizedCrop(filter_size * 56),
             transforms_dct.ImageJitter(self.jitter_param),
             transforms_dct.RandomHorizontalFlip(),
             transforms_dct.GetDCT(filter_size),
             transforms_dct.UpScaleDCT(size=56),
             transforms_dct.ToTensorDCT(),
             transforms_dct.SubsetDCT(channels=24),
             transforms_dct.Aggregate(),
             transforms_dct.NormalizeDCT(
                 #  train_y_mean_resized,  train_y_std_resized,
                 #  train_cb_mean_resized, train_cb_std_resized,
                 #  train_cr_mean_resized, train_cr_std_resized),
                 train_upscaled_static_mean,
                 train_upscaled_static_std,
                 channels=24)
         ])
     return transform
示例#8
0
def valloader_dct_resized(args):
    valdir = os.path.join(args.data, 'val')

    val_loader = torch.utils.data.DataLoader(
        ImageFolderDCT(valdir, transforms.Compose([
            transforms.Resize(256),
            transforms.CenterCrop(224),
            transforms.TransformDCT(),  # 28x28x192
            transforms.DCTFlatten2D(),
            transforms.UpsampleDCT(upscale_ratio_h=4, upscale_ratio_w=4, debug=False),
            transforms.ToTensorDCT(),
            transforms.SubsetDCT(channels=args.subset),
            transforms.Aggregate(),
            transforms.NormalizeDCT(
                train_dct_subset_mean,
                train_dct_subset_std,
                channels=args.subset
            )
        ])),
        batch_size=args.test_batch, shuffle=False,
        num_workers=args.workers, pin_memory=True)

    return val_loader
示例#9
0
    #     transforms.RandomHorizontalFlip(),
    #     transforms.ToTensorDCT2(),
    #     transforms.NormalizeDCT(
    #         train_upscaled_static_mean,
    #         train_upscaled_static_std,
    #         channels=32
    #     )
    # ])

    transform6 = transforms.Compose([
        transforms.DCTFlatten2D(mux=0b011),
        transforms.UpsampleCbCr(),
        transforms.UpsampleDCT(T=512, debug=False),
        transforms.SubsetDCT2(channels=64),
        transforms.Aggregate2(),
        transforms.CenterCrop(448 // 8),
        transforms.ToTensorDCT2(),
        transforms.NormalizeDCT(
            train_upscaled_static_dct_direct_mean,
            train_upscaled_static_dct_direct_std,
            channels=64
        )
    ])

    transform7 = transforms.Compose([
        transforms.UpsampleCbCr(),
        transforms.SubsetDCT2(channels=64),
        transforms.RandomResizedCropDCT(size=448),
        transforms.Aggregate2(),
        transforms.RandomHorizontalFlip(),
        transforms.ToTensorDCT2(),
示例#10
0
import datasets.cvtransforms as transforms_dct 


input_size1 = 512
input_size2 = 448 
transform = transforms_dct.Compose([
            transforms_dct.Resize(input_size1),
            transforms_dct.CenterCrop(input_size2)),
            transforms_dct.Upscale(upscale_factor=2)
            ])