Skip to content

Commit

Permalink
Fix Jigsaw test failing
Browse files Browse the repository at this point in the history
  • Loading branch information
aleju committed Dec 21, 2019
1 parent 91a0c56 commit c5015df
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
8 changes: 6 additions & 2 deletions checks/check_jigsaw.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@

def main():
image = ia.quokka_square((200, 200))
kpsoi = ia.quokka_keypoints((200, 200), extract="square")
aug = iaa.Jigsaw(10, 10)

images_aug = aug(images=[image] * 16)
ia.imshow(ia.draw_grid(images_aug))
images_aug, kpsois_aug = aug(images=[image] * 16,
keypoints=[kpsoi] * 16)
images_show = [kpsoi_aug.draw_on_image(image_aug)
for image_aug, kpsoi_aug in zip(images_aug, kpsois_aug)]
ia.imshow(ia.draw_grid(images_show))

gen_time = timeit.timeit(
"iaa.generate_jigsaw_destinations(10, 10, 2, rng)",
Expand Down
21 changes: 13 additions & 8 deletions test/augmenters/test_geometric.py
Original file line number Diff line number Diff line change
Expand Up @@ -9965,14 +9965,17 @@ def test_images_and_segmaps_aligned(self):
assert nb_changed > 5

def test_images_and_keypoints_aligned(self):
rs = iarandom.RNG(0)
for _ in np.arange(10):
aug = iaa.Jigsaw(nb_rows=(2, 5), nb_cols=(2, 5), max_steps=(0, 3))
y = rs.integers(0, 20, size=(1,), endpoint=False)
x = rs.integers(0, 30, size=(1,), endpoint=False)
kpsoi = ia.KeypointsOnImage([ia.Keypoint(x=x, y=y)], shape=(20, 30))
for i in np.arange(20):
aug = iaa.Jigsaw(nb_rows=(1, 3), nb_cols=(1, 3), max_steps=(2, 5),
random_state=i)
# make sure that these coords are not exactly at a grid cell
# border with any possibly sampled height/width in grid cells
y = 17.5
x = 25.5
kpsoi = ia.KeypointsOnImage([ia.Keypoint(x=x, y=y)],
shape=(20, 30))
image = np.zeros((20, 30), dtype=np.uint8)
image[y, x] = 255
image[int(y), int(x)] = 255

images_aug, kpsois_aug = aug(images=[image, image, image],
keypoints=[kpsoi, kpsoi, kpsoi])
Expand All @@ -9984,7 +9987,9 @@ def test_images_and_keypoints_aligned(self):
y_aug_img, x_aug_img = np.unravel_index(idx,
image_aug.shape)
dist = np.sqrt((x_aug - x_aug_img)**2 + (y_aug - y_aug_img)**2)
assert dist < 1.5
# best possible distance is about 0.7 as KP coords are in cell
# center and sampled coords are at cell top left
assert dist < 0.8

def test_no_error_for_1x1_grids(self):
aug = iaa.Jigsaw(nb_rows=1, nb_cols=1, max_steps=2)
Expand Down

0 comments on commit c5015df

Please sign in to comment.