Repository: open-mmlab/mmpose

Issue:
Questions about different versions of mmpose
When I run a cell
# Visualize Skeleton vis_frames = vis_skeleton(vid_path, anno, gym_categories[anno['label']]) vid = mpy.ImageSequenceClip(vis_frames, fps=24) vid.ipython_display()
in mmaction2/demo/visualize_heatmap_volume.ipynb, it raise an 'devided by zero' error, I can run it correctly before.
I check the traceback, and I remember I changed my mmpose version from 0.13.0 to 0.16.0  to use the latest posec3d demo.(Posec3d demo can't use with the version of mmpose under 0.16.0)

How to solve this problem


Discussion:
Please also raise an issue in mmaction2.
There are already similar problems above and have not been solved yet
https://github.com/open-mmlab/mmaction2/issues/1029
@kennymckormick
Could you please upload full error information to help us locate the problem? @Deep-learning999 

​
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/usr/local/lib/python3.8/dist-packages/numpy/lib/shape_base.py in split(ary, indices_or_sections, axis)
    866     try:
--> 867         len(indices_or_sections)
    868     except TypeError:

TypeError: object of type 'int' has no len()

During handling of the above exception, another exception occurred:

ZeroDivisionError                         Traceback (most recent call last)
<ipython-input-15-2e78b9e4d5b1> in <module>
      1 # Visualize Skeleton
----> 2 vis_frames = vis_skeleton(vid_path, anno, gym_categories[anno['label']])
      3 #vid = mpy.ImageSequenceClip(vis_frames, fps=24)
      4 #vid.ipython_display()

<ipython-input-5-d999199b0bcf> in vis_skeleton(vid_path, anno, category_name, ratio)
     56         bbox = np.zeros([0, 4], dtype=np.float32)
     57         result = [dict(bbox=bbox, keypoints=k) for k in kp]
---> 58         vis_frame = vis_pose_result(model, f, result)
     59 
     60         if category_name is not None:

mmpose/mmpose/apis/inference.py in vis_pose_result(model, img, result, radius, thickness, kpt_score_thr, bbox_color, dataset, show, out_file)
    748         raise NotImplementedError()
    749 
--> 750     img = model.show_result(
    751         img,
    752         result,

/mmpose/mmpose/models/detectors/top_down.py in show_result(self, img, result, skeleton, kpt_score_thr, bbox_color, pose_kpt_color, pose_limb_color, text_color, radius, thickness, font_scale, bbox_thickness, win_name, show, show_keypoint_weight, wait_time, out_file)
    279                 labels = [res['label'] for res in result]
    280             # draw bounding boxes
--> 281             imshow_bboxes(
    282                 img,
    283                 bboxes,

/mmpose/mmpose/core/visualization/image.py in imshow_bboxes(img, bboxes, labels, colors, text_color, thickness, font_scale, show, win_name, wait_time, out_file)
     40 
     41     # adapt to mmcv.imshow_bboxes input format
---> 42     bboxes = np.split(bboxes, bboxes.shape[0], axis=0)
     43     if not isinstance(colors, list):
     44         colors = [colors for _ in range(len(bboxes))]

<__array_function__ internals> in split(*args, **kwargs)

/usr/local/lib/python3.8/dist-packages/numpy/lib/shape_base.py in split(ary, indices_or_sections, axis)
    869         sections = indices_or_sections
    870         N = ary.shape[axis]
--> 871         if N % sections:
    872             raise ValueError(
    873                 'array split does not result in an equal division') from None

ZeroDivisionError: integer division or modulo by zero
I want to install the latest version of mmpose and mmaction2 will have this problem
mmpose v0.13.0 uses `imshow_bbox` from [mmcv](https://github.com/open-mmlab/mmcv/blob/366c628a85daf71fa26f652b402277c90d9f7d6e/mmcv/visualization/image.py#L30).  mmpose v0.16.0 switched to `imshow_bbox` implemented in [mmpose](https://github.com/open-mmlab/mmpose/blob/8965f540905a5c5871faae4babc763c1ce66720e/mmpose/core/visualization/image.py#L9) for better visualization effect, which failed to handle the case of empty input bbox. This will be fixed soon.

Resolving patch:
diff --git a/mmpose/core/visualization/image.py b/mmpose/core/visualization/image.py
--- a/mmpose/core/visualization/image.py
+++ b/mmpose/core/visualization/image.py
@@ -50,7 +50,8 @@ def imshow_bboxes(img,
     """
 
     # adapt to mmcv.imshow_bboxes input format
-    bboxes = np.split(bboxes, bboxes.shape[0], axis=0)
+    bboxes = np.split(
+        bboxes, bboxes.shape[0], axis=0) if bboxes.shape[0] > 0 else []
     if not isinstance(colors, list):
         colors = [colors for _ in range(len(bboxes))]
     colors = [mmcv.color_val(c) for c in colors]


Test patch:
diff --git a/tests/test_visualization.py b/tests/test_visualization.py
--- a/tests/test_visualization.py
+++ b/tests/test_visualization.py
@@ -50,6 +50,14 @@ def test_imshow_bbox():
             show=False,
             out_file=f'{tmpdir}/out.png')
 
+        # test case of empty bboxes
+        _ = imshow_bboxes(
+            img,
+            np.zeros((0, 4), dtype=np.float32),
+            labels=None,
+            colors='red',
+            show=False)
+
 
 def test_effects():
     img = np.zeros((100, 100, 3), dtype=np.uint8)