This repository has been archived by the owner on Jul 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into train-ssd
- Loading branch information
Showing
19 changed files
with
298 additions
and
102 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
from chainercv.utils.testing.assertions import assert_is_bbox # NOQA | ||
from chainercv.utils.testing.assertions import assert_is_detection_dataset # NOQA | ||
from chainercv.utils.testing.assertions import assert_is_detection_link # NOQA | ||
from chainercv.utils.testing.assertions import assert_is_image # NOQA | ||
from chainercv.utils.testing.assertions import assert_is_semantic_segmentation_dataset # NOQA | ||
from chainercv.utils.testing.assertions import assert_is_semantic_segmentation_link # NOQA | ||
from chainercv.utils.testing.constant_stub_link import ConstantStubLink # NOQA | ||
from chainercv.utils.testing.generate_random_bbox import generate_random_bbox # NOQA |
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
from chainercv.utils.testing.assertions.assert_is_bbox import assert_is_bbox # NOQA | ||
from chainercv.utils.testing.assertions.assert_is_detection_dataset import assert_is_detection_dataset # NOQA | ||
from chainercv.utils.testing.assertions.assert_is_detection_link import assert_is_detection_link # NOQA | ||
from chainercv.utils.testing.assertions.assert_is_image import assert_is_image # NOQA | ||
from chainercv.utils.testing.assertions.assert_is_semantic_segmentation_dataset import assert_is_semantic_segmentation_dataset # NOQA | ||
from chainercv.utils.testing.assertions.assert_is_semantic_segmentation_link import assert_is_semantic_segmentation_link # NOQA |
59 changes: 59 additions & 0 deletions
59
chainercv/utils/testing/assertions/assert_is_detection_link.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,59 @@ | ||
import numpy as np | ||
import six | ||
|
||
from chainercv.utils.testing.assertions.assert_is_bbox import assert_is_bbox | ||
|
||
|
||
def assert_is_detection_link(link, n_fg_class): | ||
"""Checks if a link satisfies detection link APIs. | ||
This function checks if a given link satisfies detection link APIs | ||
or not. | ||
If the link does not satifiy the APIs, this function raises an | ||
:class:`AssertionError`. | ||
Args: | ||
link: A link to be checked. | ||
n_fg_class (int): The number of foreground classes. | ||
""" | ||
|
||
imgs = [ | ||
np.random.randint(0, 256, size=(3, 480, 640)).astype(np.float32), | ||
np.random.randint(0, 256, size=(3, 480, 320)).astype(np.float32)] | ||
|
||
result = link.predict(imgs) | ||
assert len(result) == 3, \ | ||
'Link must return three elements: bboxes, labels and scores.' | ||
bboxes, labels, scores = result | ||
|
||
assert len(bboxes) == len(imgs), \ | ||
'The length of bboxes must be same as that of imgs.' | ||
assert len(labels) == len(imgs), \ | ||
'The length of labels must be same as that of imgs.' | ||
assert len(scores) == len(imgs), \ | ||
'The length of scores must be same as that of imgs.' | ||
|
||
for bbox, label, score in six.moves.zip(bboxes, labels, scores): | ||
assert_is_bbox(bbox) | ||
|
||
assert isinstance(label, np.ndarray), \ | ||
'label must be a numpy.ndarray.' | ||
assert label.dtype == np.int32, \ | ||
'The type of label must be numpy.int32.' | ||
assert label.shape[1:] == (), \ | ||
'The shape of label must be (*,).' | ||
assert len(label) == len(bbox), \ | ||
'The length of label must be same as that of bbox.' | ||
if len(label) > 0: | ||
assert label.min() >= 0 and label.max() < n_fg_class, \ | ||
'The value of label must be in [0, n_fg_class - 1].' | ||
|
||
assert isinstance(score, np.ndarray), \ | ||
'score must be a numpy.ndarray.' | ||
assert score.dtype == np.float32, \ | ||
'The type of score must be numpy.float32.' | ||
assert score.shape[1:] == (), \ | ||
'The shape of score must be (*,).' | ||
assert len(score) == len(bbox), \ | ||
'The length of score must be same as that of bbox.' |
35 changes: 35 additions & 0 deletions
35
chainercv/utils/testing/assertions/assert_is_semantic_segmentation_link.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,35 @@ | ||
import numpy as np | ||
import six | ||
|
||
|
||
def assert_is_semantic_segmentation_link(link, n_class): | ||
"""Checks if a link satisfies semantic segmentation link APIs. | ||
This function checks if a given link satisfies semantic segmentation link | ||
APIs or not. | ||
If the link does not satifiy the APIs, this function raises an | ||
:class:`AssertionError`. | ||
Args: | ||
link: A link to be checked. | ||
n_class (int): The number of classes including background. | ||
""" | ||
|
||
imgs = [ | ||
np.random.randint(0, 256, size=(3, 480, 640)).astype(np.float32), | ||
np.random.randint(0, 256, size=(3, 480, 320)).astype(np.float32)] | ||
|
||
labels = link.predict(imgs) | ||
assert len(labels) == len(imgs), \ | ||
'The length of labels must be same as that of imgs.' | ||
|
||
for img, label in six.moves.zip(imgs, labels): | ||
assert isinstance(label, np.ndarray), \ | ||
'label must be a numpy.ndarray.' | ||
assert label.dtype == np.int32, \ | ||
'The type of label must be numpy.int32.' | ||
assert label.shape == img.shape[1:], \ | ||
'The shape of label must be (H, W).' | ||
assert label.min() >= 0 and label.max() < n_class, \ | ||
'The value of label must be in [0, n_class - 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
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
Oops, something went wrong.