コード例 #1
0
    def __getitem__(self, index):  # TODO
        img_dir = self._getInputPath(index)
        if self.args.template_debug:  # if debugging the template, don't read an image
            img = self.images[index]
        else:
            img = io.imread(img_dir, as_gray=self.args.grayscale).astype(
                np.float32) / 255.0

        h, w, c = img.shape
        crop_h, crop_w = self.args.crop_h, self.args.crop_w
        if self.args.rescale:
            sc_h = np.random.randint(crop_h, h)
            sc_w = np.random.randint(crop_w, w)
            img = transforms.rescale(img, sc_h, sc_w)

        if self.args.crop:
            img = transforms.random_crop(img, [crop_h, crop_w])

        if self.args.color_aug:
            img = (img * np.random.uniform(1, 3)).clip(0, 2)

        if self.args.noise_aug:
            img = transforms.random_noise_aug(img, self.args.noise)

        if self.args.template_debug:
            label = (index > 60) * 1.0
        else:
            pass  # FIXME

        item = {'img': torch.from_numpy(img).float(), 'label': label}  # TODO

        return item
コード例 #2
0
 def transform(self, image, target):
     if self.training:
         image, target = tr_custom.random_horizontal_flip([image, target])
         image, target = tr_custom.random_rotation([image, target], angle=15)
         image, target = tr_custom.random_crop([image, target], scale=(0.8, 1.0),
                                               aspect_ratio=self.aspect_ratio)
     else:
         image, target = tr_custom.center_crop([image, target], aspect_ratio=self.aspect_ratio)
     image_fullres, target = [tr.resize(img, self.fullres) for img in [image, target]]
     image_lowres = tr.resize(image_fullres, self.lowres, interpolation=Image.NEAREST)
     image_lowres, image_fullres, target = [tr.to_tensor(img) for img in [image_lowres, image_fullres, target]]
     return image_lowres, image_fullres, target
コード例 #3
0
ファイル: train.py プロジェクト: lihaojia24/pytorch-dt
def transform_train(img, boxes, labels):
    img = random_distort(img)
    # if random.random() < 0.5:
    #     img, boxes = random_paste(img, boxes, max_ratio=4, fill=(123, 116, 103))
    img, boxes, labels = random_crop(img, boxes, labels)
    img, boxes = resize(img, boxes, size=(img_size,img_size), random_interpolation=True)
    img, boxes = random_flip(img, boxes)
    img = transforms.Compose([
        transforms.ToTensor(),
        transforms.Normalize((0.4140, 0.4265, 0.4172), (0.2646, 0.2683, 0.2751))
    ])(img)
    boxes, labels = box_coder.encode(boxes, labels)
    return img, boxes, labels