本文整理汇总了Python中imgaug.seed方法的典型用法代码示例。如果您正苦于以下问题:Python imgaug.seed方法的具体用法?Python imgaug.seed怎么用?Python imgaug.seed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类imgaug
的用法示例。
在下文中一共展示了imgaug.seed方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import seed [as 别名]
def main():
img = data.astronaut()
img = misc.imresize(img, (64, 64))
aug = iaa.Fliplr(0.5)
unseeded1 = aug.draw_grid(img, cols=8, rows=1)
unseeded2 = aug.draw_grid(img, cols=8, rows=1)
ia.seed(1000)
seeded1 = aug.draw_grid(img, cols=8, rows=1)
seeded2 = aug.draw_grid(img, cols=8, rows=1)
ia.seed(1000)
reseeded1 = aug.draw_grid(img, cols=8, rows=1)
reseeded2 = aug.draw_grid(img, cols=8, rows=1)
ia.seed(1001)
reseeded3 = aug.draw_grid(img, cols=8, rows=1)
reseeded4 = aug.draw_grid(img, cols=8, rows=1)
all_rows = np.vstack([unseeded1, unseeded2, seeded1, seeded2, reseeded1, reseeded2, reseeded3, reseeded4])
misc.imshow(all_rows)
示例2: run_and_save_augseq
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import seed [as 别名]
def run_and_save_augseq(filename, augseq, images, cols, rows, quality=75, seed=1):
ia.seed(seed)
# augseq may be a single seq (applied to all images) or a list (one seq per
# image).
# use type() here instead of isinstance, because otherwise Sequential is
# also interpreted as a list
if type(augseq) == list:
# one augmenter per image specified
assert len(augseq) == len(images)
images_aug = [augseq[i].augment_image(images[i]) for i in range(len(images))]
else:
# calling N times augment_image() is here critical for random order in
# Sequential
images_aug = [augseq.augment_image(images[i]) for i in range(len(images))]
save(
"overview_of_augmenters",
filename,
grid(images_aug, cols=cols, rows=rows),
quality=quality
)
示例3: chapter_augmenters_sometimes
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import seed [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
)
示例4: chapter_augmenters_coarsedropout
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import seed [as 别名]
def chapter_augmenters_coarsedropout():
aug = iaa.CoarseDropout(0.02, size_percent=0.5)
run_and_save_augseq(
"coarsedropout.jpg", aug,
[ia.quokka(size=(128, 128)) for _ in range(8)], cols=4, rows=2,
quality=75
)
aug = iaa.CoarseDropout((0.0, 0.05), size_percent=(0.02, 0.25))
run_and_save_augseq(
"coarsedropout_both_uniform.jpg", aug,
[ia.quokka(size=(128, 128)) for _ in range(8)], cols=4, rows=2,
quality=75,
seed=2
)
aug = iaa.CoarseDropout(0.02, size_percent=0.15, per_channel=0.5)
run_and_save_augseq(
"coarsedropout_per_channel.jpg", aug,
[ia.quokka(size=(128, 128)) for _ in range(8)], cols=4, rows=2,
quality=75,
seed=2
)
示例5: test_transform_pipeline_serialization
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import seed [as 别名]
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"])
示例6: test_transform_pipeline_serialization_with_keypoints
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import seed [as 别名]
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"])
示例7: test_lambda_serialization
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import seed [as 别名]
def test_lambda_serialization(image, mask, albumentations_bboxes, keypoints, seed, p):
def vflip_image(image, **kwargs):
return F.vflip(image)
def vflip_mask(mask, **kwargs):
return F.vflip(mask)
def vflip_bbox(bbox, **kwargs):
return F.bbox_vflip(bbox, **kwargs)
def vflip_keypoint(keypoint, **kwargs):
return F.keypoint_vflip(keypoint, **kwargs)
aug = A.Lambda(name="vflip", image=vflip_image, mask=vflip_mask, bbox=vflip_bbox, keypoint=vflip_keypoint, p=p)
serialized_aug = A.to_dict(aug)
deserialized_aug = A.from_dict(serialized_aug, lambda_transforms={"vflip": aug})
set_seed(seed)
aug_data = aug(image=image, mask=mask, bboxes=albumentations_bboxes, keypoints=keypoints)
set_seed(seed)
deserialized_aug_data = deserialized_aug(image=image, mask=mask, bboxes=albumentations_bboxes, keypoints=keypoints)
assert np.array_equal(aug_data["image"], deserialized_aug_data["image"])
assert np.array_equal(aug_data["mask"], deserialized_aug_data["mask"])
assert np.array_equal(aug_data["bboxes"], deserialized_aug_data["bboxes"])
assert np.array_equal(aug_data["keypoints"], deserialized_aug_data["keypoints"])
示例8: test_seed
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import seed [as 别名]
def test_seed(mock_seed):
ia.seed(10017)
mock_seed.assert_called_once_with(10017)
示例9: test_new_random_state__induce_pseudo_random
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import seed [as 别名]
def test_new_random_state__induce_pseudo_random(mock_rng):
with warnings.catch_warnings(record=True) as caught_warnings:
warnings.simplefilter("always")
_ = ia.new_random_state(seed=None, fully_random=False)
assert mock_rng.create_pseudo_random_.call_count == 1
assert len(caught_warnings) == 1
assert "is deprecated" in str(caught_warnings[-1].message)
示例10: test_new_random_state__induce_fully_random
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import seed [as 别名]
def test_new_random_state__induce_fully_random(mock_rng):
with warnings.catch_warnings(record=True) as caught_warnings:
warnings.simplefilter("always")
_ = ia.new_random_state(seed=None, fully_random=True)
assert mock_rng.create_fully_random.call_count == 1
assert len(caught_warnings) == 1
assert "is deprecated" in str(caught_warnings[-1].message)
示例11: test_new_random_state__use_seed
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import seed [as 别名]
def test_new_random_state__use_seed(mock_rng):
with warnings.catch_warnings(record=True) as caught_warnings:
warnings.simplefilter("always")
_ = ia.new_random_state(seed=1)
mock_rng.assert_called_once_with(1)
assert len(caught_warnings) == 1
assert "is deprecated" in str(caught_warnings[-1].message)
示例12: data_agumentation
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import seed [as 别名]
def data_agumentation(img, gt_bbox, operation_obj, txts=None, save_flag=None):
ia.seed(int((time.time() * 1000) % 100000))
shape = np.shape(gt_bbox)
[h, w, _] = np.shape(img)
if shape[1] == 8:
bboxes = np.reshape(gt_bbox, [-1, 4, 2])
else:
bboxes = gt_bbox
keypoints_on_images = []
keypoints_imgaug_obj = []
# print bboxes
# print np.shape(bboxes)
for key_points in bboxes:
# print key_points
for key_point in key_points:
keypoints_imgaug_obj.append(ia.Keypoint(x=key_point[0], y=key_point[1]))
keypoints_on_images.append(ia.KeypointsOnImage(keypoints_imgaug_obj, shape=img.shape))
seq_det = operation_obj.to_deterministic()
img_aug = seq_det.augment_image(img)
key_points_aug = seq_det.augment_keypoints(keypoints_on_images)
key_points_after = []
for idx, (keypoints_before, keypoints_after) in enumerate(zip(keypoints_on_images, key_points_aug)):
for kp_idx, keypoint in enumerate(keypoints_after.keypoints):
keypoint.x = keypoint.x if keypoint.x < w else w
keypoint.x = keypoint.x if keypoint.x > 0 else 0
keypoint.y = keypoint.y if keypoint.y < h else h
keypoint.y = keypoint.y if keypoint.y > 0 else 0
key_points_after.append([keypoint.x, keypoint.y])
# print np.shape(key_points_after)
key_points_after = np.reshape(key_points_after, [-1, 4, 2])
if save_flag:
save_gt_file('./rotated_10.txt', np.reshape(key_points_after, [-1, 8]), txts=txts)
cv2.imwrite('./rotated_10.png', img_aug)
vis_img_bbox('./rotated_10.png', './rotated_10.txt')
return img_aug, np.asarray(key_points_after, np.float32)
示例13: chapter_examples_bounding_boxes_projection
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import seed [as 别名]
def chapter_examples_bounding_boxes_projection():
import imgaug as ia
from imgaug import augmenters as iaa
ia.seed(1)
# Define image with two bounding boxes
image = ia.quokka(size=(256, 256))
bbs = ia.BoundingBoxesOnImage([
ia.BoundingBox(x1=25, x2=75, y1=25, y2=75),
ia.BoundingBox(x1=100, x2=150, y1=25, y2=75)
], shape=image.shape)
# Rescale image and bounding boxes
image_rescaled = ia.imresize_single_image(image, (512, 512))
bbs_rescaled = bbs.on(image_rescaled)
# Draw image before/after rescaling and with rescaled bounding boxes
image_bbs = bbs.draw_on_image(image, thickness=2)
image_rescaled_bbs = bbs_rescaled.draw_on_image(image_rescaled, thickness=2)
# ------------
save(
"examples_bounding_boxes",
"projection.jpg",
grid([image_bbs, image_rescaled_bbs], cols=2, rows=1),
quality=75
)
示例14: reseed
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import seed [as 别名]
def reseed(seed=0):
ia.seed(seed)
np.random.seed(seed)
random.seed(seed)
示例15: set_seed
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import seed [as 别名]
def set_seed(seed):
random.seed(seed)
np.random.seed(seed)