-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add basic tests and support for arbitrarily batched positions in 3D (#4)
- Loading branch information
1 parent
1253df6
commit ab35a93
Showing
4 changed files
with
84 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import torch | ||
|
||
from torch_subpixel_crop import subpixel_crop_2d | ||
|
||
|
||
def test_subpixel_crop_single_2d(): | ||
image = torch.zeros((10, 10)) | ||
image[4:6, 4:6] = 1 | ||
|
||
cropped_image = subpixel_crop_2d( | ||
image=image, | ||
positions=torch.tensor([5, 5]).float(), | ||
sidelength=4 | ||
) | ||
assert cropped_image.shape == (4, 4) | ||
|
||
expected = torch.zeros((4, 4)) | ||
expected[1:3, 1:3] = 1 | ||
assert torch.allclose(cropped_image, expected) | ||
|
||
|
||
def test_subpixel_crop_multi_2d(): | ||
image = torch.zeros((10, 10)) | ||
image[4:6, 4:6] = 1 | ||
|
||
cropped_image = subpixel_crop_2d( | ||
image=image, | ||
positions=torch.tensor([[4, 4], [5, 5]]).float(), | ||
sidelength=4 | ||
) | ||
assert cropped_image.shape == (2, 4, 4) | ||
|
||
expected_0 = torch.zeros((4, 4)) | ||
expected_0[2:4, 2:4] = 1 | ||
assert torch.allclose(cropped_image[0], expected_0) | ||
|
||
expected_1 = torch.zeros((4, 4)) | ||
expected_1[1:3, 1:3] = 1 | ||
assert torch.allclose(cropped_image[1], expected_1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import torch | ||
|
||
from torch_subpixel_crop import subpixel_crop_3d | ||
|
||
|
||
def test_subpixel_crop_single_3d(): | ||
image = torch.zeros((10, 10, 10)) | ||
image[4:6, 4:6, 4:6] = 1 | ||
|
||
cropped_image = subpixel_crop_3d( | ||
image=image, | ||
positions=torch.tensor([5, 5, 5]).float(), | ||
sidelength=4 | ||
) | ||
assert cropped_image.shape == (4, 4, 4) | ||
|
||
expected = torch.zeros((4, 4, 4)) | ||
expected[1:3, 1:3, 1:3] = 1 | ||
assert torch.allclose(cropped_image, expected) | ||
|
||
|
||
def test_subpixel_crop_multi_3d(): | ||
image = torch.zeros((10, 10, 10)) | ||
image[4:6, 4:6, 4:6] = 1 | ||
|
||
cropped_image = subpixel_crop_3d( | ||
image=image, | ||
positions=torch.tensor([[4, 4, 4], [5, 5, 5]]).float(), | ||
sidelength=4 | ||
) | ||
assert cropped_image.shape == (2, 4, 4, 4) | ||
|
||
expected_0 = torch.zeros((4, 4, 4)) | ||
expected_0[2:4, 2:4, 2:4] = 1 | ||
assert torch.allclose(cropped_image[0], expected_0) | ||
|
||
expected_1 = torch.zeros((4, 4, 4)) | ||
expected_1[1:3, 1:3, 1:3] = 1 | ||
assert torch.allclose(cropped_image[1], expected_1) |
This file was deleted.
Oops, something went wrong.