Exemplo n.º 1
0
def pixel_aug(p=.5):
    print('[DATA]: pixel aug')

    from albumentations import JpegCompression, Blur, Downscale, CLAHE, HueSaturationValue, \
        RandomBrightnessContrast, IAAAdditiveGaussianNoise, GaussNoise, GaussianBlur, MedianBlur, MotionBlur, \
        Compose, OneOf
    from random import sample, randint, uniform

    return Compose([
        # Jpeg Compression
        OneOf([
            JpegCompression(quality_lower=20, quality_upper=99, p=1)
        ], p=0.2),
        # Gaussian Noise
        OneOf([
            IAAAdditiveGaussianNoise(loc=randint(1, 9), p=1),
            GaussNoise(mean=uniform(0, 10.0), p=1),
        ], p=0.3),
        # Blur
        OneOf([
            GaussianBlur(blur_limit=15, p=1),
            MotionBlur(blur_limit=19, p=1),
            Downscale(scale_min=0.3, scale_max=0.99, p=1),
            Blur(blur_limit=15, p=1),
            MedianBlur(blur_limit=9, p=1)
        ], p=0.4),
        # Color
        OneOf([
            CLAHE(clip_limit=4.0, p=1),
            HueSaturationValue(p=1),
            RandomBrightnessContrast(p=1),
        ], p=0.1)
    ], p=p)
Exemplo n.º 2
0
def strong_aug(p=.5):
    return Compose([
        JpegCompression(p=0.9),
        HorizontalFlip(p=0.5),
        OneOf([
            IAAAdditiveGaussianNoise(),
            GaussNoise(),
        ], p=0.5),
        OneOf([
            MotionBlur(p=.2),
            MedianBlur(blur_limit=3, p=.1),
            Blur(blur_limit=3, p=.1),
        ],
              p=0.5),
        ShiftScaleRotate(
            shift_limit=0.0625, scale_limit=0.2, rotate_limit=15, p=.5),
        OneOf([
            CLAHE(clip_limit=2),
            IAASharpen(),
            IAAEmboss(),
            RandomContrast(),
            RandomBrightness(),
        ],
              p=0.5),
        HueSaturationValue(p=0.5),
    ],
                   p=p)
def hard_transform(image_size=224, p=0.5):
    transforms = [
        Cutout(
            num_holes=4,
            max_w_size=image_size // 4,
            max_h_size=image_size // 4,
            p=p
        ),
        ShiftScaleRotate(
            shift_limit=0.1,
            scale_limit=0.1,
            rotate_limit=15,
            border_mode=cv2.BORDER_REFLECT,
            p=p
        ),
        IAAPerspective(scale=(0.02, 0.05), p=p),
        OneOf(
            [
                HueSaturationValue(p=p),
                ToGray(p=p),
                RGBShift(p=p),
                ChannelShuffle(p=p),
            ]
        ),
        RandomBrightnessContrast(
            brightness_limit=0.5, contrast_limit=0.5, p=p
        ),
        RandomGamma(p=p),
        CLAHE(p=p),
        JpegCompression(quality_lower=50, p=p),
    ]
    transforms = Compose(transforms)
    return transforms
Exemplo n.º 4
0
def select_aug(atype, param, p=1):
    from albumentations import JpegCompression, Blur, Downscale, CLAHE, HueSaturationValue, \
        RandomBrightnessContrast, IAAAdditiveGaussianNoise, GaussNoise, GaussianBlur, MedianBlur, MotionBlur

    if atype == 'JpegCompression':
        trans_aug = JpegCompression(quality_lower=param, quality_upper=param, p=p)  # strong_aug_pixel()
    elif atype == 'Blur':
        trans_aug = Blur(blur_limit=param, p=p)
    elif atype == 'Downscale':
        trans_aug = Downscale(scale_min=param, scale_max=param, p=p)
    elif atype == 'CLAHE':
        trans_aug = CLAHE(clip_limit=param, p=p)
    elif atype == 'HueSaturationValue':
        trans_aug = HueSaturationValue(hue_shift_limit=param, sat_shift_limit=param, val_shift_limit=param, p=p)
    elif atype == 'RandomBrightnessContrast':
        trans_aug = RandomBrightnessContrast(brightness_limit=param, contrast_limit=param, p=p)
    elif atype == 'IAAAdditiveGaussianNoise':
        trans_aug = IAAAdditiveGaussianNoise(loc=param, p=p)
    elif atype == 'GaussNoise':
        trans_aug = GaussNoise(mean=param, p=p)
    elif atype == 'GaussianBlur':
        trans_aug = GaussianBlur(blur_limit=param, p=p)
    elif atype == 'MedianBlur':
        trans_aug = MedianBlur(blur_limit=param, p=p)
    elif atype == 'MotionBlur':
        trans_aug = MotionBlur(blur_limit=param, p=p)
    else:
        raise NotImplementedError(atype)
    
    aug = trans_aug
    
    return aug
