From 954eaf5c623a8bad52bcd9e4515ab486f1acce39 Mon Sep 17 00:00:00 2001 From: Yusuke Niitani Date: Tue, 27 Feb 2018 14:07:34 +0900 Subject: [PATCH 1/5] vis_keypoint --> vis_point --- chainercv/visualizations/__init__.py | 2 +- .../{vis_keypoint.py => vis_point.py} | 38 +++++++++---------- docs/source/reference/visualizations.rst | 6 +-- ...test_vis_keypoint.py => test_vis_point.py} | 14 +++---- 4 files changed, 30 insertions(+), 30 deletions(-) rename chainercv/visualizations/{vis_keypoint.py => vis_point.py} (52%) rename tests/visualizations_tests/{test_vis_keypoint.py => test_vis_point.py} (57%) diff --git a/chainercv/visualizations/__init__.py b/chainercv/visualizations/__init__.py index 1572a7ff8f..9449ed8a8e 100644 --- a/chainercv/visualizations/__init__.py +++ b/chainercv/visualizations/__init__.py @@ -1,4 +1,4 @@ from chainercv.visualizations.vis_bbox import vis_bbox # NOQA from chainercv.visualizations.vis_image import vis_image # NOQA -from chainercv.visualizations.vis_keypoint import vis_keypoint # NOQA +from chainercv.visualizations.vis_point import vis_point # NOQA from chainercv.visualizations.vis_semantic_segmentation import vis_semantic_segmentation # NOQA diff --git a/chainercv/visualizations/vis_keypoint.py b/chainercv/visualizations/vis_point.py similarity index 52% rename from chainercv/visualizations/vis_keypoint.py rename to chainercv/visualizations/vis_point.py index 6974593652..115dc5d992 100644 --- a/chainercv/visualizations/vis_keypoint.py +++ b/chainercv/visualizations/vis_point.py @@ -4,16 +4,16 @@ from chainercv.visualizations.vis_image import vis_image -def vis_keypoint(img, keypoint, kp_mask=None, ax=None): - """Visualize keypoints in an image. +def vis_point(img, point, mask=None, ax=None): + """Visualize points in an image. Example: >>> import chainercv >>> import matplotlib.pyplot as plot >>> dataset = chainercv.datasets.CUBKeypointDataset() - >>> img, keypoint, kp_mask = dataset[0] - >>> chainercv.visualizations.vis_keypoint(img, keypoint, kp_mask) + >>> img, point, mask = dataset[0] + >>> chainercv.visualizations.vis_point(img, point, mask) >>> plot.show() Args: @@ -21,15 +21,15 @@ def vis_keypoint(img, keypoint, kp_mask=None, ax=None): This is in RGB format and the range of its value is :math:`[0, 255]`. This should be visualizable using :obj:`matplotlib.pyplot.imshow(img)` - keypoint (~numpy.ndarray): An array with keypoint pairs whose shape is - :math:`(K, 2)`, where :math:`K` is - the number of keypoints in the array. + point (~numpy.ndarray): An array of point coordinates whose shape is + :math:`(P, 2)`, where :math:`P` is + the number of points. The second axis corresponds to :math:`y` and :math:`x` coordinates - of the keypoint. - kp_mask (~numpy.ndarray, optional): A boolean array whose shape is - :math:`(K,)`. If :math:`i` th index is :obj:`True`, the - :math:`i` th keypoint is not displayed. If not specified, - all keypoints in :obj:`keypoint` will be displayed. + of the points. + mask (~numpy.ndarray, optional): A boolean array whose shape is + :math:`(P,)`. If :math:`i` th index is :obj:`True`, the + :math:`i` th point is not displayed. If not specified, + all points in :obj:`keypoint` will be displayed. ax (matplotlib.axes.Axes, optional): If provided, plot on this axis. Returns: @@ -42,18 +42,18 @@ def vis_keypoint(img, keypoint, kp_mask=None, ax=None): ax = vis_image(img, ax=ax) _, H, W = img.shape - n_kp = len(keypoint) + n_point = len(point) - if kp_mask is None: - kp_mask = np.ones((n_kp,), dtype=np.bool) + if mask is None: + mask = np.ones((n_point,), dtype=np.bool) cm = plot.get_cmap('gist_rainbow') - colors = [cm(1. * i / n_kp) for i in six.moves.range(n_kp)] + colors = [cm(1. * i / n_point) for i in six.moves.range(n_point)] - for i in range(n_kp): - if kp_mask[i]: - ax.scatter(keypoint[i][1], keypoint[i][0], c=colors[i], s=100) + for i in range(n_point): + if mask[i]: + ax.scatter(point[i][1], point[i][0], c=colors[i], s=100) ax.set_xlim(left=0, right=W) ax.set_ylim(bottom=H - 1, top=0) diff --git a/docs/source/reference/visualizations.rst b/docs/source/reference/visualizations.rst index a673a8d88f..c00682e6be 100644 --- a/docs/source/reference/visualizations.rst +++ b/docs/source/reference/visualizations.rst @@ -12,9 +12,9 @@ vis_image ~~~~~~~~~ .. autofunction:: vis_image -vis_keypoint -~~~~~~~~~~~~ -.. autofunction:: vis_keypoint +vis_point +~~~~~~~~~ +.. autofunction:: vis_point vis_semantic_segmentation ~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/tests/visualizations_tests/test_vis_keypoint.py b/tests/visualizations_tests/test_vis_point.py similarity index 57% rename from tests/visualizations_tests/test_vis_keypoint.py rename to tests/visualizations_tests/test_vis_point.py index 2cab9580b5..ffdddff089 100644 --- a/tests/visualizations_tests/test_vis_keypoint.py +++ b/tests/visualizations_tests/test_vis_point.py @@ -4,7 +4,7 @@ from chainer import testing -from chainercv.visualizations import vis_keypoint +from chainercv.visualizations import vis_point try: import matplotlib # NOQA @@ -14,17 +14,17 @@ @testing.parameterize( - {'kp_mask': np.array([True, True, False])}, - {'kp_mask': None} + {'mask': np.array([True, True, False])}, + {'mask': None} ) -class TestVisKeypoint(unittest.TestCase): +class TestVisPoint(unittest.TestCase): - def test_vis_keypoint(self): + def test_vis_point(self): if optional_modules: img = np.random.randint( 0, 255, size=(3, 32, 32)).astype(np.float32) - keypoint = np.random.uniform(size=(3, 2)).astype(np.float32) - ax = vis_keypoint(img, keypoint, self.kp_mask) + point = np.random.uniform(size=(3, 2)).astype(np.float32) + ax = vis_point(img, point, self.mask) self.assertTrue(isinstance(ax, matplotlib.axes.Axes)) From ed9b5aca98fa7aac21230c644f98187a9837c8e9 Mon Sep 17 00:00:00 2001 From: Yusuke Niitani Date: Tue, 27 Feb 2018 15:31:22 +0900 Subject: [PATCH 2/5] fix doc --- chainercv/visualizations/vis_point.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chainercv/visualizations/vis_point.py b/chainercv/visualizations/vis_point.py index 115dc5d992..69770c9a71 100644 --- a/chainercv/visualizations/vis_point.py +++ b/chainercv/visualizations/vis_point.py @@ -27,7 +27,7 @@ def vis_point(img, point, mask=None, ax=None): The second axis corresponds to :math:`y` and :math:`x` coordinates of the points. mask (~numpy.ndarray, optional): A boolean array whose shape is - :math:`(P,)`. If :math:`i` th index is :obj:`True`, the + :math:`(P,)`. If :math:`i` th element is :obj:`True`, the :math:`i` th point is not displayed. If not specified, all points in :obj:`keypoint` will be displayed. ax (matplotlib.axes.Axes, optional): If provided, plot on this axis. From da722f7cdc568b67a9f5bdaac341fef039262145 Mon Sep 17 00:00:00 2001 From: Yusuke Niitani Date: Wed, 28 Feb 2018 11:24:16 +0900 Subject: [PATCH 3/5] fix doc --- chainercv/visualizations/vis_point.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chainercv/visualizations/vis_point.py b/chainercv/visualizations/vis_point.py index 69770c9a71..0b952755dc 100644 --- a/chainercv/visualizations/vis_point.py +++ b/chainercv/visualizations/vis_point.py @@ -29,7 +29,7 @@ def vis_point(img, point, mask=None, ax=None): mask (~numpy.ndarray, optional): A boolean array whose shape is :math:`(P,)`. If :math:`i` th element is :obj:`True`, the :math:`i` th point is not displayed. If not specified, - all points in :obj:`keypoint` will be displayed. + all points in :obj:`point` will be displayed. ax (matplotlib.axes.Axes, optional): If provided, plot on this axis. Returns: From 6802b3200202c3f134f40c9c5bf3391c20c82358 Mon Sep 17 00:00:00 2001 From: Yusuke Niitani Date: Tue, 6 Mar 2018 10:38:26 +0900 Subject: [PATCH 4/5] reflect comment --- chainercv/visualizations/vis_point.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/chainercv/visualizations/vis_point.py b/chainercv/visualizations/vis_point.py index 0b952755dc..0cb6b5bf7e 100644 --- a/chainercv/visualizations/vis_point.py +++ b/chainercv/visualizations/vis_point.py @@ -1,3 +1,5 @@ +from __future__ import division + import numpy as np import six @@ -26,7 +28,7 @@ def vis_point(img, point, mask=None, ax=None): the number of points. The second axis corresponds to :math:`y` and :math:`x` coordinates of the points. - mask (~numpy.ndarray, optional): A boolean array whose shape is + mask (~numpy.ndarray): A boolean array whose shape is :math:`(P,)`. If :math:`i` th element is :obj:`True`, the :math:`i` th point is not displayed. If not specified, all points in :obj:`point` will be displayed. @@ -49,7 +51,7 @@ def vis_point(img, point, mask=None, ax=None): cm = plot.get_cmap('gist_rainbow') - colors = [cm(1. * i / n_point) for i in six.moves.range(n_point)] + colors = [cm(i / n_point) for i in six.moves.range(n_point)] for i in range(n_point): if mask[i]: From b60710b1a637752b99b7273ea5e355ba31887d72 Mon Sep 17 00:00:00 2001 From: Yusuke Niitani Date: Tue, 6 Mar 2018 12:34:17 +0900 Subject: [PATCH 5/5] remove optional --- chainercv/visualizations/vis_point.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chainercv/visualizations/vis_point.py b/chainercv/visualizations/vis_point.py index 0cb6b5bf7e..3f8c2a73c3 100644 --- a/chainercv/visualizations/vis_point.py +++ b/chainercv/visualizations/vis_point.py @@ -32,7 +32,7 @@ def vis_point(img, point, mask=None, ax=None): :math:`(P,)`. If :math:`i` th element is :obj:`True`, the :math:`i` th point is not displayed. If not specified, all points in :obj:`point` will be displayed. - ax (matplotlib.axes.Axes, optional): If provided, plot on this axis. + ax (matplotlib.axes.Axes): If provided, plot on this axis. Returns: ~matploblib.axes.Axes: