-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
322 additions
and
34 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
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
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
50 changes: 50 additions & 0 deletions
50
tests/pytorch_learner/dataset/visualizer/test_classification_visualizer.py
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,50 @@ | ||
from typing import Callable | ||
import unittest | ||
|
||
import torch | ||
|
||
from rastervision.pytorch_learner.dataset import ClassificationVisualizer | ||
|
||
|
||
class TestClassificationVisualizer(unittest.TestCase): | ||
def assertNoError(self, fn: Callable, msg: str = ''): | ||
try: | ||
fn() | ||
except Exception: | ||
self.fail(msg) | ||
|
||
def test_plot_batch(self): | ||
# w/o z | ||
viz = ClassificationVisualizer( | ||
class_names=['bg', 'fg'], | ||
channel_display_groups=dict(RGB=[0, 1, 2], IR=[3])) | ||
x = torch.randn(size=(2, 4, 256, 256)) | ||
y = torch.tensor([0, 1]) | ||
self.assertNoError(lambda: viz.plot_batch(x, y)) | ||
|
||
# w/ z | ||
viz = ClassificationVisualizer( | ||
class_names=['bg', 'fg'], | ||
channel_display_groups=dict(RGB=[0, 1, 2], IR=[3])) | ||
x = torch.randn(size=(2, 4, 256, 256)) | ||
y = torch.tensor([0, 1]) | ||
z = torch.tensor([[0.9, 0.1], [0.6, 0.4]]) | ||
self.assertNoError(lambda: viz.plot_batch(x, y, z=z)) | ||
|
||
def test_plot_batch_temporal(self): | ||
# w/o z | ||
viz = ClassificationVisualizer( | ||
class_names=['bg', 'fg'], | ||
channel_display_groups=dict(RGB=[0, 1, 2], IR=[3])) | ||
x = torch.randn(size=(2, 3, 4, 256, 256)) | ||
y = torch.tensor([0, 1]) | ||
self.assertNoError(lambda: viz.plot_batch(x, y)) | ||
|
||
# w/ z | ||
viz = ClassificationVisualizer( | ||
class_names=['bg', 'fg'], | ||
channel_display_groups=dict(RGB=[0, 1, 2], IR=[3])) | ||
x = torch.randn(size=(2, 3, 4, 256, 256)) | ||
y = torch.tensor([0, 1]) | ||
z = torch.tensor([[0.9, 0.1], [0.6, 0.4]]) | ||
self.assertNoError(lambda: viz.plot_batch(x, y, z=z)) |
61 changes: 61 additions & 0 deletions
61
tests/pytorch_learner/dataset/visualizer/test_object_detection_visualizer.py
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,61 @@ | ||
from typing import Callable | ||
import unittest | ||
|
||
import torch | ||
|
||
from rastervision.core.box import Box | ||
from rastervision.pytorch_learner.dataset import (ObjectDetectionVisualizer, | ||
BoxList) | ||
|
||
|
||
def random_boxlist(x, nboxes: int = 5) -> BoxList: | ||
extent = Box(0, 0, *x.shape[-2:]) | ||
boxes = [extent.make_random_square(50) for _ in range(nboxes)] | ||
npboxes = torch.from_numpy(Box.to_npboxes(boxes)) | ||
class_ids = torch.randint(0, 2, size=(nboxes, )) | ||
scores = torch.rand(nboxes) | ||
return BoxList(npboxes, class_ids=class_ids, scores=scores) | ||
|
||
|
||
class TestClassificationVisualizer(unittest.TestCase): | ||
def assertNoError(self, fn: Callable, msg: str = ''): | ||
try: | ||
fn() | ||
except Exception: | ||
self.fail(msg) | ||
|
||
def test_plot_batch(self): | ||
# w/o z | ||
viz = ObjectDetectionVisualizer( | ||
class_names=['bg', 'fg'], | ||
channel_display_groups=dict(RGB=[0, 1, 2], IR=[3])) | ||
x = torch.randn(size=(2, 4, 256, 256)) | ||
y = [random_boxlist(_x) for _x in x] | ||
self.assertNoError(lambda: viz.plot_batch(x, y)) | ||
|
||
# w/ z | ||
viz = ObjectDetectionVisualizer( | ||
class_names=['bg', 'fg'], | ||
channel_display_groups=dict(RGB=[0, 1, 2], IR=[3])) | ||
x = torch.randn(size=(2, 4, 256, 256)) | ||
y = [random_boxlist(_x) for _x in x] | ||
z = [random_boxlist(_x) for _x in x] | ||
self.assertNoError(lambda: viz.plot_batch(x, y, z=z)) | ||
|
||
def test_plot_batch_temporal(self): | ||
# w/o z | ||
viz = ObjectDetectionVisualizer( | ||
class_names=['bg', 'fg'], | ||
channel_display_groups=dict(RGB=[0, 1, 2], IR=[3])) | ||
x = torch.randn(size=(2, 3, 4, 256, 256)) | ||
y = [random_boxlist(_x) for _x in x] | ||
self.assertNoError(lambda: viz.plot_batch(x, y)) | ||
|
||
# w/ z | ||
viz = ObjectDetectionVisualizer( | ||
class_names=['bg', 'fg'], | ||
channel_display_groups=dict(RGB=[0, 1, 2], IR=[3])) | ||
x = torch.randn(size=(2, 3, 4, 256, 256)) | ||
y = [random_boxlist(_x) for _x in x] | ||
z = [random_boxlist(_x) for _x in x] | ||
self.assertNoError(lambda: viz.plot_batch(x, y, z=z)) |
Oops, something went wrong.