本文整理汇总了Python中imgaug.augmenters.Sequential方法的典型用法代码示例。如果您正苦于以下问题:Python augmenters.Sequential方法的具体用法?Python augmenters.Sequential怎么用?Python augmenters.Sequential使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类imgaug.augmenters
的用法示例。
在下文中一共展示了augmenters.Sequential方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _load_augmentation_aug_non_geometric
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Sequential [as 别名]
def _load_augmentation_aug_non_geometric():
return iaa.Sequential([
iaa.Sometimes(0.3, iaa.Multiply((0.5, 1.5), per_channel=0.5)),
iaa.Sometimes(0.2, iaa.JpegCompression(compression=(70, 99))),
iaa.Sometimes(0.2, iaa.GaussianBlur(sigma=(0, 3.0))),
iaa.Sometimes(0.2, iaa.MotionBlur(k=15, angle=[-45, 45])),
iaa.Sometimes(0.2, iaa.MultiplyHue((0.5, 1.5))),
iaa.Sometimes(0.2, iaa.MultiplySaturation((0.5, 1.5))),
iaa.Sometimes(0.34, iaa.MultiplyHueAndSaturation((0.5, 1.5),
per_channel=True)),
iaa.Sometimes(0.34, iaa.Grayscale(alpha=(0.0, 1.0))),
iaa.Sometimes(0.2, iaa.ChangeColorTemperature((1100, 10000))),
iaa.Sometimes(0.1, iaa.GammaContrast((0.5, 2.0))),
iaa.Sometimes(0.2, iaa.SigmoidContrast(gain=(3, 10),
cutoff=(0.4, 0.6))),
iaa.Sometimes(0.1, iaa.CLAHE()),
iaa.Sometimes(0.1, iaa.HistogramEqualization()),
iaa.Sometimes(0.2, iaa.LinearContrast((0.5, 2.0), per_channel=0.5)),
iaa.Sometimes(0.1, iaa.Emboss(alpha=(0, 1.0), strength=(0, 2.0)))
])
示例2: example_augment_images_and_keypoints
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Sequential [as 别名]
def example_augment_images_and_keypoints():
print("Example: Augment Images and Keypoints")
import numpy as np
import imgaug.augmenters as iaa
images = np.zeros((2, 128, 128, 3), dtype=np.uint8) # two example images
images[:, 64, 64, :] = 255
points = [
[(10.5, 20.5)], # points on first image
[(50.5, 50.5), (60.5, 60.5), (70.5, 70.5)] # points on second image
]
seq = iaa.Sequential([
iaa.AdditiveGaussianNoise(scale=0.05*255),
iaa.Affine(translate_px={"x": (1, 5)})
])
# augment keypoints and images
images_aug, points_aug = seq(images=images, keypoints=points)
print("Image 1 center", np.argmax(images_aug[0, 64, 64:64+6, 0]))
print("Image 2 center", np.argmax(images_aug[1, 64, 64:64+6, 0]))
print("Points 1", points_aug[0])
print("Points 2", points_aug[1])
示例3: example_augment_images_and_bounding_boxes
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Sequential [as 别名]
def example_augment_images_and_bounding_boxes():
print("Example: Augment Images and Bounding Boxes")
import numpy as np
import imgaug as ia
import imgaug.augmenters as iaa
images = np.zeros((2, 128, 128, 3), dtype=np.uint8) # two example images
images[:, 64, 64, :] = 255
bbs = [
[ia.BoundingBox(x1=10.5, y1=15.5, x2=30.5, y2=50.5)],
[ia.BoundingBox(x1=10.5, y1=20.5, x2=50.5, y2=50.5),
ia.BoundingBox(x1=40.5, y1=75.5, x2=70.5, y2=100.5)]
]
seq = iaa.Sequential([
iaa.AdditiveGaussianNoise(scale=0.05*255),
iaa.Affine(translate_px={"x": (1, 5)})
])
images_aug, bbs_aug = seq(images=images, bounding_boxes=bbs)
示例4: example_augment_images_and_polygons
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Sequential [as 别名]
def example_augment_images_and_polygons():
print("Example: Augment Images and Polygons")
import numpy as np
import imgaug as ia
import imgaug.augmenters as iaa
images = np.zeros((2, 128, 128, 3), dtype=np.uint8) # two example images
images[:, 64, 64, :] = 255
polygons = [
[ia.Polygon([(10.5, 10.5), (50.5, 10.5), (50.5, 50.5)])],
[ia.Polygon([(0.0, 64.5), (64.5, 0.0), (128.0, 128.0), (64.5, 128.0)])]
]
seq = iaa.Sequential([
iaa.AdditiveGaussianNoise(scale=0.05*255),
iaa.Affine(translate_px={"x": (1, 5)})
])
images_aug, polygons_aug = seq(images=images, polygons=polygons)
示例5: example_augment_images_and_linestrings
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Sequential [as 别名]
def example_augment_images_and_linestrings():
print("Example: Augment Images and LineStrings")
import numpy as np
import imgaug as ia
import imgaug.augmenters as iaa
images = np.zeros((2, 128, 128, 3), dtype=np.uint8) # two example images
images[:, 64, 64, :] = 255
ls = [
[ia.LineString([(10.5, 10.5), (50.5, 10.5), (50.5, 50.5)])],
[ia.LineString([(0.0, 64.5), (64.5, 0.0), (128.0, 128.0), (64.5, 128.0),
(128.0, 0.0)])]
]
seq = iaa.Sequential([
iaa.AdditiveGaussianNoise(scale=0.05*255),
iaa.Affine(translate_px={"x": (1, 5)})
])
images_aug, ls_aug = seq(images=images, line_strings=ls)
示例6: example_augment_images_and_segmentation_maps
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Sequential [as 别名]
def example_augment_images_and_segmentation_maps():
print("Example: Augment Images and Segmentation Maps")
import numpy as np
import imgaug.augmenters as iaa
# Standard scenario: You have N=16 RGB-images and additionally one segmentation
# map per image. You want to augment each image and its heatmaps identically.
images = np.random.randint(0, 255, (16, 128, 128, 3), dtype=np.uint8)
segmaps = np.random.randint(0, 10, size=(16, 64, 64, 1), dtype=np.int32)
seq = iaa.Sequential([
iaa.GaussianBlur((0, 3.0)),
iaa.Affine(translate_px={"x": (-40, 40)}),
iaa.Crop(px=(0, 10))
])
images_aug, segmaps_aug = seq(images=images, segmentation_maps=segmaps)
示例7: test_deprecation_warning
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Sequential [as 别名]
def test_deprecation_warning(self):
aug1 = iaa.Sequential([])
aug2 = iaa.Sequential([])
with warnings.catch_warnings(record=True) as caught_warnings:
warnings.simplefilter("always")
aug = iaa.Alpha(0.75, first=aug1, second=aug2)
assert (
"is deprecated"
in str(caught_warnings[-1].message)
)
assert isinstance(aug, iaa.BlendAlpha)
assert np.isclose(aug.factor.value, 0.75)
assert aug.foreground is aug1
assert aug.background is aug2
示例8: test_returns_correct_objects__mul_hue_and_mul_saturation
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Sequential [as 别名]
def test_returns_correct_objects__mul_hue_and_mul_saturation(self):
aug = iaa.MultiplyHueAndSaturation(mul_hue=(0.9, 1.1),
mul_saturation=(0.8, 1.2))
assert isinstance(aug, iaa.WithHueAndSaturation)
assert isinstance(aug.children, iaa.Sequential)
assert len(aug.children) == 2
assert isinstance(aug.children[0], iaa.WithChannels)
assert aug.children[0].channels == [0]
assert len(aug.children[0].children) == 1
assert isinstance(aug.children[0].children[0], iaa.Multiply)
assert is_parameter_instance(aug.children[0].children[0].mul,
iap.Uniform)
assert np.isclose(aug.children[0].children[0].mul.a.value, 0.9)
assert np.isclose(aug.children[0].children[0].mul.b.value, 1.1)
assert isinstance(aug.children[1], iaa.WithChannels)
assert aug.children[1].channels == [1]
assert len(aug.children[0].children) == 1
assert isinstance(aug.children[1].children[0], iaa.Multiply)
assert is_parameter_instance(aug.children[1].children[0].mul,
iap.Uniform)
assert np.isclose(aug.children[1].children[0].mul.a.value, 0.8)
assert np.isclose(aug.children[1].children[0].mul.b.value, 1.2)
示例9: test_returns_correct_class
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Sequential [as 别名]
def test_returns_correct_class(self):
# this test is practically identical to
# TestMultiplyToHueAndSaturation
# .test_returns_correct_objects__mul_saturation
aug = iaa.MultiplySaturation((0.9, 1.1))
assert isinstance(aug, iaa.WithHueAndSaturation)
assert isinstance(aug.children, iaa.Sequential)
assert len(aug.children) == 1
assert isinstance(aug.children[0], iaa.WithChannels)
assert aug.children[0].channels == [1]
assert len(aug.children[0].children) == 1
assert isinstance(aug.children[0].children[0], iaa.Multiply)
assert is_parameter_instance(aug.children[0].children[0].mul,
iap.Uniform)
assert np.isclose(aug.children[0].children[0].mul.a.value, 0.9)
assert np.isclose(aug.children[0].children[0].mul.b.value, 1.1)
示例10: __init__
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Sequential [as 别名]
def __init__(self):
self.seq = iaa.Sequential([
iaa.Sometimes(0.5, iaa.OneOf([
iaa.GaussianBlur((0, 3.0)), # blur images with a sigma between 0 and 3.0
iaa.AverageBlur(k=(2, 7)), # blur image using local means with kernel sizes between 2 and 7
iaa.MedianBlur(k=(3, 11)), # blur image using local medians with kernel sizes between 2 and 7
])),
iaa.Sometimes(0.5, iaa.AdditiveGaussianNoise(loc=0, scale=(0.0, 0.05 * 255), per_channel=0.5)),
iaa.Sometimes(0.5, iaa.Add((-10, 10), per_channel=0.5)),
iaa.Sometimes(0.5, iaa.AddToHueAndSaturation((-20, 20))),
iaa.Sometimes(0.5, iaa.FrequencyNoiseAlpha(
exponent=(-4, 0),
first=iaa.Multiply((0.5, 1.5), per_channel=True),
second=iaa.LinearContrast((0.5, 2.0))
)),
iaa.Sometimes(0.5, iaa.PiecewiseAffine(scale=(0.01, 0.05))),
iaa.Sometimes(0.5, iaa.PerspectiveTransform(scale=(0.01, 0.1)))
], random_order=True)
示例11: create_augmenter
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Sequential [as 别名]
def create_augmenter(stage: str = "train"):
if stage == "train":
return iaa.Sequential([
iaa.Fliplr(0.5),
iaa.CropAndPad(px=(0, 112), sample_independently=False),
iaa.Affine(translate_percent={"x": (-0.4, 0.4), "y": (-0.4, 0.4)}),
iaa.SomeOf((0, 3), [
iaa.AddToHueAndSaturation((-10, 10)),
iaa.Affine(scale={"x": (0.9, 1.1), "y": (0.9, 1.1)}),
iaa.GaussianBlur(sigma=(0, 1.0)),
iaa.AdditiveGaussianNoise(scale=0.05 * 255)
])
])
elif stage == "val":
return iaa.Sequential([
iaa.CropAndPad(px=(0, 112), sample_independently=False),
iaa.Affine(translate_percent={"x": (-0.4, 0.4), "y": (-0.4, 0.4)}),
])
elif stage == "test":
return iaa.Sequential([])
示例12: init_augmentations
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Sequential [as 别名]
def init_augmentations(self):
if self.transform_probability > 0 and self.use_imgaug:
augmentations = iaa.Sometimes(
self.transform_probability,
iaa.Sequential([
iaa.SomeOf(
(1, None),
[
iaa.AddToHueAndSaturation(iap.Uniform(-20, 20), per_channel=True),
iaa.GaussianBlur(sigma=(0, 1.0)),
iaa.LinearContrast((0.75, 1.0)),
iaa.PiecewiseAffine(scale=(0.01, 0.02), mode='edge'),
],
random_order=True
),
iaa.Resize(
{"height": (16, self.image_size.height), "width": "keep-aspect-ratio"},
interpolation=imgaug.ALL
),
])
)
else:
augmentations = None
return augmentations
示例13: amaugimg
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Sequential [as 别名]
def amaugimg(image):
#数据增强
image = cv2.cvtColor(np.asarray(image), cv2.COLOR_RGB2BGR)
seq = iaa.Sequential([
# iaa.Affine(rotate=(-5, 5),
# shear=(-5, 5),
# mode='edge'),
iaa.SomeOf((0, 2), #选择数据增强
[
iaa.GaussianBlur((0, 1.5)),
iaa.AdditiveGaussianNoise(loc=0, scale=(0.0, 0.01 * 255), per_channel=0.5),
# iaa.AddToHueAndSaturation((-5, 5)), # change hue and saturation
iaa.PiecewiseAffine(scale=(0.01, 0.03)),
iaa.PerspectiveTransform(scale=(0.01, 0.1))
],
random_order=True
)
])
image = seq.augment_image(image)
image = Image.fromarray(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
return image
示例14: augment
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Sequential [as 别名]
def augment(image, bbox):
x = random.randint(-50, 50)
y = random.randint(-50, 50)
aug = iaa.Sequential([iaa.Multiply(random.uniform(0.5, 1.5)),
iaa.AdditiveGaussianNoise(random.uniform(0.01, 0.1) * 255),
iaa.Affine(translate_px={"x": x, "y": y},
scale=random.uniform(0.5, 1.5),
rotate=random.uniform(-45, 45),
cval=(0, 255))])
bbs = ia.BoundingBoxesOnImage([ia.BoundingBox(x1=bbox[0], y1=bbox[1], x2=bbox[2], y2=bbox[3])], shape=image.shape)
aug = aug.to_deterministic()
image_aug = aug.augment_image(image)
bbs_aug = aug.augment_bounding_boxes([bbs])[0]
b = bbs_aug.bounding_boxes
bbs_aug = [b[0].x1, b[0].y1, b[0].x2, b[0].y2]
bbs_aug = np.asarray(bbs_aug)
bbs_aug[0] = bbs_aug[0] if bbs_aug[0] > 0 else 0
bbs_aug[1] = bbs_aug[1] if bbs_aug[1] > 0 else 0
bbs_aug[2] = bbs_aug[2] if bbs_aug[2] < size else size
bbs_aug[3] = bbs_aug[3] if bbs_aug[3] < size else size
return image_aug, bbs_aug
示例15: augment_flip
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Sequential [as 别名]
def augment_flip(image, bbox):
aug = iaa.Sequential([iaa.Fliplr(1.0)])
bbs = ia.BoundingBoxesOnImage([
ia.BoundingBox(x1=bbox[0], y1=bbox[1], x2=bbox[2], y2=bbox[3])], shape=image.shape)
aug = aug.to_deterministic()
image_aug = aug.augment_image(image)
image_aug = image_aug.copy()
bbs_aug = aug.augment_bounding_boxes([bbs])[0]
b = bbs_aug.bounding_boxes
bbs_aug = [b[0].x1, b[0].y1, b[0].x2, b[0].y2]
bbs_aug = np.asarray(bbs_aug)
bbs_aug[0] = bbs_aug[0] if bbs_aug[0] > 0 else 0
bbs_aug[1] = bbs_aug[1] if bbs_aug[1] > 0 else 0
bbs_aug[2] = bbs_aug[2] if bbs_aug[2] < size else size
bbs_aug[3] = bbs_aug[3] if bbs_aug[3] < size else size
return image_aug, bbs_aug