本文整理汇总了Python中imgaug.augmenters.Sometimes方法的典型用法代码示例。如果您正苦于以下问题:Python augmenters.Sometimes方法的具体用法?Python augmenters.Sometimes怎么用?Python augmenters.Sometimes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类imgaug.augmenters
的用法示例。
在下文中一共展示了augmenters.Sometimes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _load_augmentation_aug_non_geometric
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Sometimes [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: __init__
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Sometimes [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)
示例3: __init__
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Sometimes [as 别名]
def __init__(self, augmentation_rate):
self.augs = iaa.Sometimes(
augmentation_rate,
iaa.SomeOf(
(4, 7),
[
iaa.Affine(rotate=(-10, 10)),
iaa.Fliplr(0.2),
iaa.AverageBlur(k=(2, 10)),
iaa.Add((-10, 10), per_channel=0.5),
iaa.Multiply((0.75, 1.25), per_channel=0.5),
iaa.ContrastNormalization((0.5, 2.0), per_channel=0.5),
iaa.Crop(px=(0, 20))
],
random_order=True
)
)
示例4: init_augmentations
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Sometimes [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
示例5: chapter_augmenters_sometimes
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Sometimes [as 别名]
def chapter_augmenters_sometimes():
aug = iaa.Sometimes(0.5, iaa.GaussianBlur(sigma=2.0))
run_and_save_augseq(
"sometimes.jpg", aug,
[ia.quokka(size=(64, 64)) for _ in range(16)], cols=8, rows=2,
seed=2
)
aug = iaa.Sometimes(
0.5,
iaa.GaussianBlur(sigma=2.0),
iaa.Sequential([iaa.Affine(rotate=45), iaa.Sharpen(alpha=1.0)])
)
run_and_save_augseq(
"sometimes_if_else.jpg", aug,
[ia.quokka(size=(64, 64)) for _ in range(16)], cols=8, rows=2
)
示例6: _rectify_augmenter
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Sometimes [as 别名]
def _rectify_augmenter(self, augment):
import netharn as nh
if augment is True:
augment = 'simple'
if not augment:
augmenter = None
elif augment == 'simple':
augmenter = iaa.Sequential([
iaa.Crop(percent=(0, .2)),
iaa.Fliplr(p=.5)
])
elif augment == 'complex':
augmenter = iaa.Sequential([
iaa.Sometimes(0.2, nh.data.transforms.HSVShift(hue=0.1, sat=1.5, val=1.5)),
iaa.Crop(percent=(0, .2)),
iaa.Fliplr(p=.5)
])
else:
raise KeyError('Unknown augmentation {!r}'.format(augment))
return augmenter
示例7: _rectify_augmenter
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Sometimes [as 别名]
def _rectify_augmenter(self, augmenter):
import netharn as nh
if augmenter is True:
augmenter = 'simple'
if not augmenter:
augmenter = None
elif augmenter == 'simple':
augmenter = iaa.Sequential([
iaa.Crop(percent=(0, .2)),
iaa.Fliplr(p=.5)
])
elif augmenter == 'complex':
augmenter = iaa.Sequential([
iaa.Sometimes(0.2, nh.data.transforms.HSVShift(hue=0.1, sat=1.5, val=1.5)),
iaa.Crop(percent=(0, .2)),
iaa.Fliplr(p=.5)
])
else:
raise KeyError('Unknown augmentation {!r}'.format(self.augment))
return augmenter
示例8: __init__
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Sometimes [as 别名]
def __init__(self,data_dir, back_dir,
batch_size=50,gan=True,imsize=128,
res_x=640,res_y=480,
**kwargs):
'''
data_dir: Folder that contains cropped image+xyz
back_dir: Folder that contains random background images
batch_size: batch size for training
gan: if False, gt for GAN is not yielded
'''
self.data_dir = data_dir
self.back_dir = back_dir
self.imsize=imsize
self.batch_size = batch_size
self.gan = gan
self.backfiles = os.listdir(back_dir)
data_list = os.listdir(data_dir)
self.datafiles=[]
self.res_x=res_x
self.res_y=res_y
for file in data_list:
if(file.endswith(".npy")):
self.datafiles.append(file)
self.n_data = len(self.datafiles)
self.n_background = len(self.backfiles)
print("Total training views:", self.n_data)
self.seq_syn= iaa.Sequential([
iaa.WithChannels(0, iaa.Add((-15, 15))),
iaa.WithChannels(1, iaa.Add((-15, 15))),
iaa.WithChannels(2, iaa.Add((-15, 15))),
iaa.ContrastNormalization((0.8, 1.3)),
iaa.Multiply((0.8, 1.2),per_channel=0.5),
iaa.GaussianBlur(sigma=(0.0, 0.5)),
iaa.Sometimes(0.1, iaa.AdditiveGaussianNoise(scale=10, per_channel=True)),
iaa.Sometimes(0.5, iaa.ContrastNormalization((0.5, 2.2), per_channel=0.3)),
], random_order=True)
示例9: _load_augmentation_aug_geometric
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Sometimes [as 别名]
def _load_augmentation_aug_geometric():
return iaa.OneOf([
iaa.Sequential([iaa.Fliplr(0.5), iaa.Flipud(0.2)]),
iaa.CropAndPad(percent=(-0.05, 0.1),
pad_mode='constant',
pad_cval=(0, 255)),
iaa.Crop(percent=(0.0, 0.1)),
iaa.Crop(percent=(0.3, 0.5)),
iaa.Crop(percent=(0.3, 0.5)),
iaa.Crop(percent=(0.3, 0.5)),
iaa.Sequential([
iaa.Affine(
# scale images to 80-120% of their size,
# individually per axis
scale={"x": (0.8, 1.2), "y": (0.8, 1.2)},
# translate by -20 to +20 percent (per axis)
translate_percent={"x": (-0.2, 0.2), "y": (-0.2, 0.2)},
rotate=(-45, 45), # rotate by -45 to +45 degrees
shear=(-16, 16), # shear by -16 to +16 degrees
# use nearest neighbour or bilinear interpolation (fast)
order=[0, 1],
# if mode is constant, use a cval between 0 and 255
mode='constant',
cval=(0, 255),
# use any of scikit-image's warping modes
# (see 2nd image from the top for examples)
),
iaa.Sometimes(0.3, iaa.Crop(percent=(0.3, 0.5)))])
])
示例10: _load_augmentation_aug_all2
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Sometimes [as 别名]
def _load_augmentation_aug_all2():
return iaa.Sequential([
iaa.Sometimes(0.65, _load_augmentation_aug_non_geometric()),
iaa.Sometimes(0.65, _load_augmentation_aug_geometric())
])
示例11: example_using_augmenters_only_once
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Sometimes [as 别名]
def example_using_augmenters_only_once():
print("Example: Using Augmenters Only Once")
from imgaug import augmenters as iaa
import numpy as np
images = np.random.randint(0, 255, (16, 128, 128, 3), dtype=np.uint8)
# always horizontally flip each input image
images_aug = iaa.Fliplr(1.0)(images=images)
# vertically flip each input image with 90% probability
images_aug = iaa.Flipud(0.9)(images=images)
# blur 50% of all images using a gaussian kernel with a sigma of 3.0
images_aug = iaa.Sometimes(0.5, iaa.GaussianBlur(3.0))(images=images)
示例12: apply_augment_sequence
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Sometimes [as 别名]
def apply_augment_sequence(image_set_x, image_set_y):
"""
Randomly flip and rotate the images in both set with deterministic order. This turns 1 image into 8 images.
Parameters:
image_set_x: List of Images (X) to augment
image_set_y: List of corresponding Y image to augment in the same deterministic order applied to image_set_x
Returns:
image_setx_aug, image_sety_aug : augmented versions of the inputs
"""
# Sometimes(0.5, ...) applies the given augmenter in 50% of all cases,
# e.g. Sometimes(0.5, GaussianBlur(0.3)) would blur roughly every second image.
sometimes = lambda aug: iaa.Sometimes(0.5, aug)
seq = iaa.Sequential(
[
iaa.Fliplr(0.5),
iaa.Flipud(0.5),
sometimes(iaa.Affine(
rotate=(90, 90),
))
],
random_order=False)
seq_det = seq.to_deterministic()
image_setx_aug = seq_det.augment_images(image_set_x)
image_sety_aug = seq_det.augment_images(image_set_y)
return image_setx_aug, image_sety_aug
示例13: augment_soft
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Sometimes [as 别名]
def augment_soft(img):
# Sometimes(0.5, ...) applies the given augmenter in 50% of all cases,
# e.g. Sometimes(0.5, GaussianBlur(0.3)) would blur roughly every second image.
sometimes = lambda aug: iaa.Sometimes(0.5, aug)
# Define our sequence of augmentation steps that will be applied to every image
# All augmenters with per_channel=0.5 will sample one value _per image_
# in 50% of all cases. In all other cases they will sample new values
# _per channel_.
seq = iaa.Sequential(
[
# apply the following augmenters to most images
iaa.Fliplr(0.5), # horizontally flip 50% of all images
# crop images by -5% to 10% of their height/width
iaa.Crop(
percent=(0, 0.2),
),
iaa.Scale({"height": CROP_SIZE, "width": CROP_SIZE }),
],
random_order=False
)
if img.ndim == 3:
img = seq.augment_images(np.expand_dims(img, axis=0)).squeeze(axis=0)
else:
img = seq.augment_images(img)
return img
示例14: imgaug
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Sometimes [as 别名]
def imgaug(args):
# Number of batches and batch size for this example
filename, root, fold_A = args
img = cv2.imread(os.path.join(root,filename))
print('image opened ' + os.path.join(root,filename))
batch_size = 4
for i in range(0,batch_size):
imageio.imwrite(os.path.join(root, os.path.splitext(filename)[0] + '_' + str(i) + '.jpg'), img) #convert the current image in B into a jpg from png
nb_batches = 1
# Example augmentation sequence to run in the background
sometimes = lambda aug: iaa.Sometimes(0.4, aug)
augseq = iaa.Sequential(
[
iaa.PiecewiseAffine(scale=(0.01, 0.01005))
]
)
# Make batches out of the example image (here: 10 batches, each 32 times
# the example image)
batches = []
for _ in range(nb_batches):
batches.append(Batch(images=[img] * batch_size))
#Save images
for batch in augseq.augment_batches(batches, background=False):
count = 0
for img in batch.images_aug:
path = os.path.join(fold_A,root.rsplit('/', 1)[-1], os.path.splitext(filename)[0] + '_' + str(count) + '.jpg')
cv2.imwrite(path, img)
print('image saved as: ' + path)
count +=1
示例15: aug_on_fly
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Sometimes [as 别名]
def aug_on_fly(img, det_mask, cls_mask):
"""Do augmentation with different combination on each training batch
"""
def image_basic_augmentation(image, masks, ratio_operations=0.9):
# without additional operations
# according to the paper, operations such as shearing, fliping horizontal/vertical,
# rotating, zooming and channel shifting will be apply
sometimes = lambda aug: iaa.Sometimes(ratio_operations, aug)
hor_flip_angle = np.random.uniform(0, 1)
ver_flip_angle = np.random.uniform(0, 1)
seq = iaa.Sequential([
sometimes(
iaa.SomeOf((0, 5), [
iaa.Fliplr(hor_flip_angle),
iaa.Flipud(ver_flip_angle),
iaa.Affine(shear=(-16, 16)),
iaa.Affine(scale={'x': (1, 1.6), 'y': (1, 1.6)}),
iaa.PerspectiveTransform(scale=(0.01, 0.1))
]))
])
det_mask, cls_mask = masks[0], masks[1]
seq_to_deterministic = seq.to_deterministic()
aug_img = seq_to_deterministic.augment_images(image)
aug_det_mask = seq_to_deterministic.augment_images(det_mask)
aug_cls_mask = seq_to_deterministic.augment_images(cls_mask)
return aug_img, aug_det_mask, aug_cls_mask
aug_image, aug_det_mask, aug_cls_mask = image_basic_augmentation(image=img, masks=[det_mask, cls_mask])
return aug_image, aug_det_mask, aug_cls_mask