Esempio n. 1
0
    def Img_transform(self, name, size, split='train'):

        # if len(args.crop_size) == 1:
        # 	crop_size = (args.crop_size[0] , args.crop_size[0]) ## W x H
        # else:
        # 	crop_size = (args.crop_size[1] , args.crop_size[0])

        assert (isinstance(size, tuple) and len(size) == 2)

        if name in ['CS', 'IDD']:

            if split == 'train':
                t = [
                    transforms.Resize(size),
                    transforms.RandomCrop((512, 512)),
                    transforms.RandomHorizontalFlip(),
                    transforms.ToTensor()
                ]
            else:
                t = [transforms.Resize(size), transforms.ToTensor()]

            return transforms.Compose(t)

        if split == 'train':
            t = [
                transforms.Resize(size),
                transforms.RandomHorizontalFlip(),
                transforms.ToTensor()
            ]
        else:
            t = [transforms.Resize(size), transforms.ToTensor()]

        return transforms.Compose(t)
Esempio n. 2
0
 def __init__(self, cfg):
     self.cfg = cfg
     if self.cfg.mode == 'train':
         self.transform = transform.Compose( transform.Normalize(mean=cfg.mean, std=cfg.std),
                                             transform.Resize(size=512),
                                             transform.RandomRotate(-15, 15),
                                             transform.RandomCrop(448, 448),
                                             transform.RandomHorizontalFlip(),
                                             transform.RandomMask(),
                                             transform.ToTensor())
     elif self.cfg.mode == 'val' or self.cfg.mode == 'test': 
         self.transform = transform.Compose( transform.Normalize(mean=cfg.mean, std=cfg.std),
                                             transform.Resize(size=512),
                                             transform.ToTensor())
     else:
         raise ValueError
Esempio n. 3
0
    def __init__(self, cfg):
        with open(cfg.datapath + '/' + cfg.mode + '.txt', 'r') as lines:
            self.samples = []
            for line in lines:
                imagepath = cfg.datapath + '/image/' + line.strip() + '.jpg'
                maskpath = cfg.datapath + '/scribble/' + line.strip() + '.png'
                self.samples.append([imagepath, maskpath])

        if cfg.mode == 'train':
            self.transform = transform.Compose(
                transform.Normalize(mean=cfg.mean, std=cfg.std),
                transform.Resize(320, 320), transform.RandomHorizontalFlip(),
                transform.RandomCrop(320, 320), transform.ToTensor())
        elif cfg.mode == 'test':
            self.transform = transform.Compose(
                transform.Normalize(mean=cfg.mean, std=cfg.std),
                transform.Resize(320, 320), transform.ToTensor())
        else:
            raise ValueError
Esempio n. 4
0
    def __init__(self, cfg):
        with open(os.path.join(cfg.datapath, cfg.mode + '.txt'), 'r') as lines:
            self.samples = []
            for line in lines:
                imagepath = os.path.join(cfg.datapath, 'image',
                                         line.strip() + '.jpg')
                maskpath = os.path.join(cfg.datapath, 'mask',
                                        line.strip() + '.png')
                self.samples.append([imagepath, maskpath])

        if cfg.mode == 'train':
            self.transform = transform.Compose(
                transform.Normalize(mean=cfg.mean, std=cfg.std),
                transform.Resize(320, 320), transform.RandomHorizontalFlip(),
                transform.RandomCrop(288, 288), transform.ToTensor())
        elif cfg.mode == 'test':
            self.transform = transform.Compose(
                transform.Normalize(mean=cfg.mean, std=cfg.std),
                transform.Resize(320, 320), transform.ToTensor())
        else:
            raise ValueError
import torchvision
import torch
print(torch.__version__)
print(torchvision.__version__)

normalize = T.Normalize(mean=[0.43216, 0.394666, 0.37645],
                        std=[0.22803, 0.22145, 0.216989])
# def normalize(tensor):
#     # Subtract the mean, and scale to the interval [-1,1]
#     tensor_minusmean = tensor - tensor.mean()
#     return tensor_minusmean/tensor_minusmean.abs().max()
transform_video = torchvision.transforms.Compose([
    T.ToFloatTensorInZeroOne(),
    T.Resize((128, 171)),
    T.RandomHorizontalFlip(), normalize,
    T.RandomCrop((112, 112))
])
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

root = ET.parse(
    '/root/yangsen-data/LIRIS-ACCEDE-movies/ACCEDEmovies.xml').getroot()
movie_length = {}


def get_sec(time_str: str) -> int:
    """Get Seconds from time."""
    h, m, s = time_str.split(':')
    return int(h) * 3600 + int(m) * 60 + int(s)


for i in root:
Esempio n. 6
0
    if args.distributed:
        torch.cuda.set_device(args.local_rank)
        torch.distributed.init_process_group(backend='nccl', init_method='env://')
        synchronize()

    img_mean = [0.485, 0.456, 0.406]
    img_std = [0.229, 0.224, 0.225]
    device = 'cuda'
    # torch.backends.cudnn.deterministic = True

    train_trans = transform.Compose(
        [
            transform.RandomScale(0.5, 2.0),
            # transform.Resize(args.size, None),
            transform.RandomHorizontalFlip(),
            transform.RandomCrop(args.size),
            transform.RandomBrightness(0.04),
            transform.ToTensor(),
            transform.Normalize(img_mean, img_std),
            transform.Pad(args.size)
        ]
    )

    valid_trans = transform.Compose(
        [transform.ToTensor(), transform.Normalize(img_mean, img_std)]
    )

    train_set = ADE20K(args.path, 'train', train_trans)
    valid_set = ADE20K(args.path, 'valid', valid_trans)

    arch_map = {'vovnet39': vovnet39, 'vovnet57': vovnet57}