Exemplo n.º 1
0
 def test_trans_resize(self):
     trans = transforms.Compose([
         transforms.Resize(300),
         transforms.RandomResizedCrop((280, 280)),
         transforms.Resize(280),
         transforms.Resize((256, 200)),
         transforms.Resize((180, 160)),
         transforms.CenterCrop(128),
         transforms.CenterCrop((128, 128)),
     ])
     self.do_transform(trans)
Exemplo n.º 2
0
    def __init__(self,
                 path,
                 mode='train',
                 image_size=224,
                 resize_short_size=256):
        super(ImageNetDataset, self).__init__(path)
        self.mode = mode

        self.samples = []
        list_file = "train_list.txt" if self.mode == "train" else "val_list.txt"
        with open(os.path.join([path, list_file]), 'r') as f:
            for line in f:
                _image, _label = line.strip().split(" ")
                self.samples.append((_image, int(_label)))
        normalize = transforms.Normalize(mean=[123.675, 116.28, 103.53],
                                         std=[58.395, 57.120, 57.375])
        if self.mode == 'train':
            self.transform = transforms.Compose([
                transforms.RandomResizedCrop(image_size),
                transforms.RandomHorizontalFlip(),
                transforms.Transpose(), normalize
            ])
        else:
            self.transform = transforms.Compose([
                transforms.Resize(resize_short_size),
                transforms.CenterCrop(image_size),
                transforms.Transpose(), normalize
            ])
Exemplo n.º 3
0
    def __init__(self,
                 data_dir,
                 mode='train',
                 image_size=224,
                 resize_short_size=256):
        super(ImageNetDataset, self).__init__()
        train_file_list = os.path.join(data_dir, 'train_list.txt')
        val_file_list = os.path.join(data_dir, 'val_list.txt')
        test_file_list = os.path.join(data_dir, 'test_list.txt')
        self.data_dir = data_dir
        self.mode = mode

        normalize = transforms.Normalize(
            mean=[123.675, 116.28, 103.53], std=[58.395, 57.120, 57.375])
        if self.mode == 'train':
            self.transform = transforms.Compose([
                transforms.RandomResizedCrop(image_size),
                transforms.RandomHorizontalFlip(), transforms.Transpose(),
                normalize
            ])
        else:
            self.transform = transforms.Compose([
                transforms.Resize(resize_short_size),
                transforms.CenterCrop(image_size), transforms.Transpose(),
                normalize
            ])

        if mode == 'train':
            with open(train_file_list) as flist:
                full_lines = [line.strip() for line in flist]
                np.random.shuffle(full_lines)
                if os.getenv('PADDLE_TRAINING_ROLE'):
                    # distributed mode if the env var `PADDLE_TRAINING_ROLE` exits
                    trainer_id = int(os.getenv("PADDLE_TRAINER_ID", "0"))
                    trainer_count = int(os.getenv("PADDLE_TRAINERS_NUM", "1"))
                    per_node_lines = len(full_lines) // trainer_count
                    lines = full_lines[trainer_id * per_node_lines:(
                        trainer_id + 1) * per_node_lines]
                    print(
                        "read images from %d, length: %d, lines length: %d, total: %d"
                        % (trainer_id * per_node_lines, per_node_lines,
                           len(lines), len(full_lines)))
                else:
                    lines = full_lines
            self.data = [line.split() for line in lines]
        else:
            with open(val_file_list) as flist:
                lines = [line.strip() for line in flist]
                self.data = [line.split() for line in lines]
Exemplo n.º 4
0
    def __init__(self, data_dir, image_size=224, resize_short_size=256):
        super(ImageNetValDataset, self).__init__()
        val_file_list = os.path.join(data_dir, 'val_list.txt')
        test_file_list = os.path.join(data_dir, 'test_list.txt')
        self.data_dir = data_dir

        normalize = transforms.Normalize(mean=[123.675, 116.28, 103.53],
                                         std=[58.395, 57.120, 57.375])
        self.transform = transforms.Compose([
            transforms.Resize(resize_short_size),
            transforms.CenterCrop(image_size),
            transforms.Transpose(), normalize
        ])

        with open(val_file_list) as flist:
            lines = [line.strip() for line in flist]
            self.data = [line.split() for line in lines]
Exemplo n.º 5
0
    def __init__(self,
                 path,
                 mode='train',
                 image_size=224,
                 resize_short_size=256):
        super(ImageNetDataset, self).__init__(path)
        self.mode = mode

        normalize = transforms.Normalize(mean=[123.675, 116.28, 103.53],
                                         std=[58.395, 57.120, 57.375])
        if self.mode == 'train':
            self.transform = transforms.Compose([
                transforms.RandomResizedCrop(image_size),
                transforms.RandomHorizontalFlip(),
                transforms.Transpose(), normalize
            ])
        else:
            self.transform = transforms.Compose([
                transforms.Resize(resize_short_size),
                transforms.CenterCrop(image_size),
                transforms.Transpose(), normalize
            ])