本文整理汇总了Python中imgaug.augmenters.Flipud方法的典型用法代码示例。如果您正苦于以下问题:Python augmenters.Flipud方法的具体用法?Python augmenters.Flipud怎么用?Python augmenters.Flipud使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类imgaug.augmenters
的用法示例。
在下文中一共展示了augmenters.Flipud方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Flipud [as 别名]
def __init__(self, dataset_path,scale,k_fold_test=1, mode='train'):
super().__init__()
self.mode = mode
self.img_path=dataset_path+'/img'
self.mask_path=dataset_path+'/mask'
self.image_lists,self.label_lists=self.read_list(self.img_path,k_fold_test=k_fold_test)
self.flip =iaa.SomeOf((2,4),[
iaa.Fliplr(0.5),
iaa.Flipud(0.5),
iaa.Affine(rotate=(-30, 30)),
iaa.AdditiveGaussianNoise(scale=(0.0,0.08*255))], random_order=True)
# resize
self.resize_label = transforms.Resize(scale, Image.NEAREST)
self.resize_img = transforms.Resize(scale, Image.BILINEAR)
# normalization
self.to_tensor = transforms.ToTensor()
示例2: img_aug
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Flipud [as 别名]
def img_aug(img, mask):
mask = np.where(mask > 0, 0, 255).astype(np.uint8)
flipper = iaa.Fliplr(0.5).to_deterministic()
mask = flipper.augment_image(mask)
img = flipper.augment_image(img)
vflipper = iaa.Flipud(0.5).to_deterministic()
img = vflipper.augment_image(img)
mask = vflipper.augment_image(mask)
if random.random() < 0.5:
rot_time = random.choice([1, 2, 3])
for i in range(rot_time):
img = np.rot90(img)
mask = np.rot90(mask)
if random.random() < 0.5:
translater = iaa.Affine(translate_percent={"x": (-0.2, 0.2), "y": (-0.2, 0.2)},
scale={"x": (0.8, 1.2), "y": (0.8, 1.2)},
shear=(-8, 8),
cval=(255)
).to_deterministic()
img = translater.augment_image(img)
mask = translater.augment_image(mask)
# if random.random() < 0.5:
# img = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
mask = np.where(mask > 0, 0, 255).astype(np.uint8)
return img, mask
示例3: example_single_augmenters
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Flipud [as 别名]
def example_single_augmenters():
print("Example: Single Augmenters")
from imgaug import augmenters as iaa
images = np.random.randint(0, 255, (16, 128, 128, 3), dtype=np.uint8)
flipper = iaa.Fliplr(1.0) # always horizontally flip each input image
images[0] = flipper.augment_image(images[0]) # horizontally flip image 0
vflipper = iaa.Flipud(0.9) # vertically flip each input image with 90% probability
images[1] = vflipper.augment_image(images[1]) # probably vertically flip image 1
blurer = iaa.GaussianBlur(3.0)
images[2] = blurer.augment_image(images[2]) # blur image 2 by a sigma of 3.0
images[3] = blurer.augment_image(images[3]) # blur image 3 by a sigma of 3.0 too
translater = iaa.Affine(translate_px={"x": -16}) # move each input image by 16px to the left
images[4] = translater.augment_image(images[4]) # move image 4 to the left
scaler = iaa.Affine(scale={"y": (0.8, 1.2)}) # scale each input image to 80-120% on the y axis
images[5] = scaler.augment_image(images[5]) # scale image 5 by 80-120% on the y axis
示例4: _load_augmentation_aug_geometric
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Flipud [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)))])
])
示例5: example_using_augmenters_only_once
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Flipud [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)
示例6: test_returns_flipud
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Flipud [as 别名]
def test_returns_flipud(self):
aug = iaa.VerticalFlip(0.5)
assert isinstance(aug, iaa.Flipud)
assert np.allclose(aug.p.p.value, 0.5)
示例7: create_aug
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Flipud [as 别名]
def create_aug(self, *args, **kwargs):
return iaa.Flipud(*args, **kwargs)
示例8: apply_augment_sequence
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Flipud [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
示例9: aug_on_fly
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Flipud [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
示例10: chapter_augmenters_flipud
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Flipud [as 别名]
def chapter_augmenters_flipud():
aug = iaa.Flipud(0.5)
run_and_save_augseq(
"flipud.jpg", aug,
[ia.quokka(size=(64, 64)) for _ in range(16)], cols=8, rows=2
)
示例11: test_find
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Flipud [as 别名]
def test_find():
reseed()
noop1 = iaa.Noop(name="Noop")
fliplr = iaa.Fliplr(name="Fliplr")
flipud = iaa.Flipud(name="Flipud")
noop2 = iaa.Noop(name="Noop2")
seq2 = iaa.Sequential([flipud, noop2], name="Seq2")
seq1 = iaa.Sequential([noop1, fliplr, seq2], name="Seq")
augs = seq1.find_augmenters_by_name("Seq")
assert len(augs) == 1
assert augs[0] == seq1
augs = seq1.find_augmenters_by_name("Seq2")
assert len(augs) == 1
assert augs[0] == seq2
augs = seq1.find_augmenters_by_names(["Seq", "Seq2"])
assert len(augs) == 2
assert augs[0] == seq1
assert augs[1] == seq2
augs = seq1.find_augmenters_by_name(r"Seq.*", regex=True)
assert len(augs) == 2
assert augs[0] == seq1
assert augs[1] == seq2
augs = seq1.find_augmenters(lambda aug, parents: aug.name in ["Seq", "Seq2"])
assert len(augs) == 2
assert augs[0] == seq1
assert augs[1] == seq2
augs = seq1.find_augmenters(lambda aug, parents: aug.name in ["Seq", "Seq2"] and len(parents) > 0)
assert len(augs) == 1
assert augs[0] == seq2
augs = seq1.find_augmenters(lambda aug, parents: aug.name in ["Seq", "Seq2"], flat=False)
assert len(augs) == 2
assert augs[0] == seq1
assert augs[1] == [seq2]
示例12: test_remove
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Flipud [as 别名]
def test_remove():
reseed()
def get_seq():
noop1 = iaa.Noop(name="Noop")
fliplr = iaa.Fliplr(name="Fliplr")
flipud = iaa.Flipud(name="Flipud")
noop2 = iaa.Noop(name="Noop2")
seq2 = iaa.Sequential([flipud, noop2], name="Seq2")
seq1 = iaa.Sequential([noop1, fliplr, seq2], name="Seq")
return seq1
augs = get_seq()
augs = augs.remove_augmenters(lambda aug, parents: aug.name == "Seq2")
seqs = augs.find_augmenters_by_name(r"Seq.*", regex=True)
assert len(seqs) == 1
assert seqs[0].name == "Seq"
augs = get_seq()
augs = augs.remove_augmenters(lambda aug, parents: aug.name == "Seq2" and len(parents) == 0)
seqs = augs.find_augmenters_by_name(r"Seq.*", regex=True)
assert len(seqs) == 2
assert seqs[0].name == "Seq"
assert seqs[1].name == "Seq2"
augs = get_seq()
augs = augs.remove_augmenters(lambda aug, parents: True)
assert augs is not None
assert isinstance(augs, iaa.Noop)
augs = get_seq()
augs = augs.remove_augmenters(lambda aug, parents: True, noop_if_topmost=False)
assert augs is None
示例13: __init__
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Flipud [as 别名]
def __init__(self):
self.imgaug_transform = iaa.Flipud(p=1)
self.augmentor_op = Operations.Flip(probability=1, top_bottom_left_right="TOP_BOTTOM")
self.solt_stream = slc.Stream([slt.RandomFlip(p=1, axis=0)])
示例14: processor
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Flipud [as 别名]
def processor(self):
return iaa.Flipud(1)
示例15: train
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Flipud [as 别名]
def train(model, dataset_dir, subset):
"""Train the model."""
# Training dataset.
dataset_train = NucleusDataset()
dataset_train.load_nucleus(dataset_dir, subset)
dataset_train.prepare()
# Validation dataset
dataset_val = NucleusDataset()
dataset_val.load_nucleus(dataset_dir, "val")
dataset_val.prepare()
# Image augmentation
# http://imgaug.readthedocs.io/en/latest/source/augmenters.html
augmentation = iaa.SomeOf((0, 2), [
iaa.Fliplr(0.5),
iaa.Flipud(0.5),
iaa.OneOf([iaa.Affine(rotate=90),
iaa.Affine(rotate=180),
iaa.Affine(rotate=270)]),
iaa.Multiply((0.8, 1.5)),
iaa.GaussianBlur(sigma=(0.0, 5.0))
])
# *** This training schedule is an example. Update to your needs ***
# If starting from imagenet, train heads only for a bit
# since they have random weights
print("Train network heads")
model.train(dataset_train, dataset_val,
learning_rate=config.LEARNING_RATE,
epochs=20,
augmentation=augmentation,
layers='heads')
print("Train all layers")
model.train(dataset_train, dataset_val,
learning_rate=config.LEARNING_RATE,
epochs=40,
augmentation=augmentation,
layers='all')
############################################################
# RLE Encoding
############################################################