Skip to content

Commit

Permalink
* Rewrite relative unittest based on dataset_info
Browse files Browse the repository at this point in the history
* Add bc-breaking test for functions related to dataset_info
* Rename DatasetInfo.dataset_info as DatasetInfo._dataset_info
* Fix dataset_info of h36m dataset
  • Loading branch information
ly015 committed Aug 25, 2021
1 parent 0e8b7d4 commit d65a7ae
Show file tree
Hide file tree
Showing 9 changed files with 295 additions and 103 deletions.
3 changes: 2 additions & 1 deletion configs/_base_/datasets/h36m.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,5 @@
dict(link=('right_elbow', 'right_wrist'), id=15, color=[255, 128, 0])
},
joint_weights=[1.] * 17,
sigmas=[])
sigmas=[],
stats_info=dict(bbox_center=(528., 427.), bbox_scale=400.))
10 changes: 6 additions & 4 deletions mmpose/apis/inference_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def _collate_pose_sequence(pose_results, with_track_id=True, target_frame=-1):

def inference_pose_lifter_model(model,
pose_results_2d,
dataset,
dataset=None,
dataset_info=None,
with_track_id=True,
image_size=None,
Expand Down Expand Up @@ -245,8 +245,9 @@ def inference_pose_lifter_model(model,

if dataset_info is not None:
flip_pairs = dataset_info.flip_pairs
bbox_center = dataset_info.bbox_center
bbox_scale = dataset_info.bbox_scale
assert 'stats_info' in dataset_info._dataset_info
bbox_center = dataset_info._dataset_info['stats_info']['bbox_center']
bbox_scale = dataset_info._dataset_info['stats_info']['bbox_scale']
else:
warnings.warn(
'dataset is deprecated.'
Expand Down Expand Up @@ -283,6 +284,7 @@ def inference_pose_lifter_model(model,
else:
input_2d_visible = np.ones((T, K, 1), dtype=np.float32)

# TODO: Will be removed in the later versions
# Dummy 3D input
# This is for compatibility with configs in mmpose<=v0.14.0, where a
# 3D input is required to generate denormalization parameters. This
Expand Down Expand Up @@ -348,11 +350,11 @@ def vis_3d_pose_result(model,
result,
img=None,
dataset='Body3DH36MDataset',
dataset_info=None,
kpt_score_thr=0.3,
radius=8,
thickness=2,
num_instances=-1,
dataset_info=None,
show=False,
out_file=None):
"""Visualize the 3D pose estimation results.
Expand Down
18 changes: 9 additions & 9 deletions mmpose/datasets/dataset_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
class DatasetInfo:

def __init__(self, dataset_info):
self.dataset_info = dataset_info
self.dataset_name = self.dataset_info['dataset_name']
self.paper_info = self.dataset_info['paper_info']
self.keypoint_info = self.dataset_info['keypoint_info']
self.skeleton_info = self.dataset_info['skeleton_info']
self._dataset_info = dataset_info
self.dataset_name = self._dataset_info['dataset_name']
self.paper_info = self._dataset_info['paper_info']
self.keypoint_info = self._dataset_info['keypoint_info']
self.skeleton_info = self._dataset_info['skeleton_info']
self.joint_weights = np.array(
self.dataset_info['joint_weights'], dtype=np.float32)[:, None]
self._dataset_info['joint_weights'], dtype=np.float32)[:, None]

self.sigmas = np.array(self.dataset_info['sigmas'])
self.sigmas = np.array(self._dataset_info['sigmas'])

self._parse_keypoint_info()
self._parse_skeleton_info()

def _parse_skeleton_info(self):
"""Parse skeleton info.
"""Parse skeleton information.
- link_num (int): number of links.
- skeleton (list((2,))): list of links (id).
Expand All @@ -42,7 +42,7 @@ def _parse_skeleton_info(self):
self.pose_link_color = np.array(self.pose_link_color)

def _parse_keypoint_info(self):
"""Parse keypoint info.
"""Parse keypoint information.
- keypoint_num (int): number of keypoints.
- keypoint_id2name (dict): mapping keypoint id to keypoint name.
Expand Down
64 changes: 39 additions & 25 deletions tests/test_apis/test_inference.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import numpy as np
import pytest

from mmpose.apis import (inference_bottom_up_pose_model,
inference_top_down_pose_model, init_pose_model,
process_mmdet_results, vis_pose_result)
from mmpose.datasets import DatasetInfo


def test_top_down_demo():
Expand All @@ -15,14 +15,21 @@ def test_top_down_demo():
None,
device='cpu')
image_name = 'tests/data/coco/000000000785.jpg'
dataset_info = DatasetInfo(pose_model.cfg.data['test'].get(
'dataset_info', None))

person_result = []
person_result.append({'bbox': [50, 50, 50, 100]})
# test a single image, with a list of bboxes.
pose_results, _ = inference_top_down_pose_model(
pose_model, image_name, person_result, format='xywh')
pose_model,
image_name,
person_result,
format='xywh',
dataset_info=dataset_info)
# show the results
vis_pose_result(pose_model, image_name, pose_results)
vis_pose_result(
pose_model, image_name, pose_results, dataset_info=dataset_info)

# AIC demo
pose_model = init_pose_model(
Expand All @@ -31,16 +38,18 @@ def test_top_down_demo():
None,
device='cpu')
image_name = 'tests/data/aic/054d9ce9201beffc76e5ff2169d2af2f027002ca.jpg'
dataset_info = DatasetInfo(pose_model.cfg.data['test'].get(
'dataset_info', None))
# test a single image, with a list of bboxes.
pose_results, _ = inference_top_down_pose_model(
pose_model,
image_name,
person_result,
format='xywh',
dataset='TopDownAicDataset')
dataset_info=dataset_info)
# show the results
vis_pose_result(
pose_model, image_name, pose_results, dataset='TopDownAicDataset')
pose_model, image_name, pose_results, dataset_info=dataset_info)

# OneHand10K demo
# build the pose model from a config file and a checkpoint file
Expand All @@ -50,16 +59,18 @@ def test_top_down_demo():
None,
device='cpu')
image_name = 'tests/data/onehand10k/9.jpg'
dataset_info = DatasetInfo(pose_model.cfg.data['test'].get(
'dataset_info', None))
# test a single image, with a list of bboxes.
pose_results, _ = inference_top_down_pose_model(
pose_model,
image_name,
person_result,
format='xywh',
dataset='OneHand10KDataset')
dataset_info=dataset_info)
# show the results
vis_pose_result(
pose_model, image_name, pose_results, dataset='OneHand10KDataset')
pose_model, image_name, pose_results, dataset_info=dataset_info)

# InterHand2DDataset demo
# build the pose model from a config file and a checkpoint file
Expand All @@ -69,16 +80,18 @@ def test_top_down_demo():
None,
device='cpu')
image_name = 'tests/data/interhand2.6m/image2017.jpg'
dataset_info = DatasetInfo(pose_model.cfg.data['test'].get(
'dataset_info', None))
# test a single image, with a list of bboxes.
pose_results, _ = inference_top_down_pose_model(
pose_model,
image_name,
person_result,
format='xywh',
dataset='InterHand2DDataset')
dataset_info=dataset_info)
# show the results
vis_pose_result(
pose_model, image_name, pose_results, dataset='InterHand2DDataset')
pose_model, image_name, pose_results, dataset_info=dataset_info)

# Face300WDataset demo
# build the pose model from a config file and a checkpoint file
Expand All @@ -88,16 +101,18 @@ def test_top_down_demo():
None,
device='cpu')
image_name = 'tests/data/300w/indoor_020.png'
dataset_info = DatasetInfo(pose_model.cfg.data['test'].get(
'dataset_info', None))
# test a single image, with a list of bboxes.
pose_results, _ = inference_top_down_pose_model(
pose_model,
image_name,
person_result,
format='xywh',
dataset='Face300WDataset')
dataset_info=dataset_info)
# show the results
vis_pose_result(
pose_model, image_name, pose_results, dataset='Face300WDataset')
pose_model, image_name, pose_results, dataset_info=dataset_info)

# FaceAFLWDataset demo
# build the pose model from a config file and a checkpoint file
Expand All @@ -107,16 +122,18 @@ def test_top_down_demo():
None,
device='cpu')
image_name = 'tests/data/aflw/image04476.jpg'
dataset_info = DatasetInfo(pose_model.cfg.data['test'].get(
'dataset_info', None))
# test a single image, with a list of bboxes.
pose_results, _ = inference_top_down_pose_model(
pose_model,
image_name,
person_result,
format='xywh',
dataset='FaceAFLWDataset')
dataset_info=dataset_info)
# show the results
vis_pose_result(
pose_model, image_name, pose_results, dataset='FaceAFLWDataset')
pose_model, image_name, pose_results, dataset_info=dataset_info)

# FaceCOFWDataset demo
# build the pose model from a config file and a checkpoint file
Expand All @@ -126,24 +143,18 @@ def test_top_down_demo():
None,
device='cpu')
image_name = 'tests/data/cofw/001766.jpg'
dataset_info = DatasetInfo(pose_model.cfg.data['test'].get(
'dataset_info', None))
# test a single image, with a list of bboxes.
pose_results, _ = inference_top_down_pose_model(
pose_model,
image_name,
person_result,
format='xywh',
dataset='FaceCOFWDataset')
dataset_info=dataset_info)
# show the results
vis_pose_result(
pose_model, image_name, pose_results, dataset='FaceCOFWDataset')

with pytest.raises(NotImplementedError):
pose_results, _ = inference_top_down_pose_model(
pose_model,
image_name,
person_result,
format='xywh',
dataset='test')
pose_model, image_name, pose_results, dataset_info=dataset_info)


def test_bottom_up_demo():
Expand All @@ -156,12 +167,15 @@ def test_bottom_up_demo():
device='cpu')

image_name = 'tests/data/coco/000000000785.jpg'
dataset_info = DatasetInfo(pose_model.cfg.data['test'].get(
'dataset_info', None))

pose_results, _ = inference_bottom_up_pose_model(pose_model, image_name)
pose_results, _ = inference_bottom_up_pose_model(
pose_model, image_name, dataset_info=dataset_info)

# show the results
vis_pose_result(
pose_model, image_name, pose_results, dataset='BottomUpCocoDataset')
pose_model, image_name, pose_results, dataset_info=dataset_info)


def test_process_mmdet_results():
Expand Down
Loading

0 comments on commit d65a7ae

Please sign in to comment.