From 62fdc7d320320df88ce44f980bcfdacf0a428f01 Mon Sep 17 00:00:00 2001 From: Shingo Kitagawa Date: Wed, 13 Jan 2021 16:13:20 +0900 Subject: [PATCH 1/4] use try to import chainer depend modules --- .../python/jsk_recognition_utils/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/jsk_recognition_utils/python/jsk_recognition_utils/__init__.py b/jsk_recognition_utils/python/jsk_recognition_utils/__init__.py index ff10544c75..cdea2d4b88 100644 --- a/jsk_recognition_utils/python/jsk_recognition_utils/__init__.py +++ b/jsk_recognition_utils/python/jsk_recognition_utils/__init__.py @@ -1,12 +1,15 @@ -from jsk_recognition_utils import chainermodels from jsk_recognition_utils import color from jsk_recognition_utils import conversations -from jsk_recognition_utils import datasets from jsk_recognition_utils import feature from jsk_recognition_utils import mask from jsk_recognition_utils import visualize from jsk_recognition_utils import geometry +try: + from jsk_recognition_utils import chainermodels # NOQA + from jsk_recognition_utils import datasets # NOQA +except ImportError: + print('Please install chainer<7.0.0 to import chainermodels') bounding_box_msg_to_aabb = conversations.bounding_box_msg_to_aabb rects_msg_to_ndarray = conversations.rects_msg_to_ndarray From 58a4821c48fa4163f914fc7ed0c58142dc51b254 Mon Sep 17 00:00:00 2001 From: Shingo Kitagawa Date: Wed, 13 Jan 2021 16:52:13 +0900 Subject: [PATCH 2/4] update import error message --- .../python/jsk_recognition_utils/__init__.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/jsk_recognition_utils/python/jsk_recognition_utils/__init__.py b/jsk_recognition_utils/python/jsk_recognition_utils/__init__.py index cdea2d4b88..92baf24537 100644 --- a/jsk_recognition_utils/python/jsk_recognition_utils/__init__.py +++ b/jsk_recognition_utils/python/jsk_recognition_utils/__init__.py @@ -1,3 +1,5 @@ +from __future__ import print_function + from jsk_recognition_utils import color from jsk_recognition_utils import conversations from jsk_recognition_utils import feature @@ -9,7 +11,11 @@ from jsk_recognition_utils import chainermodels # NOQA from jsk_recognition_utils import datasets # NOQA except ImportError: - print('Please install chainer<7.0.0 to import chainermodels') + import sys + print( + 'Please install chainer<7.0.0 to import ' + 'jsk_recognition_utils.chainermodels and datasets', + file=sys.stderr) bounding_box_msg_to_aabb = conversations.bounding_box_msg_to_aabb rects_msg_to_ndarray = conversations.rects_msg_to_ndarray From f523b88506605bc37963e8d1e7327dfdbbaea760 Mon Sep 17 00:00:00 2001 From: Shingo Kitagawa Date: Wed, 13 Jan 2021 18:15:15 +0900 Subject: [PATCH 3/4] add fcn and chainercv in exec_depend --- jsk_recognition_utils/package.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jsk_recognition_utils/package.xml b/jsk_recognition_utils/package.xml index f36759a810..9b40f9751e 100644 --- a/jsk_recognition_utils/package.xml +++ b/jsk_recognition_utils/package.xml @@ -42,8 +42,10 @@ pcl_msgs pcl_ros python-chainer-pip + python-chainercv-pip python-skimage python3-skimage + python-fcn-pip sensor_msgs std_msgs tf2_ros From c4bac2d84224b1cb7a618795c6b4fcae6d0f2384 Mon Sep 17 00:00:00 2001 From: Shingo Kitagawa Date: Wed, 13 Jan 2021 18:31:28 +0900 Subject: [PATCH 4/4] update warning messages for import error --- .../python/jsk_recognition_utils/__init__.py | 56 +++++++++++++++++-- 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/jsk_recognition_utils/python/jsk_recognition_utils/__init__.py b/jsk_recognition_utils/python/jsk_recognition_utils/__init__.py index 92baf24537..f46cc3d1ab 100644 --- a/jsk_recognition_utils/python/jsk_recognition_utils/__init__.py +++ b/jsk_recognition_utils/python/jsk_recognition_utils/__init__.py @@ -1,5 +1,7 @@ from __future__ import print_function +import sys + from jsk_recognition_utils import color from jsk_recognition_utils import conversations from jsk_recognition_utils import feature @@ -7,15 +9,57 @@ from jsk_recognition_utils import visualize from jsk_recognition_utils import geometry + +try: + import chainer # NOQA + _chainer_available = True +except ImportError: + _chainer_available = False + +try: + import chainercv # NOQA + _chainercv_available = True +except ImportError: + _chainercv_available = False + try: + import fcn # NOQA + _fcn_available = True +except ImportError: + _fcn_available = False + +if _chainer_available and _chainercv_available and _fcn_available: from jsk_recognition_utils import chainermodels # NOQA +else: + _depends = [] + if not _chainer_available: + _depends.append('chainer\\<7.0.0') + if not _chainercv_available: + _depends.append('chainercv') + if not _fcn_available: + _depends.append('fcn') + print(''' +Please install {0} +to import jsk_recognition_utils.chainermodels. + + sudo pip install {1} +'''.format(', '.join(_depends), ' '.join(_depends)), file=sys.stderr) + +if _chainer_available and _chainercv_available: from jsk_recognition_utils import datasets # NOQA -except ImportError: - import sys - print( - 'Please install chainer<7.0.0 to import ' - 'jsk_recognition_utils.chainermodels and datasets', - file=sys.stderr) +else: + _depends = [] + if not _chainer_available: + _depends.append('chainer\\<7.0.0') + if not _chainercv_available: + _depends.append('chainercv') + print(''' +Please install {0} +to import jsk_recognition_utils.datasets. + + sudo pip install {1} +'''.format(', '.join(_depends), ' '.join(_depends)), file=sys.stderr) + bounding_box_msg_to_aabb = conversations.bounding_box_msg_to_aabb rects_msg_to_ndarray = conversations.rects_msg_to_ndarray