本文整理汇总了Python中imgaug.ALL属性的典型用法代码示例。如果您正苦于以下问题:Python imgaug.ALL属性的具体用法?Python imgaug.ALL怎么用?Python imgaug.ALL使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类imgaug
的用法示例。
在下文中一共展示了imgaug.ALL属性的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_augmentations
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import ALL [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
示例2: main
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import ALL [as 别名]
def main():
img = ia.data.quokka(size=(128, 128), extract="square")
aug = iaa.ChannelShuffle()
imgs_aug = aug.augment_images([img] * 64)
ia.imshow(ia.draw_grid(imgs_aug))
aug = iaa.ChannelShuffle(p=0.1)
imgs_aug = aug.augment_images([img] * 64)
ia.imshow(ia.draw_grid(imgs_aug))
aug = iaa.ChannelShuffle(p=1.0, channels=[0, 1])
imgs_aug = aug.augment_images([img] * 64)
ia.imshow(ia.draw_grid(imgs_aug))
aug = iaa.ChannelShuffle(p=1.0, channels=[1, 2])
imgs_aug = aug.augment_images([img] * 64)
ia.imshow(ia.draw_grid(imgs_aug))
aug = iaa.ChannelShuffle(p=1.0, channels=[1, 1, 2])
imgs_aug = aug.augment_images([img] * 64)
ia.imshow(ia.draw_grid(imgs_aug))
aug = iaa.ChannelShuffle(p=1.0, channels=ia.ALL)
imgs_aug = aug.augment_images([img] * 64)
ia.imshow(ia.draw_grid(imgs_aug))
示例3: test___init___to_colorspace_is_all
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import ALL [as 别名]
def test___init___to_colorspace_is_all(self):
aug = iaa.WithBrightnessChannels(to_colorspace=ia.ALL)
assert isinstance(aug.children, iaa.Augmenter)
assert len(aug.to_colorspace.a) == len(self.valid_colorspaces)
for cspace in self.valid_colorspaces:
assert cspace in aug.to_colorspace.a
assert aug.from_colorspace == iaa.CSPACE_RGB
示例4: test_arg_is_all
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import ALL [as 别名]
def test_arg_is_all(self):
valid_values = ["class1", "class2"]
param = iap.handle_categorical_string_param(
ia.ALL, "foo", valid_values)
assert is_parameter_instance(param, iap.Choice)
assert param.a == valid_values
示例5: test_arg_is_invalid_datatype
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import ALL [as 别名]
def test_arg_is_invalid_datatype(self):
with self.assertRaises(Exception) as ctx:
_ = iap.handle_categorical_string_param(
False, "foo", ["class1"])
expected = "Expected parameter 'foo' to be imgaug.ALL"
assert expected in str(ctx.exception)
示例6: test_value_is_stochastic_all_100_iter
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import ALL [as 别名]
def test_value_is_stochastic_all_100_iter(self):
# test ia.ALL as aggregation_method
# note that each method individually and list of methods are already
# tested, so no in depth test is needed here
param = iap.IterativeNoiseAggregator(
iap.Choice([0, 50]), iterations=100, aggregation_method=ia.ALL)
assert isinstance(param.aggregation_method, iap.Choice)
assert len(param.aggregation_method.a) == 3
assert [v in param.aggregation_method.a for v in ["min", "avg", "max"]]
示例7: chapter_augmenters_cropandpad
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import ALL [as 别名]
def chapter_augmenters_cropandpad():
aug = iaa.CropAndPad(percent=(-0.25, 0.25))
run_and_save_augseq(
"cropandpad_percent.jpg", aug,
[ia.quokka(size=(128, 128)) for _ in range(8)], cols=4, rows=2
)
aug = iaa.CropAndPad(
percent=(0, 0.2),
pad_mode=["constant", "edge"],
pad_cval=(0, 128)
)
run_and_save_augseq(
"cropandpad_mode_cval.jpg", aug,
[ia.quokka(size=(64, 64)) for _ in range(16)], cols=8, rows=2
)
aug = iaa.CropAndPad(
px=((0, 30), (0, 10), (0, 30), (0, 10)),
pad_mode=ia.ALL,
pad_cval=(0, 128)
)
run_and_save_augseq(
"cropandpad_pad_complex.jpg", aug,
[ia.quokka(size=(64, 64)) for _ in range(32)], cols=8, rows=4
)
aug = iaa.CropAndPad(
px=(-10, 10),
sample_independently=False
)
run_and_save_augseq(
"cropandpad_correlated.jpg", aug,
[ia.quokka(size=(64, 64)) for _ in range(16)], cols=8, rows=2
)
示例8: __init__
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import ALL [as 别名]
def __init__(self, target_size, fill_color=127, mode='letterbox',
border='constant', random_state=None):
super(Resize, self).__init__(random_state=random_state)
self.target_size = None if target_size is None else np.array(target_size)
self.mode = mode
import imgaug.parameters as iap
if fill_color == imgaug.ALL:
self.fill_color = iap.Uniform(0, 255)
else:
self.fill_color = iap.handle_continuous_param(
fill_color, "fill_color", value_range=None,
tuple_to_uniform=True, list_to_choice=True)
self._cv2_border_type_map = {
'constant': cv2.BORDER_CONSTANT,
'edge': cv2.BORDER_REPLICATE,
'linear_ramp': None,
'maximum': None,
'mean': None,
'median': None,
'minimum': None,
'reflect': cv2.BORDER_REFLECT_101,
'symmetric': cv2.BORDER_REFLECT,
'wrap': cv2.BORDER_WRAP,
cv2.BORDER_CONSTANT: cv2.BORDER_CONSTANT,
cv2.BORDER_REPLICATE: cv2.BORDER_REPLICATE,
cv2.BORDER_REFLECT_101: cv2.BORDER_REFLECT_101,
cv2.BORDER_REFLECT: cv2.BORDER_REFLECT
}
if isinstance(border, six.string_types):
if border == imgaug.ALL:
border = [k for k, v in self._cv2_border_type_map.items()
if v is not None and isinstance(k, six.string_types)]
else:
border = [border]
if isinstance(border, (list, tuple)):
from imgaug.parameters import Choice
border = Choice(border)
self.border = border
assert self.mode == 'letterbox', 'thats all folks'
示例9: chapter_augmenters_affine
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import ALL [as 别名]
def chapter_augmenters_affine():
aug = iaa.Affine(scale=(0.5, 1.5))
run_and_save_augseq(
"affine_scale.jpg", aug,
[ia.quokka(size=(64, 64)) for _ in range(16)], cols=8, rows=2
)
aug = iaa.Affine(scale={"x": (0.5, 1.5), "y": (0.5, 1.5)})
run_and_save_augseq(
"affine_scale_independently.jpg", aug,
[ia.quokka(size=(64, 64)) for _ in range(16)], cols=8, rows=2
)
aug = iaa.Affine(translate_percent={"x": (-0.2, 0.2), "y": (-0.2, 0.2)})
run_and_save_augseq(
"affine_translate_percent.jpg", aug,
[ia.quokka(size=(64, 64)) for _ in range(16)], cols=8, rows=2
)
aug = iaa.Affine(translate_px={"x": (-20, 20), "y": (-20, 20)})
run_and_save_augseq(
"affine_translate_px.jpg", aug,
[ia.quokka(size=(64, 64)) for _ in range(16)], cols=8, rows=2
)
aug = iaa.Affine(rotate=(-45, 45))
run_and_save_augseq(
"affine_rotate.jpg", aug,
[ia.quokka(size=(64, 64)) for _ in range(16)], cols=8, rows=2
)
aug = iaa.Affine(shear=(-16, 16))
run_and_save_augseq(
"affine_shear.jpg", aug,
[ia.quokka(size=(64, 64)) for _ in range(16)], cols=8, rows=2
)
aug = iaa.Affine(translate_percent={"x": -0.20}, mode=ia.ALL, cval=(0, 255))
run_and_save_augseq(
"affine_fill.jpg", aug,
[ia.quokka(size=(64, 64)) for _ in range(16)], cols=8, rows=2
)
示例10: example_heavy_augmentations
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import ALL [as 别名]
def example_heavy_augmentations():
print("Example: Heavy Augmentations")
import imgaug as ia
from imgaug import augmenters as iaa
# random example images
images = np.random.randint(0, 255, (16, 128, 128, 3), dtype=np.uint8)
# 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.
st = 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([
iaa.Fliplr(0.5), # horizontally flip 50% of all images
iaa.Flipud(0.5), # vertically flip 50% of all images
st(iaa.Crop(percent=(0, 0.1))), # crop images by 0-10% of their height/width
st(iaa.GaussianBlur((0, 3.0))), # blur images with a sigma between 0 and 3.0
st(iaa.AdditiveGaussianNoise(loc=0, scale=(0.0, 0.05*255), per_channel=0.5)), # add gaussian noise to images
st(iaa.Dropout((0.0, 0.1), per_channel=0.5)), # randomly remove up to 10% of the pixels
st(iaa.Add((-10, 10), per_channel=0.5)), # change brightness of images (by -10 to 10 of original value)
st(iaa.Multiply((0.5, 1.5), per_channel=0.5)), # change brightness of images (50-150% of original value)
st(iaa.ContrastNormalization((0.5, 2.0), per_channel=0.5)), # improve or worsen the contrast
st(iaa.Grayscale((0.0, 1.0))), # blend with grayscale image
st(iaa.Affine(
scale={"x": (0.8, 1.2), "y": (0.8, 1.2)}, # scale images to 80-120% of their size, individually per axis
translate_px={"x": (-16, 16), "y": (-16, 16)}, # translate by -16 to +16 pixels (per axis)
rotate=(-45, 45), # rotate by -45 to +45 degrees
shear=(-16, 16), # shear by -16 to +16 degrees
order=[0, 1], # use scikit-image's interpolation orders 0 (nearest neighbour) and 1 (bilinear)
cval=(0, 255), # if mode is constant, use a cval between 0 and 1.0
mode=ia.ALL # use any of scikit-image's warping modes (see 2nd image from the top for examples)
)),
st(iaa.ElasticTransformation(alpha=(0.5, 3.5), sigma=0.25)) # apply elastic transformations with random strengths
],
random_order=True # do all of the above in random order
)
images_aug = seq.augment_images(images)
# -----
# Make sure that the example really does something
assert not np.array_equal(images, images_aug)
示例11: _json_id
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import ALL [as 别名]
def _json_id(aug):
"""
TODO:
- [ ] submit a PR to imgaug that registers parameters with classes
Example:
>>> from netharn.data.transforms.augmenter_base import *
>>> import imgaug.augmenters as iaa
>>> import imgaug
>>> _PA = ParamatarizedAugmenter
>>> augment = imgaug.augmenters.Affine()
>>> info = _PA._json_id(augment)
>>> assert info['__class__'] == 'Affine'
>>> assert _PA._json_id('') == ''
>>> #####
>>> augmentors = [
>>> iaa.Fliplr(p=.5),
>>> iaa.Flipud(p=.5),
>>> iaa.Affine(
>>> scale={"x": (1.0, 1.01), "y": (1.0, 1.01)},
>>> translate_percent={"x": (-0.1, 0.1), "y": (-0.1, 0.1)},
>>> rotate=(-15, 15),
>>> shear=(-7, 7),
>>> order=[0, 1, 3],
>>> cval=(0, 255),
>>> mode=imgaug.ALL, # use any of scikit-image's warping modes (see 2nd image from the top for examples)
>>> # Note: currently requires imgaug master version
>>> backend='cv2',
>>> ),
>>> iaa.AddToHueAndSaturation((-20, 20)), # change hue and saturation
>>> iaa.ContrastNormalization((0.5, 2.0), per_channel=0.5), # improve or worsen the contrast
>>> ]
>>> augment = iaa.Sequential(augmentors)
>>> info = _PA._json_id(augment)
>>> import ubelt as ub
>>> print(ub.repr2(info, nl=2, precision=2))
"""
_PA = ParamatarizedAugmenter
if isinstance(aug, tuple):
return [_PA._json_id(item) for item in aug]
elif isinstance(aug, imgaug.parameters.StochasticParameter):
return str(aug)
elif isinstance(aug, imgaug.augmenters.Augmenter):
info = OrderedDict()
info['__class__'] = aug.__class__.__name__
try:
params = _PA._hack_get_named_params(aug)
if params:
info['params'] = params
if isinstance(aug, list):
children = aug[:]
children = [ParamatarizedAugmenter._json_id(c) for c in children]
info['children'] = children
return info
except Exception as ex:
print(ex)
# imgaug is weird and buggy
info['__str__'] = str(aug)
else:
return str(aug)