Ejemplo n.º 1
0
 def __init__(self, data_augmentation, hflip_prob=0.5, mean=(123.0, 117.0, 104.0)):
     if data_augmentation == "hflip":
         self.transforms = T.Compose(
             [
                 T.RandomHorizontalFlip(p=hflip_prob),
                 T.PILToTensor(),
                 T.ConvertImageDtype(torch.float),
             ]
         )
     elif data_augmentation == "ssd":
         self.transforms = T.Compose(
             [
                 T.RandomPhotometricDistort(),
                 T.RandomZoomOut(fill=list(mean)),
                 T.RandomIoUCrop(),
                 T.RandomHorizontalFlip(p=hflip_prob),
                 T.PILToTensor(),
                 T.ConvertImageDtype(torch.float),
             ]
         )
     elif data_augmentation == "ssdlite":
         self.transforms = T.Compose(
             [
                 T.RandomIoUCrop(),
                 T.RandomHorizontalFlip(p=hflip_prob),
                 T.PILToTensor(),
                 T.ConvertImageDtype(torch.float),
             ]
         )
     else:
         raise ValueError(f'Unknown data augmentation policy "{data_augmentation}"')
Ejemplo n.º 2
0
 def __init__(self,
              *,
              data_augmentation,
              hflip_prob=0.5,
              mean=(123.0, 117.0, 104.0)):
     if data_augmentation == "hflip":
         self.transforms = T.Compose([
             T.RandomHorizontalFlip(p=hflip_prob),
             T.PILToTensor(),
             T.ConvertImageDtype(torch.float),
         ])
     elif data_augmentation == "lsj":
         self.transforms = T.Compose([
             T.ScaleJitter(target_size=(1024, 1024)),
             T.FixedSizeCrop(size=(1024, 1024), fill=mean),
             T.RandomHorizontalFlip(p=hflip_prob),
             T.PILToTensor(),
             T.ConvertImageDtype(torch.float),
         ])
     elif data_augmentation == "multiscale":
         self.transforms = T.Compose([
             T.RandomShortestSize(min_size=(480, 512, 544, 576, 608, 640,
                                            672, 704, 736, 768, 800),
                                  max_size=1333),
             T.RandomHorizontalFlip(p=hflip_prob),
             T.PILToTensor(),
             T.ConvertImageDtype(torch.float),
         ])
     elif data_augmentation == "ssd":
         self.transforms = T.Compose([
             T.RandomPhotometricDistort(),
             T.RandomZoomOut(fill=list(mean)),
             T.RandomIoUCrop(),
             T.RandomHorizontalFlip(p=hflip_prob),
             T.PILToTensor(),
             T.ConvertImageDtype(torch.float),
         ])
     elif data_augmentation == "ssdlite":
         self.transforms = T.Compose([
             T.RandomIoUCrop(),
             T.RandomHorizontalFlip(p=hflip_prob),
             T.PILToTensor(),
             T.ConvertImageDtype(torch.float),
         ])
     else:
         raise ValueError(
             f'Unknown data augmentation policy "{data_augmentation}"')
Ejemplo n.º 3
0
    def __init__(self):
        super().__init__()

        self.transforms = T.Compose([
            T.PILToTensor(),
            T.ConvertImageDtype(torch.float32),
            T.Normalize(mean=0.5, std=0.5),  # map [0, 1] into [-1, 1]
            T.ValidateModelInput(),
        ])
Ejemplo n.º 4
0
 def __init__(self,
              base_size,
              mean=(0.485, 0.456, 0.406),
              std=(0.229, 0.224, 0.225)):
     self.transforms = T.Compose([
         T.RandomResize(base_size, base_size),
         T.PILToTensor(),
         T.ConvertImageDtype(torch.float),
         T.Normalize(mean=mean, std=std),
     ])
Ejemplo n.º 5
0
    def __init__(
        self,
        *,
        # RandomResizeAndCrop params
        crop_size,
        min_scale=-0.2,
        max_scale=0.5,
        stretch_prob=0.8,
        # AsymmetricColorJitter params
        brightness=0.4,
        contrast=0.4,
        saturation=0.4,
        hue=0.5 / 3.14,
        # Random[H,V]Flip params
        asymmetric_jitter_prob=0.2,
        do_flip=True,
    ):
        super().__init__()

        transforms = [
            T.PILToTensor(),
            T.AsymmetricColorJitter(brightness=brightness,
                                    contrast=contrast,
                                    saturation=saturation,
                                    hue=hue,
                                    p=asymmetric_jitter_prob),
            T.RandomResizeAndCrop(crop_size=crop_size,
                                  min_scale=min_scale,
                                  max_scale=max_scale,
                                  stretch_prob=stretch_prob),
        ]

        if do_flip:
            transforms += [
                T.RandomHorizontalFlip(p=0.5),
                T.RandomVerticalFlip(p=0.1)
            ]

        transforms += [
            T.ConvertImageDtype(torch.float32),
            T.Normalize(mean=0.5, std=0.5),  # map [0, 1] into [-1, 1]
            T.RandomErasing(max_erase=2),
            T.MakeValidFlowMask(),
            T.ValidateModelInput(),
        ]
        self.transforms = T.Compose(transforms)
Ejemplo n.º 6
0
    def __init__(self,
                 base_size,
                 mean=(0.485, 0.456, 0.406),
                 std=(0.229, 0.224, 0.225),
                 contrast=1,
                 brightness=1,
                 sigma=1):
        self.contrast_initial = contrast
        self.contrast_final = contrast
        if (contrast == 1):
            self.contrast_final = contrast
        else:
            self.contrast_final = self.contrast_initial - 1

        self.brightness_initial = brightness
        self.brightness_final = brightness
        if (brightness == 1):
            self.brightness_final = brightness
        else:
            self.brightness_final = self.brightness_initial - 1

        self.sigma_initial = sigma
        self.sigma_final = sigma
        if (sigma == 1):
            self.sigma_final = sigma
        else:
            self.sigma_final = self.sigma_initial - 1

        print("Contrast: ({}, {})".format(self.contrast_final,
                                          self.contrast_initial))
        print("Brightness: ({}, {})".format(self.brightness_final,
                                            self.brightness_initial))
        print("Sigma: ({}, {})".format(self.sigma_final, self.sigma_initial))

        self.transforms = T.Compose([
            T.RandomResize(base_size, base_size),
            T.PILToTensor(),
            T.ConvertImageDtype(torch.float),
            T.ColorJitter(contrast=(self.contrast_final,
                                    self.contrast_initial),
                          brightness=(self.brightness_final,
                                      self.brightness_initial)),
            #T.GaussianBlur(kernel_size=19, sigma=(self.sigma_final, self.sigma_initial)),
            T.Normalize(mean=mean, std=std),
        ])
Ejemplo n.º 7
0
    def __init__(self,
                 base_size,
                 crop_size,
                 hflip_prob=0.5,
                 mean=(0.485, 0.456, 0.406),
                 std=(0.229, 0.224, 0.225)):
        min_size = int(0.5 * base_size)
        max_size = int(2.0 * base_size)

        trans = [T.RandomResize(min_size, max_size)]
        if hflip_prob > 0:
            trans.append(T.RandomHorizontalFlip(hflip_prob))
        trans.extend([
            T.RandomCrop(crop_size),
            T.PILToTensor(),
            T.ConvertImageDtype(torch.float),
            T.Normalize(mean=mean, std=std),
        ])
        self.transforms = T.Compose(trans)
Ejemplo n.º 8
0
 def __init__(self):
     self.transforms = T.Compose([
         T.PILToTensor(),
         T.ConvertImageDtype(torch.float),
     ])