Python albumentations.RandomBrightnessContrast() Examples
The following are 7
code examples of albumentations.RandomBrightnessContrast().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
albumentations
, or try the search function
.
Example #1
Source File: test_serialization.py From albumentations with MIT License | 6 votes |
def test_transform_pipeline_serialization(seed, image, mask): aug = A.Compose( [ A.OneOrOther( A.Compose( [ A.Resize(1024, 1024), A.RandomSizedCrop(min_max_height=(256, 1024), height=512, width=512, p=1), A.OneOf( [ A.RandomSizedCrop(min_max_height=(256, 512), height=384, width=384, p=0.5), A.RandomSizedCrop(min_max_height=(256, 512), height=512, width=512, p=0.5), ] ), ] ), A.Compose( [ A.Resize(1024, 1024), A.RandomSizedCrop(min_max_height=(256, 1025), height=256, width=256, p=1), A.OneOf([A.HueSaturationValue(p=0.5), A.RGBShift(p=0.7)], p=1), ] ), ), A.HorizontalFlip(p=1), A.RandomBrightnessContrast(p=0.5), ] ) serialized_aug = A.to_dict(aug) deserialized_aug = A.from_dict(serialized_aug) set_seed(seed) aug_data = aug(image=image, mask=mask) set_seed(seed) deserialized_aug_data = deserialized_aug(image=image, mask=mask) assert np.array_equal(aug_data["image"], deserialized_aug_data["image"]) assert np.array_equal(aug_data["mask"], deserialized_aug_data["mask"])
Example #2
Source File: test_serialization.py From albumentations with MIT License | 6 votes |
def test_transform_pipeline_serialization_with_bboxes(seed, image, bboxes, bbox_format, labels): aug = A.Compose( [ A.OneOrOther( A.Compose([A.RandomRotate90(), A.OneOf([A.HorizontalFlip(p=0.5), A.VerticalFlip(p=0.5)])]), A.Compose([A.Rotate(p=0.5), A.OneOf([A.HueSaturationValue(p=0.5), A.RGBShift(p=0.7)], p=1)]), ), A.HorizontalFlip(p=1), A.RandomBrightnessContrast(p=0.5), ], bbox_params={"format": bbox_format, "label_fields": ["labels"]}, ) serialized_aug = A.to_dict(aug) deserialized_aug = A.from_dict(serialized_aug) set_seed(seed) aug_data = aug(image=image, bboxes=bboxes, labels=labels) set_seed(seed) deserialized_aug_data = deserialized_aug(image=image, bboxes=bboxes, labels=labels) assert np.array_equal(aug_data["image"], deserialized_aug_data["image"]) assert np.array_equal(aug_data["bboxes"], deserialized_aug_data["bboxes"])
Example #3
Source File: test_serialization.py From albumentations with MIT License | 6 votes |
def test_transform_pipeline_serialization_with_keypoints(seed, image, keypoints, keypoint_format, labels): aug = A.Compose( [ A.OneOrOther( A.Compose([A.RandomRotate90(), A.OneOf([A.HorizontalFlip(p=0.5), A.VerticalFlip(p=0.5)])]), A.Compose([A.Rotate(p=0.5), A.OneOf([A.HueSaturationValue(p=0.5), A.RGBShift(p=0.7)], p=1)]), ), A.HorizontalFlip(p=1), A.RandomBrightnessContrast(p=0.5), ], keypoint_params={"format": keypoint_format, "label_fields": ["labels"]}, ) serialized_aug = A.to_dict(aug) deserialized_aug = A.from_dict(serialized_aug) set_seed(seed) aug_data = aug(image=image, keypoints=keypoints, labels=labels) set_seed(seed) deserialized_aug_data = deserialized_aug(image=image, keypoints=keypoints, labels=labels) assert np.array_equal(aug_data["image"], deserialized_aug_data["image"]) assert np.array_equal(aug_data["keypoints"], deserialized_aug_data["keypoints"])
Example #4
Source File: dataset.py From kaggle-kuzushiji-2019 with MIT License | 5 votes |
def get_transform(train: bool) -> Callable: train_initial_size = 2048 crop_min_max_height = (400, 533) crop_width = 512 crop_height = 384 if train: transforms = [ A.LongestMaxSize(max_size=train_initial_size), A.RandomSizedCrop( min_max_height=crop_min_max_height, width=crop_width, height=crop_height, w2h_ratio=crop_width / crop_height, ), A.HueSaturationValue( hue_shift_limit=7, sat_shift_limit=10, val_shift_limit=10, ), A.RandomBrightnessContrast(), A.RandomGamma(), ] else: test_size = int(train_initial_size * crop_height / np.mean(crop_min_max_height)) print(f'Test image max size {test_size} px') transforms = [ A.LongestMaxSize(max_size=test_size), ] transforms.extend([ ToTensor(), ]) return A.Compose( transforms, bbox_params={ 'format': 'coco', 'min_area': 0, 'min_visibility': 0.5, 'label_fields': ['labels'], }, )
Example #5
Source File: test_transforms.py From albumentations with MIT License | 5 votes |
def test_force_apply(): """ Unit test for https://github.com/albumentations-team/albumentations/issues/189 """ aug = A.Compose( [ A.OneOrOther( A.Compose( [ A.RandomSizedCrop(min_max_height=(256, 1025), height=512, width=512, p=1), A.OneOf( [ A.RandomSizedCrop(min_max_height=(256, 512), height=384, width=384, p=0.5), A.RandomSizedCrop(min_max_height=(256, 512), height=512, width=512, p=0.5), ] ), ] ), A.Compose( [ A.RandomSizedCrop(min_max_height=(256, 1025), height=256, width=256, p=1), A.OneOf([A.HueSaturationValue(p=0.5), A.RGBShift(p=0.7)], p=1), ] ), ), A.HorizontalFlip(p=1), A.RandomBrightnessContrast(p=0.5), ] ) res = aug(image=np.zeros((1248, 1248, 3), dtype=np.uint8)) assert res["image"].shape[0] in (256, 384, 512) assert res["image"].shape[1] in (256, 384, 512)
Example #6
Source File: augmentation.py From EfficientDet.Pytorch with MIT License | 4 votes |
def get_augumentation(phase, width=512, height=512, min_area=0., min_visibility=0.): list_transforms = [] if phase == 'train': list_transforms.extend([ albu.augmentations.transforms.LongestMaxSize( max_size=width, always_apply=True), albu.PadIfNeeded(min_height=height, min_width=width, always_apply=True, border_mode=0, value=[0, 0, 0]), albu.augmentations.transforms.RandomResizedCrop( height=height, width=width, p=0.3), albu.augmentations.transforms.Flip(), albu.augmentations.transforms.Transpose(), albu.OneOf([ albu.RandomBrightnessContrast(brightness_limit=0.5, contrast_limit=0.4), albu.RandomGamma(gamma_limit=(50, 150)), albu.NoOp() ]), albu.OneOf([ albu.RGBShift(r_shift_limit=20, b_shift_limit=15, g_shift_limit=15), albu.HueSaturationValue(hue_shift_limit=5, sat_shift_limit=5), albu.NoOp() ]), albu.CLAHE(p=0.8), albu.HorizontalFlip(p=0.5), albu.VerticalFlip(p=0.5), ]) if(phase == 'test' or phase == 'valid'): list_transforms.extend([ albu.Resize(height=height, width=width) ]) list_transforms.extend([ albu.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225), p=1), ToTensor() ]) if(phase == 'test'): return albu.Compose(list_transforms) return albu.Compose(list_transforms, bbox_params=albu.BboxParams(format='pascal_voc', min_area=min_area, min_visibility=min_visibility, label_fields=['category_id']))
Example #7
Source File: dataset.py From kaggle-kuzushiji-2019 with MIT License | 4 votes |
def get_transform( *, train: bool, test_height: int, crop_width: int, crop_height: int, scale_aug: float, color_hue_aug: int, color_sat_aug: int, color_val_aug: int, normalize: bool = True, ) -> Callable: train_initial_size = 3072 # this value should not matter any more? crop_ratio = crop_height / test_height crop_min_max_height = tuple( int(train_initial_size * crop_ratio * (1 + sign * scale_aug)) for sign in [-1, 1]) if train: transforms = [ LongestMaxSizeRandomSizedCrop( max_size=train_initial_size, min_max_height=crop_min_max_height, width=crop_width, height=crop_height, w2h_ratio=crop_width / crop_height, ), A.HueSaturationValue( hue_shift_limit=color_hue_aug, sat_shift_limit=color_sat_aug, val_shift_limit=color_val_aug, ), A.RandomBrightnessContrast(), A.RandomGamma(), ] else: transforms = [ A.LongestMaxSize(max_size=test_height), ] if normalize: transforms.append(A.Normalize()) transforms.extend([ ToTensor(), ]) return A.Compose( transforms, bbox_params={ 'format': 'coco', 'min_area': 0, 'min_visibility': 0.99, 'label_fields': ['labels'], }, )