Exemplo n.º 5
0
def hard_transform(image_size: int = 256, p: float = 0.5, **kwargs):
    """Hard augmentations (on training)"""
    _add_transform_default_params(kwargs)

    transforms = Compose([
        ShiftScaleRotate(
            shift_limit=0.1,
            scale_limit=0.1,
            rotate_limit=15,
            border_mode=cv2.BORDER_REFLECT,
            p=p,
        ),
        IAAPerspective(scale=(0.02, 0.05), p=p),
        OneOf([
            HueSaturationValue(p=p),
            ToGray(p=p),
            RGBShift(p=p),
            ChannelShuffle(p=p),
        ]),
        RandomBrightnessContrast(brightness_limit=0.5, contrast_limit=0.5,
                                 p=p),
        RandomGamma(p=p),
        CLAHE(p=p),
        JpegCompression(quality_lower=50, p=p),
        PadIfNeeded(image_size, image_size, border_mode=cv2.BORDER_CONSTANT),
    ], **kwargs)
    return transforms
Exemplo n.º 6
0
def hard_transform(image_size: int = 256, p: float = 0.5):
    """Hard augmentations"""
    transforms = Compose([
        ShiftScaleRotate(
            shift_limit=0.1,
            scale_limit=0.1,
            rotate_limit=15,
            border_mode=cv2.BORDER_REFLECT,
            p=p,
        ),
        IAAPerspective(scale=(0.02, 0.05), p=p),
        OneOf([
            HueSaturationValue(p=p),
            ToGray(p=p),
            RGBShift(p=p),
            ChannelShuffle(p=p),
        ]),
        RandomBrightnessContrast(
            brightness_limit=0.5, contrast_limit=0.5, p=p
        ),
        RandomGamma(p=p),
        CLAHE(p=p),
        JpegCompression(quality_lower=50, p=p),
    ])
    return transforms
