def test_pickleable(self): shape = (16, 16, 3) image = np.mod(np.arange(int(np.prod(shape))), 256).astype(np.uint8) image = image.reshape(shape) with TemporaryDirectory() as folder_path: path1 = os.path.join(folder_path, "batch_000000.png") path2 = os.path.join(folder_path, "batch_000010.png") augmenter = iaa.SaveDebugImageEveryNBatches(folder_path, 10) augmenter_pkl = pickle.loads(pickle.dumps(augmenter, protocol=-1)) # save two images via augmenter without pickling for _ in np.arange(20): _ = augmenter(image=image) img11 = imageio.imread(path1) img12 = imageio.imread(path2) # reset folder content os.remove(path1) os.remove(path2) # save two images via augmenter that was pickled for _ in np.arange(20): _ = augmenter_pkl(image=image) img21 = imageio.imread(path1) img22 = imageio.imread(path2) # compare the two images of original/pickled augmenters assert np.array_equal(img11, img21) assert np.array_equal(img12, img22)
def chapter_augmenters_savedebugimageeverynbatches(): fn_start = "debug/savedebugimageeverynbatches" image = ia.quokka_square((128, 128)) bbsoi = ia.quokka_bounding_boxes((128, 128), extract="square") segmaps = ia.quokka_segmentation_map((128, 128), extract="square") with tempfile.TemporaryDirectory() as folder_path: seq = iaa.Sequential([ iaa.Sequential( [iaa.Fliplr(0.5), iaa.Crop(px=(0, 16))], random_order=True), iaa.SaveDebugImageEveryNBatches(folder_path, 100) ]) _ = seq(images=[image] * 4, segmentation_maps=[segmaps] * 4, bounding_boxes=[bbsoi] * 4) image_debug_path = os.path.join(folder_path, "batch_latest.png") image_debug = imageio.imread(image_debug_path) utils.save("overview_of_augmenters", fn_start + ".jpg", image_debug, quality=95)
def test_temp_directory(self): with TemporaryDirectory() as folder_path: image = iarandom.RNG(0).integers(0, 256, size=(256, 256, 3), dtype=np.uint8) aug = iaa.SaveDebugImageEveryNBatches(folder_path, 10) for _ in np.arange(20): _ = aug(image=image) expected = iaa.draw_debug_image([image]) path1 = os.path.join(folder_path, "batch_000000.png") path2 = os.path.join(folder_path, "batch_000010.png") path_latest = os.path.join(folder_path, "batch_latest.png") assert len(list(os.listdir(folder_path))) == 3 assert os.path.isfile(path1) assert os.path.isfile(path2) assert os.path.isfile(path_latest) assert np.array_equal(imageio.imread(path1), expected) assert np.array_equal(imageio.imread(path2), expected) assert np.array_equal(imageio.imread(path_latest), expected)
def test_mocked(self): class _DummyDestination(debuglib._IImageDestination): def __init__(self): self.received = [] def receive(self, image): self.received.append(np.copy(image)) image = iarandom.RNG(0).integers(0, 256, size=(256, 256, 3), dtype=np.uint8) destination = _DummyDestination() aug = iaa.SaveDebugImageEveryNBatches(destination, 10) for _ in np.arange(20): _ = aug(image=image) expected = iaa.draw_debug_image([image]) assert len(destination.received) == 2 assert np.array_equal(destination.received[0], expected) assert np.array_equal(destination.received[1], expected)
def generate_debug(): ia.seed(1) image = ia.quokka_square((128, 128)) bbsoi = ia.quokka_bounding_boxes((128, 128), extract="square") segmaps = ia.quokka_segmentation_map((128, 128), extract="square") with tempfile.TemporaryDirectory() as folder_path: seq = iaa.Sequential([ iaa.Sequential( [iaa.Fliplr(0.5), iaa.Crop(px=(0, 16))], random_order=True), iaa.SaveDebugImageEveryNBatches(folder_path, 100) ]) _ = seq(images=[image] * 4, segmentation_maps=[segmaps] * 4, bounding_boxes=[bbsoi] * 4) image_debug_path = os.path.join(folder_path, "batch_latest.png") image_debug = imageio.imread(image_debug_path) _save("savedebugimageeverynbatches.jpg", image_debug)