def base_transform(height, width, mappings, p=2 / 3):
    return Compose([
        OneOf([
            JpegCompression(quality_lower=20, quality_upper=70, p=0.5),
            Downscale(scale_min=0.25, scale_max=0.50, interpolation=1, p=0.5),
            Resize(height // 4, width // 4, interpolation=1, p=0.5)
        ],
              p=1.0),
        HorizontalFlip(p=0.5)
    ],
                   p=p,
                   additional_targets=mappings)
Exemplo n.º 8
0
    def get_transforms(stage: str = None,
                       mode: str = None,
                       input_size: int = 224):
        train_image_transforms = [
            OpticalDistortion(distort_limit=0.3, p=0.3),
            JpegCompression(quality_lower=50, p=0.8),
            HorizontalFlip(p=0.5),
            MotionBlur(p=0.5),
            ShiftScaleRotate(shift_limit=0.1,
                             scale_limit=0.2,
                             rotate_limit=20,
                             p=0.5),
            RandomBrightnessContrast(brightness_limit=0.3,
                                     contrast_limit=0.2,
                                     p=0.4),
            HueSaturationValue(hue_shift_limit=3,
                               sat_shift_limit=20,
                               val_shift_limit=30,
                               p=0.4),
            CLAHE(clip_limit=2, p=0.3)
        ]
        infer_image_transforms = [
            Resize(input_size, input_size),
            Normalize(),
            ToTorchTensor(p=1.0)
        ]
        stack = TorchStack()

        train_images_fn = GroupTransform(transforms=train_image_transforms +
                                         infer_image_transforms)
        valid_images_fn = GroupTransform(transforms=infer_image_transforms)

        def train_aug_fn(images):
            images = train_images_fn(images)
            images = stack(images)
            return images

        def valid_aug_fn(images):
            images = valid_images_fn(images)
            images = stack(images)
            return images

        train_transforms = Augmentor(dict_key="features",
                                     augment_fn=lambda x: train_aug_fn(x))

        valid_transforms = Augmentor(dict_key="features",
                                     augment_fn=lambda x: valid_aug_fn(x))

        if mode == "train":
            return train_transforms
        else:
            return valid_transforms
Exemplo n.º 9
0
def aug(p=1):
    return Compose([
        OneOf([
            HorizontalFlip(),
            VerticalFlip(),
            ShiftScaleRotate(shift_limit=0.05, scale_limit=0.2, rotate_limit=90),
            RandomRotate90()
        ], p=0.75),
        JpegCompression(p=0.25),
        CLAHE(p=0.25),
        RandomBrightnessContrast(brightness_limit=0.3, contrast_limit=0.2, p=0.25),
        MedianBlur(p=0.25)
    ], p=p)
Exemplo n.º 10
0
 def augment_lr_image(p=.5):
     return Compose([
         OneOf([
             # IAAAdditiveGaussianNoise(),
             # GaussNoise(),
             JpegCompression()
         ], p=0.5),
         OneOf([
             MotionBlur(p=.2),
             MedianBlur(blur_limit=3, p=0.1),
             Blur(blur_limit=3, p=0.1),
         ], p=0.2)
     ], p=p)
Exemplo n.º 11
0
def strong_aug(p=1):
    return Compose(
        [
            OneOf([
                JpegCompression(quality_lower=15, quality_upper=40, p=1),
                Downscale(scale_min=0.5, scale_max=0.9, p=1)
            ],
                  p=0.5),
            #OneOf([IAAAdditiveGaussianNoise(p=1), GaussNoise(p=1)], p=0.15),
            RandomBrightness(p=0.15),
            #OneOf([MotionBlur(blur_limit=5,p=1),MedianBlur(blur_limit=5, p=1),Blur(blur_limit=5, p=1)], p=0.15),
            HorizontalFlip(p=0.5),
        ],
        p=p)
Exemplo n.º 12
0
def create_train_image_generator(X_train,
                                 y_train,
                                 batch=BATCH,
                                 supervision=False):
    aug = Compose([
        VerticalFlip(p=0.25),
        HorizontalFlip(p=0.5),
        OneOf([
            ElasticTransform(p=0.5, alpha=1, sigma=50, alpha_affine=50),
            GridDistortion(p=0.5),
            ShiftScaleRotate(p=0.5),
        ],
              p=0.5),
        CLAHE(p=0.5),
        RandomContrast(p=0.5),
        RandomBrightness(p=0.5),
        RandomGamma(p=0.5),
        JpegCompression(p=0.5),
        Blur(p=0.5)
    ])

    while True:
        image_rgb = []
        image_mask = []
        k = np.random.randint(0, 100)
        np.random.seed(k)
        np.random.shuffle(X_train)
        np.random.seed(k)
        np.random.shuffle(y_train)
        for i in range(X_train.shape[0]):
            augmented = aug(image=X_train[i], mask=y_train[i, ..., 0])
            image_rgb += [augmented['image']]
            image_mask += [augmented['mask']]
            if len(image_rgb) == batch:
                if supervision:
                    m = np.expand_dims(np.stack(image_mask, 0), -1) / 255.
                    yield np.stack(image_rgb, 0) / 255., {
                        'output_1': m,
                        'output_2': m,
                        'output_3': m,
                        'output_4': m
                    }
                else:
                    yield np.stack(image_rgb, 0) / 255., np.expand_dims(
                        np.stack(image_mask, 0), -1) / 255.

                image_rgb, image_mask = [], []

    return train_generator
Exemplo n.º 13
0
def simple_aug(p=0.5):
    return Compose([
        HorizontalFlip(p=0.5),
        ShiftScaleRotate(rotate_limit=10, scale_limit=0.15, p=0.5),
        OneOf([
            JpegCompression(quality_lower=80),
            Blur(),
        ], p=0.5),
        OneOf([
            CLAHE(),
            RandomGamma(),
            RandomContrast(),
            RandomBrightness(),
        ], p=0.5)
    ], p=p)
Exemplo n.º 14
0
def simple_aug(p=0.5):
    return Compose([
        #HorizontalFlip(p=0.5),
        ShiftScaleRotate(rotate_limit=10, scale_limit=0.15, p=0.5, border_mode=cv2.BORDER_CONSTANT, value=[0,0,0]),
        OneOf([
            JpegCompression(quality_lower=80),
            Blur(),
        ], p=0.5),
        OneOf([
            CLAHE(),
            RandomGamma(),
            RandomContrast(),
            RandomBrightness(),
        ], p=0.5)
    ], p=p)
Exemplo n.º 15
0
def train_transform(image_size=224):
    transforms = [
        LongestMaxSize(max_size=image_size),
        PadIfNeeded(image_size, image_size, border_mode=cv2.BORDER_CONSTANT),
        ShiftScaleRotate(shift_limit=0.1,
                         scale_limit=0.1,
                         rotate_limit=45,
                         border_mode=cv2.BORDER_REFLECT,
                         p=0.5),
        RandomRotate90(),
        JpegCompression(quality_lower=50),
        post_transform()
    ]
    transforms = Compose(transforms)
    return transforms
Exemplo n.º 16
0
def augment(image, mask):
    original_height, original_width = image.shape[:2]
    aug = PadIfNeeded(p=1, min_height=128, min_width=128)
    augmented = aug(image=image, mask=mask)

    image_padded = augmented['image']
    mask_padded = augmented['mask']

    aug = Compose([
        OneOf([RandomSizedCrop(p=0.5, min_max_height=(int(original_height/4), int(original_height/2)),
                              height=original_height, width=original_width),
               PadIfNeeded(min_height=original_height,
                           min_width=original_width, p=0.5)], p=1),
        VerticalFlip(p=0.5),
        RandomRotate90(p=0.5),
        HorizontalFlip(p=0.5),
        OneOf([
            ElasticTransform(p=0.5, alpha=120, sigma=120 * random.uniform(0.07,0.2),
                             alpha_affine=120 * random.uniform(0.03,0.5)),
            GridDistortion(p=0.5),
            OpticalDistortion(p=1, distort_limit=0.2, shift_limit=0.2)
        ], p=0.8),
        CLAHE(p=0.8),
        RandomContrast(p=0.8),
        RandomBrightness(p=0.8),
        RandomGamma(p=0.8),
        RGBShift(p=0.1),
        HueSaturationValue(p=0.1),
        ChannelShuffle(p=0.1),
        Blur(p=0.3),
        MedianBlur(p=0.3),
        JpegCompression(p=0.8)
    ])

    augmented = aug(image=image_padded, mask=mask_padded)
    image_v = augmented['image']
    mask_v = augmented['mask']

    aug = PadIfNeeded(p=1, min_height=1024, min_width=1024)
    augmented = aug(image=image_v, mask=mask_v)

    image_v = augmented['image']
    mask_v = augmented['mask']

    # image_v = cv2.resize(image_v, (64, 64))
    # mask_v = cv2.resize(image_v, (64, 64))
    return image_v, mask_v
Exemplo n.º 17
0
def aug(image):

    image = image.cpu().numpy()

    alpha = 2.1
    aug = RandomBrightness(p=1)
    img1 = aug.apply(image, alpha=alpha)

    angle = 286
    aug = Rotate(p=1)
    img2 = aug.apply(image, angle=angle)

    alpha = 203
    alpha_affine = 106
    sigma = 166
    aug = ElasticTransform(p=1)
    image_for_augmentation = image.copy()
    img3 = aug.apply(image_for_augmentation,
                     alpha=alpha,
                     sigma=sigma,
                     alpha_affine=alpha_affine)

    distort_limit = 0.2
    shift_limit = 0.15
    aug = OpticalDistortion(p=1)
    image_for_augmentation = image.copy()
    img4 = aug.apply(image_for_augmentation,
                     k=distort_limit,
                     dx=shift_limit,
                     dy=shift_limit)

    quality = 4
    aug = JpegCompression(p=1)
    img5 = aug.apply(image, quality=quality)

    gamma = 37
    aug = RandomGamma(p=1)
    image_for_augmentation = image.copy()
    img6 = aug.apply(image_for_augmentation, gamma=gamma / 100)

    return torch.tensor(np.stack([img1, img2, img3, img4, img5,
                                  img6])).to(device)
Exemplo n.º 18
0
def even_more_transform(height, width, mappings, p=2 / 3):
    scale = random.randint(2, 4)
    return Compose([
        OneOf([
            JpegCompression(quality_lower=20, quality_upper=70, p=0.5),
            Downscale(scale_min=0.25, scale_max=0.50, interpolation=1, p=0.5),
            Resize(height // scale, width // scale, interpolation=1, p=1.0)
        ],
              p=0.6),
        HorizontalFlip(p=0.5),
        A.augmentations.transforms.GaussNoise(p=0.2),
        A.RandomBrightnessContrast(p=0.2),
        A.RandomGamma(p=0.2),
        A.CLAHE(p=0.2),
        A.ChannelShuffle(p=0.2),
        A.MultiplicativeNoise(multiplier=[0.5, 1.5], elementwise=True, p=0.1),
        A.HueSaturationValue(
            hue_shift_limit=10, sat_shift_limit=10, val_shift_limit=10, p=0.2),
    ],
                   p=0.9,
                   additional_targets=mappings)
Exemplo n.º 19
0
def hard_transform():
    transforms = [
        ShiftScaleRotate(shift_limit=0.1,
                         scale_limit=0.1,
                         rotate_limit=15,
                         border_mode=cv2.BORDER_REFLECT,
                         p=0.5),
        IAAPerspective(scale=(0.02, 0.05), p=0.3),
        RandomBrightnessContrast(brightness_limit=0.2,
                                 contrast_limit=0.2,
                                 p=0.3),
        RandomGamma(gamma_limit=(85, 115), p=0.3),
        HueSaturationValue(p=0.3),
        ChannelShuffle(p=0.5),
        ToGray(p=0.2),
        CLAHE(p=0.3),
        RGBShift(p=0.3),
        JpegCompression(quality_lower=50),
    ]
    transforms = Compose(transforms)
    return transforms
Exemplo n.º 20
0
    def get_transforms(stage: str = None, mode: str = None, size: int = 224):
        if mode == 'train':
            transforms = [
                Resize(size, size),
                OneOf([
                    RandomBrightnessContrast(brightness_limit=0.5,
                                             contrast_limit=0.5),
                    RandomGamma(),
                    CLAHE(),
                ],
                      p=0.5),
                ShiftScaleRotate(rotate_limit=45),
                OneOf([Blur(), MotionBlur()], p=0.5),
                JpegCompression(quality_lower=10),
                Normalize(),
                ToTensor()
            ]
        else:
            transforms = [Resize(size, size), Normalize(), ToTensor()]

        return Compose(transforms=transforms)
Exemplo n.º 21
0
    def initialize(self, config, filename):
        self.config = config
        self.train = 'train' in filename

        self.A_paths = self.get_files(filename)
        #         self.boxes = self.get_boxes()

        self.A_size = self.A_paths.shape[0]
        self.batch_size = config['batch_size']
        self.size = config['image_size']
        self.transform = Compose([
            #             Resize(self.size[0], self.size[1]),
            ShiftScaleRotate(shift_limit=0.0,
                             scale_limit=(0.0, 0.1),
                             rotate_limit=10,
                             p=.3),
            OneOf([
                IAAAdditiveGaussianNoise(),
                GaussNoise(),
            ], p=0.4),
            OneOf([
                CLAHE(clip_limit=2),
                IAASharpen(),
                IAAEmboss(),
                RandomContrast(),
                RandomBrightness(),
                RandomGamma()
            ],
                  p=0.6),
            OneOf([
                RGBShift(),
                HueSaturationValue(),
            ], p=0.6),
            JpegCompression(quality_lower=40, quality_upper=100, p=0.3),
            Normalize(
                mean=[0.485, 0.456, 0.406],
                std=[0.229, 0.224, 0.225],
            ),
        ])
        self.used_classes = deque()
Exemplo n.º 22
0
def strong_aug_pixel(p=.5):
    print('[DATA]: strong aug pixel')

    from albumentations import (
    # HorizontalFlip, IAAPerspective, ShiftScaleRotate, CLAHE, RandomRotate90,
    Transpose, ShiftScaleRotate, Blur, OpticalDistortion, GridDistortion, HueSaturationValue, MultiplicativeNoise,
    IAAAdditiveGaussianNoise, GaussNoise, MotionBlur, MedianBlur, RandomBrightnessContrast, IAAPiecewiseAffine,
    IAASharpen, IAAEmboss, Flip, OneOf, Compose, JpegCompression, CLAHE)

    return Compose([
        # RandomRotate90(),
        # Flip(),
        # Transpose(),
        OneOf([
            MultiplicativeNoise(multiplier=[0.5, 1.5], per_channel=True),
            JpegCompression(quality_lower=39, quality_upper=80)
        ], p=0.2),
        OneOf([
            IAAAdditiveGaussianNoise(),
            GaussNoise(),
        ], p=0.2),
        OneOf([
            MotionBlur(p=.2),
            MedianBlur(blur_limit=3, p=0.1),
            Blur(blur_limit=3, p=0.1),
        ], p=0.2),
        # ShiftScaleRotate(shift_limit=0.0625, scale_limit=0.2, rotate_limit=45, p=0.2),
        # OneOf([
        #     OpticalDistortion(p=0.3),
        #     GridDistortion(p=.1),
        #     IAAPiecewiseAffine(p=0.3),
        # ], p=0.2),
        OneOf([
            CLAHE(clip_limit=2),
            IAASharpen(),
            IAAEmboss(),
            RandomBrightnessContrast(),            
        ], p=0.3),
        HueSaturationValue(p=0.3),
    ], p=p)
Exemplo n.º 23
0
def strong_aug(p=0.8):
    return Compose([
        # RandomRotate90(),
        # Flip(),
        # Transpose(),
        OneOf([
            IAAAdditiveGaussianNoise(),
            GaussNoise(),
        ], p=0.2),
        OneOf([ #模糊
            MotionBlur(p=0.5),
            MedianBlur(blur_limit=3, p=0.5),
            Blur(blur_limit=3, p=0.5),
            JpegCompression(p=1,quality_lower=7,quality_upper=40)
        ], p=1),
        # ShiftScaleRotate(shift_limit=0.0625, scale_limit=0.2, rotate_limit=45, p=0.2),
        OneOf([ 
            IAAPiecewiseAffine(p=1,scale=(0.005, 0.01), nb_rows=4, nb_cols=4),
            IAAPerspective(p=1,scale=(random.uniform(0.01,0.03),random.uniform(0.01, 0.03))),
            ElasticTransform(p=1,alpha=random.randint(50,100), sigma=random.randint(8,13), alpha_affine=0,border_mode=3),
        ], p=0.2),
        OneOf([ 
            ElasticTransform(p=1,alpha=random.randint(50,100), sigma=random.randint(8,13), alpha_affine=0,border_mode=3),
        ], p=0.6),
        OneOf([ 
            OpticalDistortion(p=1,distort_limit=0.2,border_mode=3),
            # GridDistortion(p=1,distort_limit=0.1,border_mode=3),
        ], p=0.1),        
        OneOf([
            CLAHE(clip_limit=2,p=0.5),
            # IAASharpen(),
            IAAEmboss(p=0.5),
            RandomBrightnessContrast(p=1), #随机调整亮度饱和度,和下一个区别?
            HueSaturationValue(p=1), #随机调整hsv值
            RGBShift(p=0.5), #随机调整rgb值
            ChannelShuffle(p=0.5), #RGB通道调换
            InvertImg(p=0.1), #255-像素值,反转图像
        ], p=0.5),    

    ], p=p) 
Exemplo n.º 24
0
def mix_transform2(resize):
    return Compose([
        pre_transform(resize=resize),
        OneOf([
            GaussNoise(p=.9),
            MotionBlur(p=.9),
            MedianBlur(p=.9),
        ], p=.6),
        OneOf([
            RandomContrast(p=.9),
            RandomBrightness(p=.9),
        ], p=.6),
        OneOf([ToGray(p=.9), JpegCompression(p=.9)], p=.6),
        HorizontalFlip(p=.6),
        ShiftScaleRotate(shift_limit=0.0625,
                         scale_limit=0,
                         rotate_limit=10,
                         interpolation=1,
                         border_mode=4,
                         p=0.6),
        post_transform(),
    ])
Exemplo n.º 25
0
 def strong_aug(w, h, p=1):
     return Compose(
         [
             #RandomRotate90(),
             #Flip(),
             HorizontalFlip(p=0.5),
             #Rotate(limit=30, p=0.5)
             #Transpose(),
             #IAAAdditiveGaussianNoise(),
             #GaussNoise(var_limit=(30, 80.0), mean=0, always_apply=False, p=0.5),
             JpegCompression(
                 quality_lower=3, quality_upper=100, p=0.5),
             OneOf([
                 MotionBlur(),
                 MedianBlur(blur_limit=10),
                 Blur(blur_limit=10)
             ],
                   p=1),
             ShiftScaleRotate(shift_limit=0.0625,
                              scale_limit=0.2,
                              rotate_limit=90,
                              p=.8),
             RGBShift(r_shift_limit=20,
                      g_shift_limit=20,
                      b_shift_limit=20,
                      p=0.5),
             #RandomGamma(gamma_limit=30, p=1),
             #ToGray(p=0.1),
             #CenterCrop(height=random.randint(int(h*0.7), int(h*0.9)), width=random.randint(int(w*0.7), int(w*0.9)), p=0.5),
             CLAHE(clip_limit=2),
             IAASharpen(),
             #Flip(p=0.5),
             #IAAEmboss(),
             #RandomContrast(),
             RandomBrightness(),
             #HueSaturationValue(hue_shift_limit=172, sat_shift_limit=20, val_shift_limit=27, p=0.5)
             #HueSaturationValue(p=0.3),
         ],
         p=p)
Exemplo n.º 26
0
def strong_aug(p=0.75):
    return Compose(
        [
            ShiftScaleRotate(scale_limit=0.1, rotate_limit=90),
            Transpose(),
            #IAAAffine(shear=0.1),
            #IAAPerspective(),
            Cutout(num_holes=20, max_h_size=8, max_w_size=8),
            HorizontalFlip(),
            VerticalFlip(),
            GaussNoise(),
            JpegCompression(),
            #RandomShadow(shadow_roi=(0, 0, 1, 1), p=0.75),
            OneOf([MotionBlur(), GaussianBlur()]),
            OneOf([ToGray(), ToSepia()]),
            RandomBrightnessContrast(brightness_limit=0.75, p=0.75)
        ],
        bbox_params=BboxParams("pascal_voc",
                               label_fields=["category_id"],
                               min_area=0.0,
                               min_visibility=0.5),
        p=p)
Exemplo n.º 27
0
def strong_aug(image, p=0.5):
    image2 = Compose(
        [  #加躁
            OneOf([
                IAAAdditiveGaussianNoise(),
                GaussNoise(),
                ISONoise(),
            ],
                  p=0.2),
            OneOf(
                [  #模糊
                    MotionBlur(p=0.1),
                    MedianBlur(blur_limit=3, p=0.1),
                    Blur(blur_limit=3, p=0.1),
                    JpegCompression(p=.1),
                ],
                p=0.2),
            OneOf(
                [  #锐化
                    CLAHE(clip_limit=2),
                    IAASharpen(),
                    IAAEmboss(),
                    RandomBrightnessContrast(),
                ],
                p=0.3),
            OneOf(
                [  #直方图均衡,对比度,色度变化,pca
                    HueSaturationValue(),
                    RandomBrightnessContrast(),
                    Equalize(),
                    # FancyPCA(),
                ],
                p=0.3),
            ToGray(p=0.1),
        ],
        p=p)(image=image)['image']
    return image2
Exemplo n.º 28
0
def strong_aug(p=1):
    return Compose(
        [
            Rotate(limit=20, p=0.8),
            #         RandomRotate90(),
            #         HorizontalFlip(p=0.4),
            #         Transpose(),
            OneOf([
                IAAAdditiveGaussianNoise(),
                GaussNoise(),
            ], p=0.7),
            OneOf([
                MotionBlur(p=.7),
                MedianBlur(blur_limit=7, p=0.7),
                Blur(blur_limit=7, p=0.7),
            ],
                  p=0.4),
            ShiftScaleRotate(
                shift_limit=0.0625, scale_limit=0.2, rotate_limit=35, p=0.2),
            OneOf([
                OpticalDistortion(p=0.3),
                GridDistortion(p=.1),
                IAAPiecewiseAffine(p=0.3),
            ],
                  p=0.4),
            OneOf([
                CLAHE(),
                IAASharpen(),
                IAAEmboss(),
                RandomBrightnessContrast(0.3, 0.7),
                JpegCompression(70),
                RandomBrightness(-0.6)
            ],
                  p=1),
            HueSaturationValue(p=0.3),
        ],
        p=p)
Exemplo n.º 29
0
 def __getitem__(self, idx):
     label1 = int(self.df[idx][1])
     c = str(self.df[idx][0])
     image = cv2.imread(c)
     image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
     image = RandomRotate90()(image=image)['image']
     image = Flip()(image=image)['image']
     image = JpegCompression(quality_lower=9,
                             quality_upper=10)(image=image)['image']
     image = Transpose()(image=image)['image']
     image = Downscale()(image=image)['image']
     image = IAAAdditiveGaussianNoise()(image=image)['image']
     image = Blur(blur_limit=7)(image=image)['image']
     image = ShiftScaleRotate(shift_limit=0.0625,
                              scale_limit=0.2,
                              rotate_limit=45)(image=image)['image']
     image = IAAPiecewiseAffine()(image=image)['image']
     image = RGBShift()(image=image)['image']
     image = RandomBrightnessContrast()(image=image)['image']
     image = HueSaturationValue()(image=image)['image']
     image = transforms.ToPILImage()(image)
     if self.transform:
         image = self.transform(image)
     return image, label1
Exemplo n.º 30
0
                      Blur(p=0.2)],
                     p=0.5)

StyleTfms = OneOf([
    MedianBlur(blur_limit=(3, 7), p=0.6),
    IAAEmboss(strength=(0.2, 0.99), p=0.4)
],
                  p=0.3)

WeatherTfms = RandomSunFlare(src_radius=80, p=0.1)

NoiseTfms = OneOf(
    [
        GaussNoise(p=0.6),
        IAAAdditiveGaussianNoise(p=0.4),  # stronger
        JpegCompression(quality_lower=25, quality_upper=55, p=0.2)
    ],
    p=0.25)

ColorTonesTfms = OneOf([ToSepia(), ToGray()], p=0.3)

ColorChannelTfms = OneOf(
    [ChannelShuffle(),
     HueSaturationValue(val_shift_limit=5),
     RGBShift()],
    p=0.3)

LightingTfms = OneOf(
    [RandomContrast(p=0.1),
     RandomBrightness(p=0.1),
     CLAHE(p=0.8)], p=0.3)