Initial snapshot: hand motion pipeline (Dyn-HaMR + dex-retargeting + SPIDER)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
+415
@@ -0,0 +1,415 @@
|
||||
# Copyright (c) OpenMMLab. All rights reserved.
|
||||
import copy
|
||||
import tempfile
|
||||
|
||||
import pytest
|
||||
from numpy.testing import assert_almost_equal
|
||||
|
||||
from mmpose.datasets import DATASETS
|
||||
from tests.utils.data_utils import convert_db_to_output
|
||||
|
||||
|
||||
def test_animal_horse10_dataset_compatibility():
|
||||
dataset = 'AnimalHorse10Dataset'
|
||||
dataset_class = DATASETS.get(dataset)
|
||||
|
||||
channel_cfg = dict(
|
||||
num_output_channels=22,
|
||||
dataset_joints=22,
|
||||
dataset_channel=[
|
||||
[
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
|
||||
18, 19, 21
|
||||
],
|
||||
],
|
||||
inference_channel=[
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
|
||||
19, 21
|
||||
])
|
||||
|
||||
data_cfg = dict(
|
||||
image_size=[256, 256],
|
||||
heatmap_size=[64, 64],
|
||||
num_output_channels=channel_cfg['num_output_channels'],
|
||||
num_joints=channel_cfg['dataset_joints'],
|
||||
dataset_channel=channel_cfg['dataset_channel'],
|
||||
inference_channel=channel_cfg['inference_channel'])
|
||||
# Test
|
||||
data_cfg_copy = copy.deepcopy(data_cfg)
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = dataset_class(
|
||||
ann_file='tests/data/horse10/test_horse10.json',
|
||||
img_prefix='tests/data/horse10/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
custom_dataset = dataset_class(
|
||||
ann_file='tests/data/horse10/test_horse10.json',
|
||||
img_prefix='tests/data/horse10/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=False)
|
||||
|
||||
assert custom_dataset.test_mode is False
|
||||
assert custom_dataset.num_images == 3
|
||||
_ = custom_dataset[0]
|
||||
|
||||
outputs = convert_db_to_output(custom_dataset.db)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, ['PCK'])
|
||||
assert_almost_equal(infos['PCK'], 1.0)
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, 'mAP')
|
||||
|
||||
|
||||
def test_animal_fly_dataset_compatibility():
|
||||
dataset = 'AnimalFlyDataset'
|
||||
dataset_class = DATASETS.get(dataset)
|
||||
|
||||
channel_cfg = dict(
|
||||
num_output_channels=32,
|
||||
dataset_joints=32,
|
||||
dataset_channel=[
|
||||
[
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
|
||||
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31
|
||||
],
|
||||
],
|
||||
inference_channel=[
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
|
||||
19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31
|
||||
])
|
||||
|
||||
data_cfg = dict(
|
||||
image_size=[192, 192],
|
||||
heatmap_size=[48, 48],
|
||||
num_output_channels=channel_cfg['num_output_channels'],
|
||||
num_joints=channel_cfg['dataset_joints'],
|
||||
dataset_channel=channel_cfg['dataset_channel'],
|
||||
inference_channel=channel_cfg['inference_channel'])
|
||||
|
||||
# Test
|
||||
data_cfg_copy = copy.deepcopy(data_cfg)
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = dataset_class(
|
||||
ann_file='tests/data/fly/test_fly.json',
|
||||
img_prefix='tests/data/fly/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
custom_dataset = dataset_class(
|
||||
ann_file='tests/data/fly/test_fly.json',
|
||||
img_prefix='tests/data/fly/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=False)
|
||||
|
||||
assert custom_dataset.test_mode is False
|
||||
assert custom_dataset.num_images == 2
|
||||
_ = custom_dataset[0]
|
||||
|
||||
outputs = convert_db_to_output(custom_dataset.db)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, ['PCK'])
|
||||
assert_almost_equal(infos['PCK'], 1.0)
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, 'mAP')
|
||||
|
||||
|
||||
def test_animal_locust_dataset_compatibility():
|
||||
dataset = 'AnimalLocustDataset'
|
||||
dataset_class = DATASETS.get(dataset)
|
||||
|
||||
channel_cfg = dict(
|
||||
num_output_channels=35,
|
||||
dataset_joints=35,
|
||||
dataset_channel=[
|
||||
[
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
|
||||
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
|
||||
34
|
||||
],
|
||||
],
|
||||
inference_channel=[
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
|
||||
19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34
|
||||
])
|
||||
|
||||
data_cfg = dict(
|
||||
image_size=[160, 160],
|
||||
heatmap_size=[40, 40],
|
||||
num_output_channels=channel_cfg['num_output_channels'],
|
||||
num_joints=channel_cfg['dataset_joints'],
|
||||
dataset_channel=channel_cfg['dataset_channel'],
|
||||
inference_channel=channel_cfg['inference_channel'])
|
||||
|
||||
# Test
|
||||
data_cfg_copy = copy.deepcopy(data_cfg)
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = dataset_class(
|
||||
ann_file='tests/data/locust/test_locust.json',
|
||||
img_prefix='tests/data/locust/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
custom_dataset = dataset_class(
|
||||
ann_file='tests/data/locust/test_locust.json',
|
||||
img_prefix='tests/data/locust/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=False)
|
||||
|
||||
assert custom_dataset.test_mode is False
|
||||
assert custom_dataset.num_images == 2
|
||||
_ = custom_dataset[0]
|
||||
|
||||
outputs = convert_db_to_output(custom_dataset.db)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, ['PCK'])
|
||||
assert_almost_equal(infos['PCK'], 1.0)
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, 'mAP')
|
||||
|
||||
|
||||
def test_animal_zebra_dataset_compatibility():
|
||||
dataset = 'AnimalZebraDataset'
|
||||
dataset_class = DATASETS.get(dataset)
|
||||
|
||||
channel_cfg = dict(
|
||||
num_output_channels=9,
|
||||
dataset_joints=9,
|
||||
dataset_channel=[
|
||||
[0, 1, 2, 3, 4, 5, 6, 7, 8],
|
||||
],
|
||||
inference_channel=[0, 1, 2, 3, 4, 5, 6, 7, 8])
|
||||
|
||||
data_cfg = dict(
|
||||
image_size=[160, 160],
|
||||
heatmap_size=[40, 40],
|
||||
num_output_channels=channel_cfg['num_output_channels'],
|
||||
num_joints=channel_cfg['dataset_joints'],
|
||||
dataset_channel=channel_cfg['dataset_channel'],
|
||||
inference_channel=channel_cfg['inference_channel'])
|
||||
|
||||
# Test
|
||||
data_cfg_copy = copy.deepcopy(data_cfg)
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = dataset_class(
|
||||
ann_file='tests/data/zebra/test_zebra.json',
|
||||
img_prefix='tests/data/zebra/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
custom_dataset = dataset_class(
|
||||
ann_file='tests/data/zebra/test_zebra.json',
|
||||
img_prefix='tests/data/zebra/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=False)
|
||||
|
||||
assert custom_dataset.test_mode is False
|
||||
assert custom_dataset.num_images == 2
|
||||
_ = custom_dataset[0]
|
||||
|
||||
outputs = convert_db_to_output(custom_dataset.db)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, ['PCK'])
|
||||
assert_almost_equal(infos['PCK'], 1.0)
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, 'mAP')
|
||||
|
||||
|
||||
def test_animal_ATRW_dataset_compatibility():
|
||||
dataset = 'AnimalATRWDataset'
|
||||
dataset_class = DATASETS.get(dataset)
|
||||
|
||||
channel_cfg = dict(
|
||||
num_output_channels=15,
|
||||
dataset_joints=15,
|
||||
dataset_channel=[
|
||||
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],
|
||||
],
|
||||
inference_channel=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])
|
||||
|
||||
data_cfg = dict(
|
||||
image_size=[256, 256],
|
||||
heatmap_size=[64, 64],
|
||||
num_output_channels=channel_cfg['num_output_channels'],
|
||||
num_joints=channel_cfg['dataset_joints'],
|
||||
dataset_channel=channel_cfg['dataset_channel'],
|
||||
inference_channel=channel_cfg['inference_channel'],
|
||||
soft_nms=False,
|
||||
nms_thr=1.0,
|
||||
oks_thr=0.9,
|
||||
vis_thr=0.2,
|
||||
use_gt_bbox=True,
|
||||
det_bbox_thr=0.0,
|
||||
bbox_file='',
|
||||
)
|
||||
|
||||
# Test
|
||||
data_cfg_copy = copy.deepcopy(data_cfg)
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = dataset_class(
|
||||
ann_file='tests/data/atrw/test_atrw.json',
|
||||
img_prefix='tests/data/atrw/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
custom_dataset = dataset_class(
|
||||
ann_file='tests/data/atrw/test_atrw.json',
|
||||
img_prefix='tests/data/atrw/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=False)
|
||||
|
||||
assert custom_dataset.test_mode is False
|
||||
assert custom_dataset.num_images == 2
|
||||
_ = custom_dataset[0]
|
||||
|
||||
outputs = convert_db_to_output(custom_dataset.db)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, 'mAP')
|
||||
assert_almost_equal(infos['AP'], 1.0)
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, ['PCK'])
|
||||
|
||||
|
||||
def test_animal_Macaque_dataset_compatibility():
|
||||
dataset = 'AnimalMacaqueDataset'
|
||||
dataset_class = DATASETS.get(dataset)
|
||||
|
||||
channel_cfg = dict(
|
||||
num_output_channels=17,
|
||||
dataset_joints=17,
|
||||
dataset_channel=[
|
||||
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],
|
||||
],
|
||||
inference_channel=[
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
|
||||
])
|
||||
|
||||
data_cfg = dict(
|
||||
image_size=[192, 256],
|
||||
heatmap_size=[48, 64],
|
||||
num_output_channels=channel_cfg['num_output_channels'],
|
||||
num_joints=channel_cfg['dataset_joints'],
|
||||
dataset_channel=channel_cfg['dataset_channel'],
|
||||
inference_channel=channel_cfg['inference_channel'],
|
||||
soft_nms=False,
|
||||
nms_thr=1.0,
|
||||
oks_thr=0.9,
|
||||
vis_thr=0.2,
|
||||
use_gt_bbox=True,
|
||||
det_bbox_thr=0.0,
|
||||
bbox_file='',
|
||||
)
|
||||
|
||||
# Test
|
||||
data_cfg_copy = copy.deepcopy(data_cfg)
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = dataset_class(
|
||||
ann_file='tests/data/macaque/test_macaque.json',
|
||||
img_prefix='tests/data/macaque/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
with pytest.warns(DeprecationWarning):
|
||||
custom_dataset = dataset_class(
|
||||
ann_file='tests/data/macaque/test_macaque.json',
|
||||
img_prefix='tests/data/macaque/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=False)
|
||||
|
||||
assert custom_dataset.test_mode is False
|
||||
assert custom_dataset.num_images == 2
|
||||
_ = custom_dataset[0]
|
||||
|
||||
outputs = convert_db_to_output(custom_dataset.db)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, 'mAP')
|
||||
assert_almost_equal(infos['AP'], 1.0)
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, ['PCK'])
|
||||
|
||||
|
||||
def test_animalpose_dataset_compatibility():
|
||||
dataset = 'AnimalPoseDataset'
|
||||
dataset_class = DATASETS.get(dataset)
|
||||
|
||||
channel_cfg = dict(
|
||||
num_output_channels=20,
|
||||
dataset_joints=20,
|
||||
dataset_channel=[
|
||||
[
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
|
||||
18, 19
|
||||
],
|
||||
],
|
||||
inference_channel=[
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
|
||||
19
|
||||
])
|
||||
|
||||
data_cfg = dict(
|
||||
image_size=[256, 256],
|
||||
heatmap_size=[64, 64],
|
||||
num_output_channels=channel_cfg['num_output_channels'],
|
||||
num_joints=channel_cfg['dataset_joints'],
|
||||
dataset_channel=channel_cfg['dataset_channel'],
|
||||
inference_channel=channel_cfg['inference_channel'],
|
||||
soft_nms=False,
|
||||
nms_thr=1.0,
|
||||
oks_thr=0.9,
|
||||
vis_thr=0.2,
|
||||
use_gt_bbox=True,
|
||||
det_bbox_thr=0.0,
|
||||
bbox_file='',
|
||||
)
|
||||
|
||||
# Test
|
||||
data_cfg_copy = copy.deepcopy(data_cfg)
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = dataset_class(
|
||||
ann_file='tests/data/animalpose/test_animalpose.json',
|
||||
img_prefix='tests/data/animalpose/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
custom_dataset = dataset_class(
|
||||
ann_file='tests/data/animalpose/test_animalpose.json',
|
||||
img_prefix='tests/data/animalpose/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=False)
|
||||
|
||||
assert custom_dataset.test_mode is False
|
||||
assert custom_dataset.num_images == 2
|
||||
_ = custom_dataset[0]
|
||||
|
||||
outputs = convert_db_to_output(custom_dataset.db)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, 'mAP')
|
||||
assert_almost_equal(infos['AP'], 1.0)
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, ['PCK'])
|
||||
+266
@@ -0,0 +1,266 @@
|
||||
# Copyright (c) OpenMMLab. All rights reserved.
|
||||
import tempfile
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from mmpose.datasets import DATASETS
|
||||
from mmpose.datasets.builder import build_dataset
|
||||
|
||||
|
||||
def test_body3d_h36m_dataset_compatibility():
|
||||
# Test Human3.6M dataset
|
||||
dataset = 'Body3DH36MDataset'
|
||||
dataset_class = DATASETS.get(dataset)
|
||||
|
||||
# test single-frame input
|
||||
data_cfg = dict(
|
||||
num_joints=17,
|
||||
seq_len=1,
|
||||
seq_frame_interval=1,
|
||||
joint_2d_src='pipeline',
|
||||
joint_2d_det_file=None,
|
||||
causal=False,
|
||||
need_camera_param=True,
|
||||
camera_param_file='tests/data/h36m/cameras.pkl')
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = dataset_class(
|
||||
ann_file='tests/data/h36m/test_h36m_body3d.npz',
|
||||
img_prefix='tests/data/h36m',
|
||||
data_cfg=data_cfg,
|
||||
pipeline=[],
|
||||
test_mode=False)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
custom_dataset = dataset_class(
|
||||
ann_file='tests/data/h36m/test_h36m_body3d.npz',
|
||||
img_prefix='tests/data/h36m',
|
||||
data_cfg=data_cfg,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
assert custom_dataset.test_mode is True
|
||||
_ = custom_dataset[0]
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
outputs = []
|
||||
for result in custom_dataset:
|
||||
outputs.append({
|
||||
'preds': result['target'][None, ...],
|
||||
'target_image_paths': [result['target_image_path']],
|
||||
})
|
||||
|
||||
metrics = ['mpjpe', 'p-mpjpe', 'n-mpjpe']
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, metrics)
|
||||
|
||||
np.testing.assert_almost_equal(infos['MPJPE'], 0.0)
|
||||
np.testing.assert_almost_equal(infos['P-MPJPE'], 0.0)
|
||||
np.testing.assert_almost_equal(infos['N-MPJPE'], 0.0)
|
||||
|
||||
# test multi-frame input with joint_2d_src = 'detection'
|
||||
data_cfg = dict(
|
||||
num_joints=17,
|
||||
seq_len=27,
|
||||
seq_frame_interval=1,
|
||||
causal=True,
|
||||
temporal_padding=True,
|
||||
joint_2d_src='detection',
|
||||
joint_2d_det_file='tests/data/h36m/test_h36m_2d_detection.npy',
|
||||
need_camera_param=True,
|
||||
camera_param_file='tests/data/h36m/cameras.pkl')
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = dataset_class(
|
||||
ann_file='tests/data/h36m/test_h36m_body3d.npz',
|
||||
img_prefix='tests/data/h36m',
|
||||
data_cfg=data_cfg,
|
||||
pipeline=[],
|
||||
test_mode=False)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
custom_dataset = dataset_class(
|
||||
ann_file='tests/data/h36m/test_h36m_body3d.npz',
|
||||
img_prefix='tests/data/h36m',
|
||||
data_cfg=data_cfg,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
assert custom_dataset.test_mode is True
|
||||
_ = custom_dataset[0]
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
outputs = []
|
||||
for result in custom_dataset:
|
||||
outputs.append({
|
||||
'preds': result['target'][None, ...],
|
||||
'target_image_paths': [result['target_image_path']],
|
||||
})
|
||||
|
||||
metrics = ['mpjpe', 'p-mpjpe', 'n-mpjpe']
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, metrics)
|
||||
|
||||
np.testing.assert_almost_equal(infos['MPJPE'], 0.0)
|
||||
np.testing.assert_almost_equal(infos['P-MPJPE'], 0.0)
|
||||
np.testing.assert_almost_equal(infos['N-MPJPE'], 0.0)
|
||||
|
||||
|
||||
def test_body3d_semi_supervision_dataset_compatibility():
|
||||
# Test Body3d Semi-supervision Dataset
|
||||
|
||||
# load labeled dataset
|
||||
labeled_data_cfg = dict(
|
||||
num_joints=17,
|
||||
seq_len=27,
|
||||
seq_frame_interval=1,
|
||||
causall=False,
|
||||
temporal_padding=True,
|
||||
joint_2d_src='gt',
|
||||
subset=1,
|
||||
subjects=['S1'],
|
||||
need_camera_param=True,
|
||||
camera_param_file='tests/data/h36m/cameras.pkl')
|
||||
labeled_dataset = dict(
|
||||
type='Body3DH36MDataset',
|
||||
ann_file='tests/data/h36m/test_h36m_body3d.npz',
|
||||
img_prefix='tests/data/h36m',
|
||||
data_cfg=labeled_data_cfg,
|
||||
pipeline=[])
|
||||
|
||||
# load unlabled data
|
||||
unlabeled_data_cfg = dict(
|
||||
num_joints=17,
|
||||
seq_len=27,
|
||||
seq_frame_interval=1,
|
||||
causal=False,
|
||||
temporal_padding=True,
|
||||
joint_2d_src='gt',
|
||||
subjects=['S5', 'S7', 'S8'],
|
||||
need_camera_param=True,
|
||||
camera_param_file='tests/data/h36m/cameras.pkl',
|
||||
need_2d_label=True)
|
||||
unlabeled_dataset = dict(
|
||||
type='Body3DH36MDataset',
|
||||
ann_file='tests/data/h36m/test_h36m_body3d.npz',
|
||||
img_prefix='tests/data/h36m',
|
||||
data_cfg=unlabeled_data_cfg,
|
||||
pipeline=[
|
||||
dict(
|
||||
type='Collect',
|
||||
keys=[('input_2d', 'unlabeled_input')],
|
||||
meta_name='metas',
|
||||
meta_keys=[])
|
||||
])
|
||||
|
||||
# combine labeled and unlabeled dataset to form a new dataset
|
||||
dataset = 'Body3DSemiSupervisionDataset'
|
||||
dataset_class = DATASETS.get(dataset)
|
||||
with pytest.warns(DeprecationWarning):
|
||||
custom_dataset = dataset_class(labeled_dataset, unlabeled_dataset)
|
||||
item = custom_dataset[0]
|
||||
assert 'unlabeled_input' in item.keys()
|
||||
|
||||
unlabeled_dataset = build_dataset(unlabeled_dataset)
|
||||
assert len(unlabeled_dataset) == len(custom_dataset)
|
||||
|
||||
|
||||
def test_body3d_mpi_inf_3dhp_dataset_compatibility():
|
||||
# Test MPI-INF-3DHP dataset
|
||||
dataset = 'Body3DMpiInf3dhpDataset'
|
||||
dataset_class = DATASETS.get(dataset)
|
||||
|
||||
# Test single-frame input on trainset
|
||||
single_frame_train_data_cfg = dict(
|
||||
num_joints=17,
|
||||
seq_len=1,
|
||||
seq_frame_interval=1,
|
||||
joint_2d_src='pipeline',
|
||||
joint_2d_det_file=None,
|
||||
causal=False,
|
||||
need_camera_param=True,
|
||||
camera_param_file='tests/data/mpi_inf_3dhp/cameras_train.pkl')
|
||||
|
||||
# Test single-frame input on testset
|
||||
single_frame_test_data_cfg = dict(
|
||||
num_joints=17,
|
||||
seq_len=1,
|
||||
seq_frame_interval=1,
|
||||
joint_2d_src='gt',
|
||||
joint_2d_det_file=None,
|
||||
causal=False,
|
||||
need_camera_param=True,
|
||||
camera_param_file='tests/data/mpi_inf_3dhp/cameras_test.pkl')
|
||||
|
||||
# Test multi-frame input on trainset
|
||||
multi_frame_train_data_cfg = dict(
|
||||
num_joints=17,
|
||||
seq_len=27,
|
||||
seq_frame_interval=1,
|
||||
joint_2d_src='gt',
|
||||
joint_2d_det_file=None,
|
||||
causal=True,
|
||||
temporal_padding=True,
|
||||
need_camera_param=True,
|
||||
camera_param_file='tests/data/mpi_inf_3dhp/cameras_train.pkl')
|
||||
|
||||
# Test multi-frame input on testset
|
||||
multi_frame_test_data_cfg = dict(
|
||||
num_joints=17,
|
||||
seq_len=27,
|
||||
seq_frame_interval=1,
|
||||
joint_2d_src='pipeline',
|
||||
joint_2d_det_file=None,
|
||||
causal=False,
|
||||
temporal_padding=True,
|
||||
need_camera_param=True,
|
||||
camera_param_file='tests/data/mpi_inf_3dhp/cameras_test.pkl')
|
||||
|
||||
ann_files = [
|
||||
'tests/data/mpi_inf_3dhp/test_3dhp_train.npz',
|
||||
'tests/data/mpi_inf_3dhp/test_3dhp_test.npz'
|
||||
] * 2
|
||||
data_cfgs = [
|
||||
single_frame_train_data_cfg, single_frame_test_data_cfg,
|
||||
multi_frame_train_data_cfg, multi_frame_test_data_cfg
|
||||
]
|
||||
|
||||
for ann_file, data_cfg in zip(ann_files, data_cfgs):
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = dataset_class(
|
||||
ann_file=ann_file,
|
||||
img_prefix='tests/data/mpi_inf_3dhp',
|
||||
data_cfg=data_cfg,
|
||||
pipeline=[],
|
||||
test_mode=False)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
custom_dataset = dataset_class(
|
||||
ann_file=ann_file,
|
||||
img_prefix='tests/data/mpi_inf_3dhp',
|
||||
data_cfg=data_cfg,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
assert custom_dataset.test_mode is True
|
||||
_ = custom_dataset[0]
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
outputs = []
|
||||
for result in custom_dataset:
|
||||
outputs.append({
|
||||
'preds':
|
||||
result['target'][None, ...],
|
||||
'target_image_paths': [result['target_image_path']],
|
||||
})
|
||||
|
||||
metrics = [
|
||||
'mpjpe', 'p-mpjpe', '3dpck', 'p-3dpck', '3dauc', 'p-3dauc'
|
||||
]
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, metrics)
|
||||
|
||||
np.testing.assert_almost_equal(infos['MPJPE'], 0.0)
|
||||
np.testing.assert_almost_equal(infos['P-MPJPE'], 0.0)
|
||||
np.testing.assert_almost_equal(infos['3DPCK'], 100.)
|
||||
np.testing.assert_almost_equal(infos['P-3DPCK'], 100.)
|
||||
np.testing.assert_almost_equal(infos['3DAUC'], 30 / 31 * 100)
|
||||
np.testing.assert_almost_equal(infos['P-3DAUC'], 30 / 31 * 100)
|
||||
+325
@@ -0,0 +1,325 @@
|
||||
# Copyright (c) OpenMMLab. All rights reserved.
|
||||
import tempfile
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
from numpy.testing import assert_almost_equal
|
||||
|
||||
from mmpose.datasets import DATASETS
|
||||
|
||||
|
||||
def convert_coco_to_output(coco, is_wholebody=False):
|
||||
outputs = []
|
||||
for img_id in coco.getImgIds():
|
||||
preds = []
|
||||
scores = []
|
||||
image = coco.imgs[img_id]
|
||||
ann_ids = coco.getAnnIds(img_id)
|
||||
for ann_id in ann_ids:
|
||||
obj = coco.anns[ann_id]
|
||||
if is_wholebody:
|
||||
keypoints = np.array(obj['keypoints'] + obj['foot_kpts'] +
|
||||
obj['face_kpts'] + obj['lefthand_kpts'] +
|
||||
obj['righthand_kpts']).reshape(-1, 3)
|
||||
else:
|
||||
keypoints = np.array(obj['keypoints']).reshape((-1, 3))
|
||||
K = keypoints.shape[0]
|
||||
if sum(keypoints[:, 2]) == 0:
|
||||
continue
|
||||
preds.append(
|
||||
np.concatenate((keypoints[:, :2], np.ones(
|
||||
[K, 1]), np.ones([K, 1]) * ann_id),
|
||||
axis=1))
|
||||
scores.append(1)
|
||||
image_paths = []
|
||||
image_paths.append(image['file_name'])
|
||||
|
||||
output = {}
|
||||
output['preds'] = np.stack(preds)
|
||||
output['scores'] = scores
|
||||
output['image_paths'] = image_paths
|
||||
output['output_heatmap'] = None
|
||||
|
||||
outputs.append(output)
|
||||
|
||||
return outputs
|
||||
|
||||
|
||||
def test_bottom_up_COCO_dataset_compatibility():
|
||||
dataset = 'BottomUpCocoDataset'
|
||||
# test COCO datasets
|
||||
dataset_class = DATASETS.get(dataset)
|
||||
|
||||
channel_cfg = dict(
|
||||
dataset_joints=17,
|
||||
dataset_channel=[
|
||||
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17],
|
||||
],
|
||||
inference_channel=[
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17
|
||||
])
|
||||
|
||||
data_cfg = dict(
|
||||
image_size=512,
|
||||
base_size=256,
|
||||
base_sigma=2,
|
||||
heatmap_size=[128, 256],
|
||||
num_joints=channel_cfg['dataset_joints'],
|
||||
dataset_channel=channel_cfg['dataset_channel'],
|
||||
inference_channel=channel_cfg['inference_channel'],
|
||||
num_scales=2,
|
||||
scale_aware_sigma=False,
|
||||
use_nms=True)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = dataset_class(
|
||||
ann_file='tests/data/coco/test_coco.json',
|
||||
img_prefix='tests/data/coco/',
|
||||
data_cfg=data_cfg,
|
||||
pipeline=[],
|
||||
test_mode=False)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
custom_dataset = dataset_class(
|
||||
ann_file='tests/data/coco/test_coco.json',
|
||||
img_prefix='tests/data/coco/',
|
||||
data_cfg=data_cfg,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
assert custom_dataset.num_images == 4
|
||||
_ = custom_dataset[0]
|
||||
assert custom_dataset.dataset_name == 'coco'
|
||||
|
||||
outputs = convert_coco_to_output(custom_dataset.coco)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, 'mAP')
|
||||
assert_almost_equal(infos['AP'], 1.0)
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
_ = custom_dataset.evaluate(outputs, tmpdir, 'PCK')
|
||||
|
||||
|
||||
def test_bottom_up_CrowdPose_dataset_compatibility():
|
||||
dataset = 'BottomUpCrowdPoseDataset'
|
||||
# test CrowdPose datasets
|
||||
dataset_class = DATASETS.get(dataset)
|
||||
|
||||
channel_cfg = dict(
|
||||
num_output_channels=14,
|
||||
dataset_joints=14,
|
||||
dataset_channel=[
|
||||
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],
|
||||
],
|
||||
inference_channel=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13])
|
||||
|
||||
data_cfg = dict(
|
||||
image_size=512,
|
||||
base_size=256,
|
||||
base_sigma=2,
|
||||
heatmap_size=[128, 256],
|
||||
num_joints=channel_cfg['dataset_joints'],
|
||||
dataset_channel=channel_cfg['dataset_channel'],
|
||||
inference_channel=channel_cfg['inference_channel'],
|
||||
num_scales=2,
|
||||
scale_aware_sigma=False)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = dataset_class(
|
||||
ann_file='tests/data/crowdpose/test_crowdpose.json',
|
||||
img_prefix='tests/data/crowdpose/',
|
||||
data_cfg=data_cfg,
|
||||
pipeline=[],
|
||||
test_mode=False)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
custom_dataset = dataset_class(
|
||||
ann_file='tests/data/crowdpose/test_crowdpose.json',
|
||||
img_prefix='tests/data/crowdpose/',
|
||||
data_cfg=data_cfg,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
image_id = 103319
|
||||
assert image_id in custom_dataset.img_ids
|
||||
assert len(custom_dataset.img_ids) == 2
|
||||
_ = custom_dataset[0]
|
||||
assert custom_dataset.dataset_name == 'crowdpose'
|
||||
|
||||
outputs = convert_coco_to_output(custom_dataset.coco)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, 'mAP')
|
||||
assert_almost_equal(infos['AP'], 1.0)
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
_ = custom_dataset.evaluate(outputs, tmpdir, 'PCK')
|
||||
|
||||
|
||||
def test_bottom_up_MHP_dataset_compatibility():
|
||||
dataset = 'BottomUpMhpDataset'
|
||||
# test MHP datasets
|
||||
dataset_class = DATASETS.get(dataset)
|
||||
|
||||
channel_cfg = dict(
|
||||
dataset_joints=16,
|
||||
dataset_channel=[
|
||||
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
|
||||
],
|
||||
inference_channel=[
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
|
||||
])
|
||||
|
||||
data_cfg = dict(
|
||||
image_size=512,
|
||||
base_size=256,
|
||||
base_sigma=2,
|
||||
heatmap_size=[128],
|
||||
num_joints=channel_cfg['dataset_joints'],
|
||||
dataset_channel=channel_cfg['dataset_channel'],
|
||||
inference_channel=channel_cfg['inference_channel'],
|
||||
num_scales=1,
|
||||
scale_aware_sigma=False,
|
||||
)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = dataset_class(
|
||||
ann_file='tests/data/mhp/test_mhp.json',
|
||||
img_prefix='tests/data/mhp/',
|
||||
data_cfg=data_cfg,
|
||||
pipeline=[],
|
||||
test_mode=False)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
custom_dataset = dataset_class(
|
||||
ann_file='tests/data/mhp/test_mhp.json',
|
||||
img_prefix='tests/data/mhp/',
|
||||
data_cfg=data_cfg,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
image_id = 2889
|
||||
assert image_id in custom_dataset.img_ids
|
||||
assert len(custom_dataset.img_ids) == 2
|
||||
_ = custom_dataset[0]
|
||||
assert custom_dataset.dataset_name == 'mhp'
|
||||
|
||||
outputs = convert_coco_to_output(custom_dataset.coco)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, 'mAP')
|
||||
assert_almost_equal(infos['AP'], 1.0)
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
_ = custom_dataset.evaluate(outputs, tmpdir, 'PCK')
|
||||
|
||||
|
||||
def test_bottom_up_AIC_dataset_compatibility():
|
||||
dataset = 'BottomUpAicDataset'
|
||||
# test MHP datasets
|
||||
dataset_class = DATASETS.get(dataset)
|
||||
|
||||
channel_cfg = dict(
|
||||
num_output_channels=14,
|
||||
dataset_joints=14,
|
||||
dataset_channel=[
|
||||
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],
|
||||
],
|
||||
inference_channel=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13])
|
||||
|
||||
data_cfg = dict(
|
||||
image_size=512,
|
||||
base_size=256,
|
||||
base_sigma=2,
|
||||
heatmap_size=[128],
|
||||
num_joints=channel_cfg['dataset_joints'],
|
||||
dataset_channel=channel_cfg['dataset_channel'],
|
||||
inference_channel=channel_cfg['inference_channel'],
|
||||
num_scales=1,
|
||||
scale_aware_sigma=False,
|
||||
)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = dataset_class(
|
||||
ann_file='tests/data/aic/test_aic.json',
|
||||
img_prefix='tests/data/aic/',
|
||||
data_cfg=data_cfg,
|
||||
pipeline=[],
|
||||
test_mode=False)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
custom_dataset = dataset_class(
|
||||
ann_file='tests/data/aic/test_aic.json',
|
||||
img_prefix='tests/data/aic/',
|
||||
data_cfg=data_cfg,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
image_id = 1
|
||||
assert image_id in custom_dataset.img_ids
|
||||
assert len(custom_dataset.img_ids) == 3
|
||||
_ = custom_dataset[0]
|
||||
|
||||
outputs = convert_coco_to_output(custom_dataset.coco)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, 'mAP')
|
||||
assert_almost_equal(infos['AP'], 1.0)
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
_ = custom_dataset.evaluate(outputs, tmpdir, 'PCK')
|
||||
|
||||
|
||||
def test_bottom_up_COCO_wholebody_dataset_compatibility():
|
||||
dataset = 'BottomUpCocoWholeBodyDataset'
|
||||
# test COCO-wholebody datasets
|
||||
dataset_class = DATASETS.get(dataset)
|
||||
|
||||
channel_cfg = dict(
|
||||
num_output_channels=133,
|
||||
dataset_joints=133,
|
||||
dataset_channel=[
|
||||
list(range(133)),
|
||||
],
|
||||
inference_channel=list(range(133)))
|
||||
|
||||
data_cfg = dict(
|
||||
image_size=512,
|
||||
base_size=256,
|
||||
base_sigma=2,
|
||||
heatmap_size=[128, 256],
|
||||
num_joints=channel_cfg['dataset_joints'],
|
||||
dataset_channel=channel_cfg['dataset_channel'],
|
||||
inference_channel=channel_cfg['inference_channel'],
|
||||
num_scales=2,
|
||||
scale_aware_sigma=False,
|
||||
)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = dataset_class(
|
||||
ann_file='tests/data/coco/test_coco_wholebody.json',
|
||||
img_prefix='tests/data/coco/',
|
||||
data_cfg=data_cfg,
|
||||
pipeline=[],
|
||||
test_mode=False)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
custom_dataset = dataset_class(
|
||||
ann_file='tests/data/coco/test_coco_wholebody.json',
|
||||
img_prefix='tests/data/coco/',
|
||||
data_cfg=data_cfg,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
assert custom_dataset.test_mode is True
|
||||
assert custom_dataset.dataset_name == 'coco_wholebody'
|
||||
|
||||
image_id = 785
|
||||
assert image_id in custom_dataset.img_ids
|
||||
assert len(custom_dataset.img_ids) == 4
|
||||
_ = custom_dataset[0]
|
||||
|
||||
outputs = convert_coco_to_output(custom_dataset.coco, is_wholebody=True)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, 'mAP')
|
||||
assert_almost_equal(infos['AP'], 1.0)
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
_ = custom_dataset.evaluate(outputs, tmpdir, 'PCK')
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
# Copyright (c) OpenMMLab. All rights reserved.
|
||||
import pytest
|
||||
|
||||
from mmpose.datasets.datasets.animal.animal_base_dataset import \
|
||||
AnimalBaseDataset
|
||||
from mmpose.datasets.datasets.body3d.body3d_base_dataset import \
|
||||
Body3DBaseDataset
|
||||
from mmpose.datasets.datasets.bottom_up.bottom_up_base_dataset import \
|
||||
BottomUpBaseDataset
|
||||
from mmpose.datasets.datasets.face.face_base_dataset import FaceBaseDataset
|
||||
from mmpose.datasets.datasets.fashion.fashion_base_dataset import \
|
||||
FashionBaseDataset
|
||||
from mmpose.datasets.datasets.hand.hand_base_dataset import HandBaseDataset
|
||||
from mmpose.datasets.datasets.top_down.topdown_base_dataset import \
|
||||
TopDownBaseDataset
|
||||
|
||||
|
||||
@pytest.mark.parametrize('BaseDataset',
|
||||
(AnimalBaseDataset, BottomUpBaseDataset,
|
||||
FaceBaseDataset, FashionBaseDataset, HandBaseDataset,
|
||||
TopDownBaseDataset, Body3DBaseDataset))
|
||||
def test_dataset_base_class(BaseDataset):
|
||||
with pytest.raises(ImportError):
|
||||
|
||||
class Dataset(BaseDataset):
|
||||
pass
|
||||
|
||||
_ = Dataset()
|
||||
+170
@@ -0,0 +1,170 @@
|
||||
# Copyright (c) OpenMMLab. All rights reserved.
|
||||
import copy
|
||||
import tempfile
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
from numpy.testing import assert_almost_equal
|
||||
|
||||
from mmpose.datasets import DATASETS
|
||||
from tests.utils.data_utils import convert_db_to_output
|
||||
|
||||
|
||||
def test_face_300W_dataset_compatibility():
|
||||
dataset = 'Face300WDataset'
|
||||
# test Face 300W datasets
|
||||
dataset_class = DATASETS.get(dataset)
|
||||
dataset_class.load_annotations = MagicMock()
|
||||
dataset_class.coco = MagicMock()
|
||||
|
||||
channel_cfg = dict(
|
||||
num_output_channels=68,
|
||||
dataset_joints=68,
|
||||
dataset_channel=[
|
||||
list(range(68)),
|
||||
],
|
||||
inference_channel=list(range(68)))
|
||||
|
||||
data_cfg = dict(
|
||||
image_size=[256, 256],
|
||||
heatmap_size=[64, 64],
|
||||
num_output_channels=channel_cfg['num_output_channels'],
|
||||
num_joints=channel_cfg['dataset_joints'],
|
||||
dataset_channel=channel_cfg['dataset_channel'],
|
||||
inference_channel=channel_cfg['inference_channel'])
|
||||
# Test
|
||||
data_cfg_copy = copy.deepcopy(data_cfg)
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = dataset_class(
|
||||
ann_file='tests/data/300w/test_300w.json',
|
||||
img_prefix='tests/data/300w/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
custom_dataset = dataset_class(
|
||||
ann_file='tests/data/300w/test_300w.json',
|
||||
img_prefix='tests/data/300w/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=False)
|
||||
|
||||
assert custom_dataset.test_mode is False
|
||||
assert custom_dataset.num_images == 2
|
||||
_ = custom_dataset[0]
|
||||
|
||||
outputs = convert_db_to_output(custom_dataset.db)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, ['NME'])
|
||||
assert_almost_equal(infos['NME'], 0.0)
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
_ = custom_dataset.evaluate(outputs, tmpdir, 'mAP')
|
||||
|
||||
|
||||
def test_face_AFLW_dataset_compatibility():
|
||||
dataset = 'FaceAFLWDataset'
|
||||
# test Face AFLW datasets
|
||||
dataset_class = DATASETS.get(dataset)
|
||||
dataset_class.load_annotations = MagicMock()
|
||||
dataset_class.coco = MagicMock()
|
||||
|
||||
channel_cfg = dict(
|
||||
num_output_channels=19,
|
||||
dataset_joints=19,
|
||||
dataset_channel=[
|
||||
list(range(19)),
|
||||
],
|
||||
inference_channel=list(range(19)))
|
||||
|
||||
data_cfg = dict(
|
||||
image_size=[256, 256],
|
||||
heatmap_size=[64, 64],
|
||||
num_output_channels=channel_cfg['num_output_channels'],
|
||||
num_joints=channel_cfg['dataset_joints'],
|
||||
dataset_channel=channel_cfg['dataset_channel'],
|
||||
inference_channel=channel_cfg['inference_channel'])
|
||||
# Test
|
||||
data_cfg_copy = copy.deepcopy(data_cfg)
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = dataset_class(
|
||||
ann_file='tests/data/aflw/test_aflw.json',
|
||||
img_prefix='tests/data/aflw/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
custom_dataset = dataset_class(
|
||||
ann_file='tests/data/aflw/test_aflw.json',
|
||||
img_prefix='tests/data/aflw/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=False)
|
||||
|
||||
assert custom_dataset.test_mode is False
|
||||
assert custom_dataset.num_images == 2
|
||||
_ = custom_dataset[0]
|
||||
|
||||
outputs = convert_db_to_output(custom_dataset.db)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, ['NME'])
|
||||
assert_almost_equal(infos['NME'], 0.0)
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
_ = custom_dataset.evaluate(outputs, tmpdir, 'mAP')
|
||||
|
||||
|
||||
def test_face_WFLW_dataset_compatibility():
|
||||
dataset = 'FaceWFLWDataset'
|
||||
# test Face WFLW datasets
|
||||
dataset_class = DATASETS.get(dataset)
|
||||
dataset_class.load_annotations = MagicMock()
|
||||
dataset_class.coco = MagicMock()
|
||||
|
||||
channel_cfg = dict(
|
||||
num_output_channels=98,
|
||||
dataset_joints=98,
|
||||
dataset_channel=[
|
||||
list(range(98)),
|
||||
],
|
||||
inference_channel=list(range(98)))
|
||||
|
||||
data_cfg = dict(
|
||||
image_size=[256, 256],
|
||||
heatmap_size=[64, 64],
|
||||
num_output_channels=channel_cfg['num_output_channels'],
|
||||
num_joints=channel_cfg['dataset_joints'],
|
||||
dataset_channel=channel_cfg['dataset_channel'],
|
||||
inference_channel=channel_cfg['inference_channel'])
|
||||
# Test
|
||||
data_cfg_copy = copy.deepcopy(data_cfg)
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = dataset_class(
|
||||
ann_file='tests/data/wflw/test_wflw.json',
|
||||
img_prefix='tests/data/wflw/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
custom_dataset = dataset_class(
|
||||
ann_file='tests/data/wflw/test_wflw.json',
|
||||
img_prefix='tests/data/wflw/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=False)
|
||||
|
||||
assert custom_dataset.test_mode is False
|
||||
assert custom_dataset.num_images == 2
|
||||
_ = custom_dataset[0]
|
||||
|
||||
outputs = convert_db_to_output(custom_dataset.db)
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, ['NME'])
|
||||
assert_almost_equal(infos['NME'], 0.0)
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
_ = custom_dataset.evaluate(outputs, tmpdir, 'mAP')
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
# Copyright (c) OpenMMLab. All rights reserved.
|
||||
import tempfile
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
from numpy.testing import assert_almost_equal
|
||||
|
||||
from mmpose.datasets import DATASETS
|
||||
from tests.utils.data_utils import convert_db_to_output
|
||||
|
||||
|
||||
def test_deepfashion_dataset_compatibility():
|
||||
dataset = 'DeepFashionDataset'
|
||||
# test JHMDB datasets
|
||||
dataset_class = DATASETS.get(dataset)
|
||||
dataset_class.load_annotations = MagicMock()
|
||||
dataset_class.coco = MagicMock()
|
||||
|
||||
channel_cfg = dict(
|
||||
num_output_channels=8,
|
||||
dataset_joints=8,
|
||||
dataset_channel=[
|
||||
[0, 1, 2, 3, 4, 5, 6, 7],
|
||||
],
|
||||
inference_channel=[0, 1, 2, 3, 4, 5, 6, 7])
|
||||
|
||||
data_cfg = dict(
|
||||
image_size=[192, 256],
|
||||
heatmap_size=[48, 64],
|
||||
num_output_channels=channel_cfg['num_output_channels'],
|
||||
num_joints=channel_cfg['dataset_joints'],
|
||||
dataset_channel=channel_cfg['dataset_channel'],
|
||||
inference_channel=channel_cfg['inference_channel'],
|
||||
soft_nms=False,
|
||||
nms_thr=1.0,
|
||||
oks_thr=0.9,
|
||||
vis_thr=0.2,
|
||||
use_gt_bbox=True,
|
||||
det_bbox_thr=0.0,
|
||||
image_thr=0.0,
|
||||
bbox_file='')
|
||||
|
||||
# Test gt bbox
|
||||
with pytest.warns(DeprecationWarning):
|
||||
custom_dataset = dataset_class(
|
||||
ann_file='tests/data/fld/test_fld.json',
|
||||
img_prefix='tests/data/fld/',
|
||||
subset='full',
|
||||
data_cfg=data_cfg,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
assert custom_dataset.test_mode is True
|
||||
assert custom_dataset.dataset_name == 'deepfashion_full'
|
||||
|
||||
image_id = 128
|
||||
assert image_id in custom_dataset.img_ids
|
||||
assert len(custom_dataset.img_ids) == 2
|
||||
_ = custom_dataset[0]
|
||||
|
||||
outputs = convert_db_to_output(custom_dataset.db)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, ['PCK', 'EPE', 'AUC'])
|
||||
assert_almost_equal(infos['PCK'], 1.0)
|
||||
assert_almost_equal(infos['AUC'], 0.95)
|
||||
assert_almost_equal(infos['EPE'], 0.0)
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, 'mAP')
|
||||
+388
@@ -0,0 +1,388 @@
|
||||
# Copyright (c) OpenMMLab. All rights reserved.
|
||||
import copy
|
||||
import tempfile
|
||||
|
||||
import pytest
|
||||
from numpy.testing import assert_almost_equal
|
||||
|
||||
from mmpose.datasets import DATASETS
|
||||
from tests.utils.data_utils import convert_db_to_output
|
||||
|
||||
|
||||
def test_top_down_OneHand10K_dataset_compatibility():
|
||||
dataset = 'OneHand10KDataset'
|
||||
dataset_class = DATASETS.get(dataset)
|
||||
|
||||
channel_cfg = dict(
|
||||
num_output_channels=21,
|
||||
dataset_joints=21,
|
||||
dataset_channel=[
|
||||
[
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
|
||||
18, 19, 20
|
||||
],
|
||||
],
|
||||
inference_channel=[
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
|
||||
19, 20
|
||||
])
|
||||
|
||||
data_cfg = dict(
|
||||
image_size=[256, 256],
|
||||
heatmap_size=[64, 64],
|
||||
num_output_channels=channel_cfg['num_output_channels'],
|
||||
num_joints=channel_cfg['dataset_joints'],
|
||||
dataset_channel=channel_cfg['dataset_channel'],
|
||||
inference_channel=channel_cfg['inference_channel'])
|
||||
# Test
|
||||
data_cfg_copy = copy.deepcopy(data_cfg)
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = dataset_class(
|
||||
ann_file='tests/data/onehand10k/test_onehand10k.json',
|
||||
img_prefix='tests/data/onehand10k/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
custom_dataset = dataset_class(
|
||||
ann_file='tests/data/onehand10k/test_onehand10k.json',
|
||||
img_prefix='tests/data/onehand10k/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=False)
|
||||
|
||||
assert custom_dataset.test_mode is False
|
||||
assert custom_dataset.num_images == 4
|
||||
_ = custom_dataset[0]
|
||||
|
||||
outputs = convert_db_to_output(custom_dataset.db)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, ['PCK', 'EPE', 'AUC'])
|
||||
assert_almost_equal(infos['PCK'], 1.0)
|
||||
assert_almost_equal(infos['AUC'], 0.95)
|
||||
assert_almost_equal(infos['EPE'], 0.0)
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, 'mAP')
|
||||
|
||||
|
||||
def test_top_down_FreiHand_dataset_compatibility():
|
||||
dataset = 'FreiHandDataset'
|
||||
dataset_class = DATASETS.get(dataset)
|
||||
|
||||
channel_cfg = dict(
|
||||
num_output_channels=21,
|
||||
dataset_joints=21,
|
||||
dataset_channel=[
|
||||
[
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
|
||||
18, 19, 20
|
||||
],
|
||||
],
|
||||
inference_channel=[
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
|
||||
19, 20
|
||||
])
|
||||
|
||||
data_cfg = dict(
|
||||
image_size=[224, 224],
|
||||
heatmap_size=[56, 56],
|
||||
num_output_channels=channel_cfg['num_output_channels'],
|
||||
num_joints=channel_cfg['dataset_joints'],
|
||||
dataset_channel=channel_cfg['dataset_channel'],
|
||||
inference_channel=channel_cfg['inference_channel'])
|
||||
# Test
|
||||
data_cfg_copy = copy.deepcopy(data_cfg)
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = dataset_class(
|
||||
ann_file='tests/data/freihand/test_freihand.json',
|
||||
img_prefix='tests/data/freihand/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
custom_dataset = dataset_class(
|
||||
ann_file='tests/data/freihand/test_freihand.json',
|
||||
img_prefix='tests/data/freihand/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=False)
|
||||
|
||||
assert custom_dataset.test_mode is False
|
||||
assert custom_dataset.num_images == 8
|
||||
_ = custom_dataset[0]
|
||||
|
||||
outputs = convert_db_to_output(custom_dataset.db)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, ['PCK', 'EPE', 'AUC'])
|
||||
assert_almost_equal(infos['PCK'], 1.0)
|
||||
assert_almost_equal(infos['AUC'], 0.95)
|
||||
assert_almost_equal(infos['EPE'], 0.0)
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, 'mAP')
|
||||
|
||||
|
||||
def test_top_down_RHD_dataset_compatibility():
|
||||
dataset = 'Rhd2DDataset'
|
||||
dataset_class = DATASETS.get(dataset)
|
||||
|
||||
channel_cfg = dict(
|
||||
num_output_channels=21,
|
||||
dataset_joints=21,
|
||||
dataset_channel=[
|
||||
[
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
|
||||
18, 19, 20
|
||||
],
|
||||
],
|
||||
inference_channel=[
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
|
||||
19, 20
|
||||
])
|
||||
|
||||
data_cfg = dict(
|
||||
image_size=[256, 256],
|
||||
heatmap_size=[64, 64],
|
||||
num_output_channels=channel_cfg['num_output_channels'],
|
||||
num_joints=channel_cfg['dataset_joints'],
|
||||
dataset_channel=channel_cfg['dataset_channel'],
|
||||
inference_channel=channel_cfg['inference_channel'])
|
||||
# Test
|
||||
data_cfg_copy = copy.deepcopy(data_cfg)
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = dataset_class(
|
||||
ann_file='tests/data/rhd/test_rhd.json',
|
||||
img_prefix='tests/data/rhd/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
custom_dataset = dataset_class(
|
||||
ann_file='tests/data/rhd/test_rhd.json',
|
||||
img_prefix='tests/data/rhd/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=False)
|
||||
|
||||
assert custom_dataset.test_mode is False
|
||||
assert custom_dataset.num_images == 3
|
||||
_ = custom_dataset[0]
|
||||
|
||||
outputs = convert_db_to_output(custom_dataset.db)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, ['PCK', 'EPE', 'AUC'])
|
||||
assert_almost_equal(infos['PCK'], 1.0)
|
||||
assert_almost_equal(infos['AUC'], 0.95)
|
||||
assert_almost_equal(infos['EPE'], 0.0)
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, 'mAP')
|
||||
|
||||
|
||||
def test_top_down_Panoptic_dataset_compatibility():
|
||||
dataset = 'PanopticDataset'
|
||||
dataset_class = DATASETS.get(dataset)
|
||||
|
||||
channel_cfg = dict(
|
||||
num_output_channels=21,
|
||||
dataset_joints=21,
|
||||
dataset_channel=[
|
||||
[
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
|
||||
18, 19, 20
|
||||
],
|
||||
],
|
||||
inference_channel=[
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
|
||||
19, 20
|
||||
])
|
||||
|
||||
data_cfg = dict(
|
||||
image_size=[256, 256],
|
||||
heatmap_size=[64, 64],
|
||||
num_output_channels=channel_cfg['num_output_channels'],
|
||||
num_joints=channel_cfg['dataset_joints'],
|
||||
dataset_channel=channel_cfg['dataset_channel'],
|
||||
inference_channel=channel_cfg['inference_channel'])
|
||||
# Test
|
||||
data_cfg_copy = copy.deepcopy(data_cfg)
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = dataset_class(
|
||||
ann_file='tests/data/panoptic/test_panoptic.json',
|
||||
img_prefix='tests/data/panoptic/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
custom_dataset = dataset_class(
|
||||
ann_file='tests/data/panoptic/test_panoptic.json',
|
||||
img_prefix='tests/data/panoptic/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=False)
|
||||
|
||||
assert custom_dataset.test_mode is False
|
||||
assert custom_dataset.num_images == 4
|
||||
_ = custom_dataset[0]
|
||||
|
||||
outputs = convert_db_to_output(custom_dataset.db)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir,
|
||||
['PCKh', 'EPE', 'AUC'])
|
||||
assert_almost_equal(infos['PCKh'], 1.0)
|
||||
assert_almost_equal(infos['AUC'], 0.95)
|
||||
assert_almost_equal(infos['EPE'], 0.0)
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, 'mAP')
|
||||
|
||||
|
||||
def test_top_down_InterHand2D_dataset_compatibility():
|
||||
dataset = 'InterHand2DDataset'
|
||||
dataset_class = DATASETS.get(dataset)
|
||||
|
||||
channel_cfg = dict(
|
||||
num_output_channels=21,
|
||||
dataset_joints=21,
|
||||
dataset_channel=[
|
||||
[
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
|
||||
18, 19, 20
|
||||
],
|
||||
],
|
||||
inference_channel=[
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
|
||||
19, 20
|
||||
])
|
||||
|
||||
data_cfg = dict(
|
||||
image_size=[256, 256],
|
||||
heatmap_size=[64, 64],
|
||||
num_output_channels=channel_cfg['num_output_channels'],
|
||||
num_joints=channel_cfg['dataset_joints'],
|
||||
dataset_channel=channel_cfg['dataset_channel'],
|
||||
inference_channel=channel_cfg['inference_channel'])
|
||||
# Test
|
||||
data_cfg_copy = copy.deepcopy(data_cfg)
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = dataset_class(
|
||||
ann_file='tests/data/interhand2.6m/test_interhand2.6m_data.json',
|
||||
camera_file='tests/data/interhand2.6m/'
|
||||
'test_interhand2.6m_camera.json',
|
||||
joint_file='tests/data/interhand2.6m/'
|
||||
'test_interhand2.6m_joint_3d.json',
|
||||
img_prefix='tests/data/interhand2.6m/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
custom_dataset = dataset_class(
|
||||
ann_file='tests/data/interhand2.6m/test_interhand2.6m_data.json',
|
||||
camera_file='tests/data/interhand2.6m/'
|
||||
'test_interhand2.6m_camera.json',
|
||||
joint_file='tests/data/interhand2.6m/'
|
||||
'test_interhand2.6m_joint_3d.json',
|
||||
img_prefix='tests/data/interhand2.6m/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=False)
|
||||
|
||||
assert custom_dataset.test_mode is False
|
||||
assert custom_dataset.num_images == 4
|
||||
assert len(custom_dataset.db) == 6
|
||||
|
||||
_ = custom_dataset[0]
|
||||
|
||||
outputs = convert_db_to_output(custom_dataset.db)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, ['PCK', 'EPE', 'AUC'])
|
||||
print(infos, flush=True)
|
||||
assert_almost_equal(infos['PCK'], 1.0)
|
||||
assert_almost_equal(infos['AUC'], 0.95)
|
||||
assert_almost_equal(infos['EPE'], 0.0)
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, 'mAP')
|
||||
|
||||
|
||||
def test_top_down_InterHand3D_dataset_compatibility():
|
||||
dataset = 'InterHand3DDataset'
|
||||
dataset_class = DATASETS.get(dataset)
|
||||
|
||||
channel_cfg = dict(
|
||||
num_output_channels=42,
|
||||
dataset_joints=42,
|
||||
dataset_channel=[
|
||||
[
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
|
||||
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
|
||||
34, 35, 36, 37, 38, 39, 40, 41
|
||||
],
|
||||
],
|
||||
inference_channel=[
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
|
||||
19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
|
||||
36, 37, 38, 39, 40, 41
|
||||
])
|
||||
|
||||
data_cfg = dict(
|
||||
image_size=[256, 256],
|
||||
heatmap_size=[64, 64, 64],
|
||||
heatmap3d_depth_bound=400.0,
|
||||
heatmap_size_root=64,
|
||||
root_depth_bound=400.0,
|
||||
num_output_channels=channel_cfg['num_output_channels'],
|
||||
num_joints=channel_cfg['dataset_joints'],
|
||||
dataset_channel=channel_cfg['dataset_channel'],
|
||||
inference_channel=channel_cfg['inference_channel'])
|
||||
# Test
|
||||
data_cfg_copy = copy.deepcopy(data_cfg)
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = dataset_class(
|
||||
ann_file='tests/data/interhand2.6m/test_interhand2.6m_data.json',
|
||||
camera_file='tests/data/interhand2.6m/'
|
||||
'test_interhand2.6m_camera.json',
|
||||
joint_file='tests/data/interhand2.6m/'
|
||||
'test_interhand2.6m_joint_3d.json',
|
||||
img_prefix='tests/data/interhand2.6m/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
custom_dataset = dataset_class(
|
||||
ann_file='tests/data/interhand2.6m/test_interhand2.6m_data.json',
|
||||
camera_file='tests/data/interhand2.6m/'
|
||||
'test_interhand2.6m_camera.json',
|
||||
joint_file='tests/data/interhand2.6m/'
|
||||
'test_interhand2.6m_joint_3d.json',
|
||||
img_prefix='tests/data/interhand2.6m/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=False)
|
||||
|
||||
assert custom_dataset.test_mode is False
|
||||
assert custom_dataset.num_images == 4
|
||||
assert len(custom_dataset.db) == 4
|
||||
|
||||
_ = custom_dataset[0]
|
||||
|
||||
outputs = convert_db_to_output(
|
||||
custom_dataset.db, keys=['rel_root_depth', 'hand_type'], is_3d=True)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir,
|
||||
['MRRPE', 'MPJPE', 'Handedness_acc'])
|
||||
assert_almost_equal(infos['MRRPE'], 0.0, decimal=5)
|
||||
assert_almost_equal(infos['MPJPE_all'], 0.0, decimal=5)
|
||||
assert_almost_equal(infos['MPJPE_single'], 0.0, decimal=5)
|
||||
assert_almost_equal(infos['MPJPE_interacting'], 0.0, decimal=5)
|
||||
assert_almost_equal(infos['Handedness_acc'], 1.0)
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, 'mAP')
|
||||
+156
@@ -0,0 +1,156 @@
|
||||
# Copyright (c) OpenMMLab. All rights reserved.
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from mmpose.apis import (extract_pose_sequence, get_track_id,
|
||||
inference_bottom_up_pose_model,
|
||||
inference_pose_lifter_model,
|
||||
inference_top_down_pose_model, init_pose_model,
|
||||
vis_3d_pose_result, vis_pose_result,
|
||||
vis_pose_tracking_result)
|
||||
|
||||
|
||||
def test_inference_without_dataset_info():
|
||||
# Top down
|
||||
pose_model = init_pose_model(
|
||||
'configs/body/2d_kpt_sview_rgb_img/topdown_heatmap/'
|
||||
'coco/res50_coco_256x192.py',
|
||||
None,
|
||||
device='cpu')
|
||||
|
||||
if 'dataset_info' in pose_model.cfg:
|
||||
_ = pose_model.cfg.pop('dataset_info')
|
||||
|
||||
image_name = 'tests/data/coco/000000000785.jpg'
|
||||
person_result = []
|
||||
person_result.append({'bbox': [50, 50, 50, 100]})
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
pose_results, _ = inference_top_down_pose_model(
|
||||
pose_model, image_name, person_result, format='xywh')
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
vis_pose_result(pose_model, image_name, pose_results)
|
||||
|
||||
with pytest.raises(NotImplementedError):
|
||||
with pytest.warns(DeprecationWarning):
|
||||
pose_results, _ = inference_top_down_pose_model(
|
||||
pose_model,
|
||||
image_name,
|
||||
person_result,
|
||||
format='xywh',
|
||||
dataset='test')
|
||||
|
||||
# Bottom up
|
||||
pose_model = init_pose_model(
|
||||
'configs/body/2d_kpt_sview_rgb_img/associative_embedding/'
|
||||
'coco/res50_coco_512x512.py',
|
||||
None,
|
||||
device='cpu')
|
||||
if 'dataset_info' in pose_model.cfg:
|
||||
_ = pose_model.cfg.pop('dataset_info')
|
||||
|
||||
image_name = 'tests/data/coco/000000000785.jpg'
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
pose_results, _ = inference_bottom_up_pose_model(
|
||||
pose_model, image_name)
|
||||
with pytest.warns(DeprecationWarning):
|
||||
vis_pose_result(pose_model, image_name, pose_results)
|
||||
|
||||
# Top down tracking
|
||||
pose_model = init_pose_model(
|
||||
'configs/body/2d_kpt_sview_rgb_img/topdown_heatmap/'
|
||||
'coco/res50_coco_256x192.py',
|
||||
None,
|
||||
device='cpu')
|
||||
|
||||
if 'dataset_info' in pose_model.cfg:
|
||||
_ = pose_model.cfg.pop('dataset_info')
|
||||
|
||||
image_name = 'tests/data/coco/000000000785.jpg'
|
||||
person_result = [{'bbox': [50, 50, 50, 100]}]
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
pose_results, _ = inference_top_down_pose_model(
|
||||
pose_model, image_name, person_result, format='xywh')
|
||||
|
||||
pose_results, _ = get_track_id(pose_results, [], next_id=0)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
vis_pose_tracking_result(pose_model, image_name, pose_results)
|
||||
|
||||
with pytest.raises(NotImplementedError):
|
||||
with pytest.warns(DeprecationWarning):
|
||||
vis_pose_tracking_result(
|
||||
pose_model, image_name, pose_results, dataset='test')
|
||||
|
||||
# Bottom up tracking
|
||||
pose_model = init_pose_model(
|
||||
'configs/body/2d_kpt_sview_rgb_img/associative_embedding/'
|
||||
'coco/res50_coco_512x512.py',
|
||||
None,
|
||||
device='cpu')
|
||||
|
||||
if 'dataset_info' in pose_model.cfg:
|
||||
_ = pose_model.cfg.pop('dataset_info')
|
||||
|
||||
image_name = 'tests/data/coco/000000000785.jpg'
|
||||
with pytest.warns(DeprecationWarning):
|
||||
pose_results, _ = inference_bottom_up_pose_model(
|
||||
pose_model, image_name)
|
||||
|
||||
pose_results, next_id = get_track_id(pose_results, [], next_id=0)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
vis_pose_tracking_result(
|
||||
pose_model,
|
||||
image_name,
|
||||
pose_results,
|
||||
dataset='BottomUpCocoDataset')
|
||||
|
||||
# Pose lifting
|
||||
pose_model = init_pose_model(
|
||||
'configs/body/3d_kpt_sview_rgb_img/pose_lift/'
|
||||
'h36m/simplebaseline3d_h36m.py',
|
||||
None,
|
||||
device='cpu')
|
||||
|
||||
pose_det_result = {
|
||||
'keypoints': np.zeros((17, 3)),
|
||||
'bbox': [50, 50, 50, 50],
|
||||
'track_id': 0,
|
||||
'image_name': 'tests/data/h36m/S1_Directions_1.54138969_000001.jpg',
|
||||
}
|
||||
|
||||
if 'dataset_info' in pose_model.cfg:
|
||||
_ = pose_model.cfg.pop('dataset_info')
|
||||
|
||||
pose_results_2d = [[pose_det_result]]
|
||||
|
||||
dataset = pose_model.cfg.data['test']['type']
|
||||
|
||||
pose_results_2d = extract_pose_sequence(
|
||||
pose_results_2d, frame_idx=0, causal=False, seq_len=1, step=1)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = inference_pose_lifter_model(
|
||||
pose_model, pose_results_2d, dataset, with_track_id=False)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
pose_lift_results = inference_pose_lifter_model(
|
||||
pose_model, pose_results_2d, dataset, with_track_id=True)
|
||||
|
||||
for res in pose_lift_results:
|
||||
res['title'] = 'title'
|
||||
with pytest.warns(DeprecationWarning):
|
||||
vis_3d_pose_result(
|
||||
pose_model,
|
||||
pose_lift_results,
|
||||
img=pose_results_2d[0][0]['image_name'],
|
||||
dataset=dataset)
|
||||
|
||||
with pytest.raises(NotImplementedError):
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = inference_pose_lifter_model(
|
||||
pose_model, pose_results_2d, dataset='test')
|
||||
+748
@@ -0,0 +1,748 @@
|
||||
# Copyright (c) OpenMMLab. All rights reserved.
|
||||
import copy
|
||||
import tempfile
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
from numpy.testing import assert_almost_equal
|
||||
|
||||
from mmpose.datasets import DATASETS
|
||||
from tests.utils.data_utils import convert_db_to_output
|
||||
|
||||
|
||||
def test_top_down_COCO_dataset_compatibility():
|
||||
dataset = 'TopDownCocoDataset'
|
||||
# test COCO datasets
|
||||
dataset_class = DATASETS.get(dataset)
|
||||
dataset_class.load_annotations = MagicMock()
|
||||
dataset_class.coco = MagicMock()
|
||||
|
||||
channel_cfg = dict(
|
||||
num_output_channels=17,
|
||||
dataset_joints=17,
|
||||
dataset_channel=[
|
||||
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],
|
||||
],
|
||||
inference_channel=[
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
|
||||
])
|
||||
|
||||
data_cfg = dict(
|
||||
image_size=[192, 256],
|
||||
heatmap_size=[48, 64],
|
||||
num_output_channels=channel_cfg['num_output_channels'],
|
||||
num_joints=channel_cfg['dataset_joints'],
|
||||
dataset_channel=channel_cfg['dataset_channel'],
|
||||
inference_channel=channel_cfg['inference_channel'],
|
||||
soft_nms=False,
|
||||
nms_thr=1.0,
|
||||
oks_thr=0.9,
|
||||
vis_thr=0.2,
|
||||
use_gt_bbox=True,
|
||||
det_bbox_thr=0.0,
|
||||
bbox_file='tests/data/coco/test_coco_det_AP_H_56.json',
|
||||
)
|
||||
# Test det bbox
|
||||
data_cfg_copy = copy.deepcopy(data_cfg)
|
||||
data_cfg_copy['use_gt_bbox'] = False
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = dataset_class(
|
||||
ann_file='tests/data/coco/test_coco.json',
|
||||
img_prefix='tests/data/coco/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = dataset_class(
|
||||
ann_file='tests/data/coco/test_coco.json',
|
||||
img_prefix='tests/data/coco/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=False)
|
||||
|
||||
# Test gt bbox
|
||||
with pytest.warns(DeprecationWarning):
|
||||
custom_dataset = dataset_class(
|
||||
ann_file='tests/data/coco/test_coco.json',
|
||||
img_prefix='tests/data/coco/',
|
||||
data_cfg=data_cfg,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
assert custom_dataset.test_mode is True
|
||||
assert custom_dataset.dataset_name == 'coco'
|
||||
|
||||
image_id = 785
|
||||
assert image_id in custom_dataset.img_ids
|
||||
assert len(custom_dataset.img_ids) == 4
|
||||
_ = custom_dataset[0]
|
||||
|
||||
outputs = convert_db_to_output(custom_dataset.db)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, 'mAP')
|
||||
assert_almost_equal(infos['AP'], 1.0)
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
_ = custom_dataset.evaluate(outputs, tmpdir, 'PCK')
|
||||
|
||||
|
||||
def test_top_down_MHP_dataset_compatibility():
|
||||
dataset = 'TopDownMhpDataset'
|
||||
# test MHP datasets
|
||||
dataset_class = DATASETS.get(dataset)
|
||||
dataset_class.load_annotations = MagicMock()
|
||||
dataset_class.coco = MagicMock()
|
||||
|
||||
channel_cfg = dict(
|
||||
num_output_channels=16,
|
||||
dataset_joints=16,
|
||||
dataset_channel=[
|
||||
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
|
||||
],
|
||||
inference_channel=[
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
|
||||
])
|
||||
|
||||
data_cfg = dict(
|
||||
image_size=[192, 256],
|
||||
heatmap_size=[48, 64],
|
||||
num_output_channels=channel_cfg['num_output_channels'],
|
||||
num_joints=channel_cfg['dataset_joints'],
|
||||
dataset_channel=channel_cfg['dataset_channel'],
|
||||
inference_channel=channel_cfg['inference_channel'],
|
||||
soft_nms=False,
|
||||
nms_thr=1.0,
|
||||
oks_thr=0.9,
|
||||
vis_thr=0.2,
|
||||
bbox_thr=1.0,
|
||||
use_gt_bbox=True,
|
||||
det_bbox_thr=0.0,
|
||||
bbox_file='',
|
||||
)
|
||||
|
||||
# Test det bbox
|
||||
with pytest.raises(AssertionError):
|
||||
data_cfg_copy = copy.deepcopy(data_cfg)
|
||||
data_cfg_copy['use_gt_bbox'] = False
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = dataset_class(
|
||||
ann_file='tests/data/mhp/test_mhp.json',
|
||||
img_prefix='tests/data/mhp/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
# Test gt bbox
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = dataset_class(
|
||||
ann_file='tests/data/mhp/test_mhp.json',
|
||||
img_prefix='tests/data/mhp/',
|
||||
data_cfg=data_cfg,
|
||||
pipeline=[],
|
||||
test_mode=False)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
custom_dataset = dataset_class(
|
||||
ann_file='tests/data/mhp/test_mhp.json',
|
||||
img_prefix='tests/data/mhp/',
|
||||
data_cfg=data_cfg,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
assert custom_dataset.test_mode is True
|
||||
assert custom_dataset.dataset_name == 'mhp'
|
||||
|
||||
image_id = 2889
|
||||
assert image_id in custom_dataset.img_ids
|
||||
assert len(custom_dataset.img_ids) == 2
|
||||
_ = custom_dataset[0]
|
||||
|
||||
outputs = convert_db_to_output(custom_dataset.db)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, 'mAP')
|
||||
assert_almost_equal(infos['AP'], 1.0)
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
_ = custom_dataset.evaluate(outputs, tmpdir, 'PCK')
|
||||
|
||||
|
||||
def test_top_down_PoseTrack18_dataset_compatibility():
|
||||
dataset = 'TopDownPoseTrack18Dataset'
|
||||
# test PoseTrack datasets
|
||||
dataset_class = DATASETS.get(dataset)
|
||||
dataset_class.load_annotations = MagicMock()
|
||||
dataset_class.coco = MagicMock()
|
||||
|
||||
channel_cfg = dict(
|
||||
num_output_channels=17,
|
||||
dataset_joints=17,
|
||||
dataset_channel=[
|
||||
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],
|
||||
],
|
||||
inference_channel=[
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
|
||||
])
|
||||
|
||||
data_cfg = dict(
|
||||
image_size=[192, 256],
|
||||
heatmap_size=[48, 64],
|
||||
num_output_channels=channel_cfg['num_output_channels'],
|
||||
num_joints=channel_cfg['dataset_joints'],
|
||||
dataset_channel=channel_cfg['dataset_channel'],
|
||||
inference_channel=channel_cfg['inference_channel'],
|
||||
soft_nms=False,
|
||||
nms_thr=1.0,
|
||||
oks_thr=0.9,
|
||||
vis_thr=0.2,
|
||||
use_gt_bbox=True,
|
||||
det_bbox_thr=0.0,
|
||||
bbox_file='tests/data/posetrack18/annotations/'
|
||||
'test_posetrack18_human_detections.json',
|
||||
)
|
||||
# Test det bbox
|
||||
data_cfg_copy = copy.deepcopy(data_cfg)
|
||||
data_cfg_copy['use_gt_bbox'] = False
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = dataset_class(
|
||||
ann_file='tests/data/posetrack18/annotations/'
|
||||
'test_posetrack18_val.json',
|
||||
img_prefix='tests/data/posetrack18/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = dataset_class(
|
||||
ann_file='tests/data/posetrack18/annotations/'
|
||||
'test_posetrack18_val.json',
|
||||
img_prefix='tests/data/posetrack18/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=False)
|
||||
|
||||
# Test gt bbox
|
||||
with pytest.warns(DeprecationWarning):
|
||||
custom_dataset = dataset_class(
|
||||
ann_file='tests/data/posetrack18/annotations/'
|
||||
'test_posetrack18_val.json',
|
||||
img_prefix='tests/data/posetrack18/',
|
||||
data_cfg=data_cfg,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
assert custom_dataset.test_mode is True
|
||||
assert custom_dataset.dataset_name == 'posetrack18'
|
||||
|
||||
image_id = 10128340000
|
||||
assert image_id in custom_dataset.img_ids
|
||||
assert len(custom_dataset.img_ids) == 3
|
||||
_ = custom_dataset[0]
|
||||
|
||||
|
||||
def test_top_down_CrowdPose_dataset_compatibility():
|
||||
dataset = 'TopDownCrowdPoseDataset'
|
||||
# test CrowdPose datasets
|
||||
dataset_class = DATASETS.get(dataset)
|
||||
dataset_class.load_annotations = MagicMock()
|
||||
dataset_class.coco = MagicMock()
|
||||
|
||||
channel_cfg = dict(
|
||||
num_output_channels=14,
|
||||
dataset_joints=14,
|
||||
dataset_channel=[
|
||||
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],
|
||||
],
|
||||
inference_channel=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13])
|
||||
|
||||
data_cfg = dict(
|
||||
image_size=[192, 256],
|
||||
heatmap_size=[48, 64],
|
||||
num_output_channels=channel_cfg['num_output_channels'],
|
||||
num_joints=channel_cfg['dataset_joints'],
|
||||
dataset_channel=channel_cfg['dataset_channel'],
|
||||
inference_channel=channel_cfg['inference_channel'],
|
||||
soft_nms=False,
|
||||
nms_thr=1.0,
|
||||
oks_thr=0.9,
|
||||
vis_thr=0.2,
|
||||
use_gt_bbox=True,
|
||||
det_bbox_thr=0.0,
|
||||
bbox_file='tests/data/crowdpose/test_crowdpose_det_AP_40.json',
|
||||
)
|
||||
# Test det bbox
|
||||
data_cfg_copy = copy.deepcopy(data_cfg)
|
||||
data_cfg_copy['use_gt_bbox'] = False
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = dataset_class(
|
||||
ann_file='tests/data/crowdpose/test_crowdpose.json',
|
||||
img_prefix='tests/data/crowdpose/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = dataset_class(
|
||||
ann_file='tests/data/crowdpose/test_crowdpose.json',
|
||||
img_prefix='tests/data/crowdpose/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=False)
|
||||
|
||||
# Test gt bbox
|
||||
with pytest.warns(DeprecationWarning):
|
||||
custom_dataset = dataset_class(
|
||||
ann_file='tests/data/crowdpose/test_crowdpose.json',
|
||||
img_prefix='tests/data/crowdpose/',
|
||||
data_cfg=data_cfg,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
assert custom_dataset.test_mode is True
|
||||
assert custom_dataset.dataset_name == 'crowdpose'
|
||||
|
||||
image_id = 103319
|
||||
assert image_id in custom_dataset.img_ids
|
||||
assert len(custom_dataset.img_ids) == 2
|
||||
_ = custom_dataset[0]
|
||||
|
||||
outputs = convert_db_to_output(custom_dataset.db)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, 'mAP')
|
||||
assert_almost_equal(infos['AP'], 1.0)
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
_ = custom_dataset.evaluate(outputs, tmpdir, 'PCK')
|
||||
|
||||
|
||||
def test_top_down_COCO_wholebody_dataset_compatibility():
|
||||
dataset = 'TopDownCocoWholeBodyDataset'
|
||||
# test COCO datasets
|
||||
dataset_class = DATASETS.get(dataset)
|
||||
dataset_class.load_annotations = MagicMock()
|
||||
dataset_class.coco = MagicMock()
|
||||
|
||||
channel_cfg = dict(
|
||||
num_output_channels=133,
|
||||
dataset_joints=133,
|
||||
dataset_channel=[
|
||||
list(range(133)),
|
||||
],
|
||||
inference_channel=list(range(133)))
|
||||
|
||||
data_cfg = dict(
|
||||
image_size=[192, 256],
|
||||
heatmap_size=[48, 64],
|
||||
num_output_channels=channel_cfg['num_output_channels'],
|
||||
num_joints=channel_cfg['dataset_joints'],
|
||||
dataset_channel=channel_cfg['dataset_channel'],
|
||||
inference_channel=channel_cfg['inference_channel'],
|
||||
soft_nms=False,
|
||||
nms_thr=1.0,
|
||||
oks_thr=0.9,
|
||||
vis_thr=0.2,
|
||||
use_gt_bbox=True,
|
||||
det_bbox_thr=0.0,
|
||||
bbox_file='tests/data/coco/test_coco_det_AP_H_56.json',
|
||||
)
|
||||
# Test det bbox
|
||||
data_cfg_copy = copy.deepcopy(data_cfg)
|
||||
data_cfg_copy['use_gt_bbox'] = False
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = dataset_class(
|
||||
ann_file='tests/data/coco/test_coco_wholebody.json',
|
||||
img_prefix='tests/data/coco/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = dataset_class(
|
||||
ann_file='tests/data/coco/test_coco_wholebody.json',
|
||||
img_prefix='tests/data/coco/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=False)
|
||||
|
||||
# Test gt bbox
|
||||
with pytest.warns(DeprecationWarning):
|
||||
custom_dataset = dataset_class(
|
||||
ann_file='tests/data/coco/test_coco_wholebody.json',
|
||||
img_prefix='tests/data/coco/',
|
||||
data_cfg=data_cfg,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
assert custom_dataset.test_mode is True
|
||||
assert custom_dataset.dataset_name == 'coco_wholebody'
|
||||
|
||||
image_id = 785
|
||||
assert image_id in custom_dataset.img_ids
|
||||
assert len(custom_dataset.img_ids) == 4
|
||||
_ = custom_dataset[0]
|
||||
|
||||
outputs = convert_db_to_output(custom_dataset.db)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, 'mAP')
|
||||
assert_almost_equal(infos['AP'], 1.0)
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
_ = custom_dataset.evaluate(outputs, tmpdir, 'PCK')
|
||||
|
||||
|
||||
def test_top_down_OCHuman_dataset_compatibility():
|
||||
dataset = 'TopDownOCHumanDataset'
|
||||
# test OCHuman datasets
|
||||
dataset_class = DATASETS.get(dataset)
|
||||
dataset_class.load_annotations = MagicMock()
|
||||
dataset_class.coco = MagicMock()
|
||||
|
||||
channel_cfg = dict(
|
||||
num_output_channels=17,
|
||||
dataset_joints=17,
|
||||
dataset_channel=[
|
||||
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],
|
||||
],
|
||||
inference_channel=[
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
|
||||
])
|
||||
|
||||
data_cfg = dict(
|
||||
image_size=[192, 256],
|
||||
heatmap_size=[48, 64],
|
||||
num_output_channels=channel_cfg['num_output_channels'],
|
||||
num_joints=channel_cfg['dataset_joints'],
|
||||
dataset_channel=channel_cfg['dataset_channel'],
|
||||
inference_channel=channel_cfg['inference_channel'],
|
||||
soft_nms=False,
|
||||
nms_thr=1.0,
|
||||
oks_thr=0.9,
|
||||
vis_thr=0.2,
|
||||
use_gt_bbox=True,
|
||||
det_bbox_thr=0.0,
|
||||
bbox_file='',
|
||||
)
|
||||
|
||||
with pytest.raises(AssertionError):
|
||||
# Test det bbox
|
||||
data_cfg_copy = copy.deepcopy(data_cfg)
|
||||
data_cfg_copy['use_gt_bbox'] = False
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = dataset_class(
|
||||
ann_file='tests/data/ochuman/test_ochuman.json',
|
||||
img_prefix='tests/data/ochuman/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
# Test gt bbox
|
||||
with pytest.warns(DeprecationWarning):
|
||||
custom_dataset = dataset_class(
|
||||
ann_file='tests/data/ochuman/test_ochuman.json',
|
||||
img_prefix='tests/data/ochuman/',
|
||||
data_cfg=data_cfg,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
assert custom_dataset.test_mode is True
|
||||
assert custom_dataset.dataset_name == 'ochuman'
|
||||
|
||||
image_id = 1
|
||||
assert image_id in custom_dataset.img_ids
|
||||
assert len(custom_dataset.img_ids) == 3
|
||||
_ = custom_dataset[0]
|
||||
|
||||
outputs = convert_db_to_output(custom_dataset.db)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, 'mAP')
|
||||
assert_almost_equal(infos['AP'], 1.0)
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
_ = custom_dataset.evaluate(outputs, tmpdir, 'PCK')
|
||||
|
||||
|
||||
def test_top_down_MPII_dataset_compatibility():
|
||||
dataset = 'TopDownMpiiDataset'
|
||||
# test COCO datasets
|
||||
dataset_class = DATASETS.get(dataset)
|
||||
dataset_class.load_annotations = MagicMock()
|
||||
dataset_class.coco = MagicMock()
|
||||
|
||||
channel_cfg = dict(
|
||||
num_output_channels=16,
|
||||
dataset_joints=16,
|
||||
dataset_channel=[
|
||||
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
|
||||
],
|
||||
inference_channel=[
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
|
||||
])
|
||||
|
||||
data_cfg = dict(
|
||||
image_size=[256, 256],
|
||||
heatmap_size=[64, 64],
|
||||
num_output_channels=channel_cfg['num_output_channels'],
|
||||
num_joints=channel_cfg['dataset_joints'],
|
||||
dataset_channel=channel_cfg['dataset_channel'],
|
||||
inference_channel=channel_cfg['inference_channel'],
|
||||
)
|
||||
|
||||
# Test det bbox
|
||||
data_cfg_copy = copy.deepcopy(data_cfg)
|
||||
with pytest.warns(DeprecationWarning):
|
||||
custom_dataset = dataset_class(
|
||||
ann_file='tests/data/mpii/test_mpii.json',
|
||||
img_prefix='tests/data/mpii/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[])
|
||||
|
||||
assert len(custom_dataset) == 5
|
||||
assert custom_dataset.dataset_name == 'mpii'
|
||||
_ = custom_dataset[0]
|
||||
|
||||
|
||||
def test_top_down_MPII_TRB_dataset_compatibility():
|
||||
dataset = 'TopDownMpiiTrbDataset'
|
||||
# test MPII TRB datasets
|
||||
dataset_class = DATASETS.get(dataset)
|
||||
|
||||
channel_cfg = dict(
|
||||
num_output_channels=40,
|
||||
dataset_joints=40,
|
||||
dataset_channel=[list(range(40))],
|
||||
inference_channel=list(range(40)))
|
||||
|
||||
data_cfg = dict(
|
||||
image_size=[256, 256],
|
||||
heatmap_size=[64, 64],
|
||||
num_output_channels=channel_cfg['num_output_channels'],
|
||||
num_joints=channel_cfg['dataset_joints'],
|
||||
dataset_channel=channel_cfg['dataset_channel'],
|
||||
inference_channel=channel_cfg['inference_channel'])
|
||||
|
||||
data_cfg_copy = copy.deepcopy(data_cfg)
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = dataset_class(
|
||||
ann_file='tests/data/mpii/test_mpii_trb.json',
|
||||
img_prefix='tests/data/mpii/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=False)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
custom_dataset = dataset_class(
|
||||
ann_file='tests/data/mpii/test_mpii_trb.json',
|
||||
img_prefix='tests/data/mpii/',
|
||||
data_cfg=data_cfg,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
assert custom_dataset.test_mode is True
|
||||
assert custom_dataset.dataset_name == 'mpii_trb'
|
||||
_ = custom_dataset[0]
|
||||
|
||||
|
||||
def test_top_down_AIC_dataset_compatibility():
|
||||
dataset = 'TopDownAicDataset'
|
||||
# test AIC datasets
|
||||
dataset_class = DATASETS.get(dataset)
|
||||
dataset_class.load_annotations = MagicMock()
|
||||
dataset_class.coco = MagicMock()
|
||||
|
||||
channel_cfg = dict(
|
||||
num_output_channels=14,
|
||||
dataset_joints=14,
|
||||
dataset_channel=[
|
||||
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],
|
||||
],
|
||||
inference_channel=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13])
|
||||
|
||||
data_cfg = dict(
|
||||
image_size=[192, 256],
|
||||
heatmap_size=[48, 64],
|
||||
num_output_channels=channel_cfg['num_output_channels'],
|
||||
num_joints=channel_cfg['dataset_joints'],
|
||||
dataset_channel=channel_cfg['dataset_channel'],
|
||||
inference_channel=channel_cfg['inference_channel'],
|
||||
soft_nms=False,
|
||||
nms_thr=1.0,
|
||||
oks_thr=0.9,
|
||||
vis_thr=0.2,
|
||||
use_gt_bbox=True,
|
||||
det_bbox_thr=0.0,
|
||||
bbox_file='')
|
||||
|
||||
with pytest.raises(AssertionError):
|
||||
# Test det bbox
|
||||
data_cfg_copy = copy.deepcopy(data_cfg)
|
||||
data_cfg_copy['use_gt_bbox'] = False
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = dataset_class(
|
||||
ann_file='tests/data/aic/test_aic.json',
|
||||
img_prefix='tests/data/aic/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = dataset_class(
|
||||
ann_file='tests/data/aic/test_aic.json',
|
||||
img_prefix='tests/data/aic/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=False)
|
||||
|
||||
# Test gt bbox
|
||||
with pytest.warns(DeprecationWarning):
|
||||
custom_dataset = dataset_class(
|
||||
ann_file='tests/data/aic/test_aic.json',
|
||||
img_prefix='tests/data/aic/',
|
||||
data_cfg=data_cfg,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
assert custom_dataset.test_mode is True
|
||||
assert custom_dataset.dataset_name == 'aic'
|
||||
|
||||
image_id = 1
|
||||
assert image_id in custom_dataset.img_ids
|
||||
assert len(custom_dataset.img_ids) == 3
|
||||
_ = custom_dataset[0]
|
||||
|
||||
outputs = convert_db_to_output(custom_dataset.db)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, 'mAP')
|
||||
assert_almost_equal(infos['AP'], 1.0)
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
_ = custom_dataset.evaluate(outputs, tmpdir, 'PCK')
|
||||
|
||||
|
||||
def test_top_down_JHMDB_dataset_compatibility():
|
||||
dataset = 'TopDownJhmdbDataset'
|
||||
# test JHMDB datasets
|
||||
dataset_class = DATASETS.get(dataset)
|
||||
dataset_class.load_annotations = MagicMock()
|
||||
dataset_class.coco = MagicMock()
|
||||
|
||||
channel_cfg = dict(
|
||||
num_output_channels=15,
|
||||
dataset_joints=15,
|
||||
dataset_channel=[
|
||||
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],
|
||||
],
|
||||
inference_channel=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])
|
||||
|
||||
data_cfg = dict(
|
||||
image_size=[192, 256],
|
||||
heatmap_size=[48, 64],
|
||||
num_output_channels=channel_cfg['num_output_channels'],
|
||||
num_joints=channel_cfg['dataset_joints'],
|
||||
dataset_channel=channel_cfg['dataset_channel'],
|
||||
inference_channel=channel_cfg['inference_channel'],
|
||||
soft_nms=False,
|
||||
nms_thr=1.0,
|
||||
oks_thr=0.9,
|
||||
vis_thr=0.2,
|
||||
use_gt_bbox=True,
|
||||
det_bbox_thr=0.0,
|
||||
bbox_file='')
|
||||
|
||||
with pytest.raises(AssertionError):
|
||||
# Test det bbox
|
||||
data_cfg_copy = copy.deepcopy(data_cfg)
|
||||
data_cfg_copy['use_gt_bbox'] = False
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = dataset_class(
|
||||
ann_file='tests/data/jhmdb/test_jhmdb_sub1.json',
|
||||
img_prefix='tests/data/jhmdb/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = dataset_class(
|
||||
ann_file='tests/data/jhmdb/test_jhmdb_sub1.json',
|
||||
img_prefix='tests/data/jhmdb/',
|
||||
data_cfg=data_cfg_copy,
|
||||
pipeline=[],
|
||||
test_mode=False)
|
||||
|
||||
# Test gt bbox
|
||||
with pytest.warns(DeprecationWarning):
|
||||
custom_dataset = dataset_class(
|
||||
ann_file='tests/data/jhmdb/test_jhmdb_sub1.json',
|
||||
img_prefix='tests/data/jhmdb/',
|
||||
data_cfg=data_cfg,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
assert custom_dataset.test_mode is True
|
||||
assert custom_dataset.dataset_name == 'jhmdb'
|
||||
|
||||
image_id = 2290001
|
||||
assert image_id in custom_dataset.img_ids
|
||||
assert len(custom_dataset.img_ids) == 3
|
||||
_ = custom_dataset[0]
|
||||
|
||||
outputs = convert_db_to_output(custom_dataset.db)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, ['PCK'])
|
||||
assert_almost_equal(infos['Mean PCK'], 1.0)
|
||||
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, ['tPCK'])
|
||||
assert_almost_equal(infos['Mean tPCK'], 1.0)
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
_ = custom_dataset.evaluate(outputs, tmpdir, 'mAP')
|
||||
|
||||
|
||||
def test_top_down_h36m_dataset_compatibility():
|
||||
dataset = 'TopDownH36MDataset'
|
||||
# test AIC datasets
|
||||
dataset_class = DATASETS.get(dataset)
|
||||
dataset_class.load_annotations = MagicMock()
|
||||
dataset_class.coco = MagicMock()
|
||||
|
||||
channel_cfg = dict(
|
||||
num_output_channels=17,
|
||||
dataset_joints=17,
|
||||
dataset_channel=[
|
||||
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],
|
||||
],
|
||||
inference_channel=[
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
|
||||
])
|
||||
|
||||
data_cfg = dict(
|
||||
image_size=[256, 256],
|
||||
heatmap_size=[64, 64],
|
||||
num_output_channels=channel_cfg['num_output_channels'],
|
||||
num_joints=channel_cfg['dataset_joints'],
|
||||
dataset_channel=channel_cfg['dataset_channel'],
|
||||
inference_channel=channel_cfg['inference_channel'])
|
||||
|
||||
# Test gt bbox
|
||||
with pytest.warns(DeprecationWarning):
|
||||
custom_dataset = dataset_class(
|
||||
ann_file='tests/data/h36m/h36m_coco.json',
|
||||
img_prefix='tests/data/h36m/',
|
||||
data_cfg=data_cfg,
|
||||
pipeline=[],
|
||||
test_mode=True)
|
||||
|
||||
assert custom_dataset.test_mode is True
|
||||
assert custom_dataset.dataset_name == 'h36m'
|
||||
|
||||
image_id = 1
|
||||
assert image_id in custom_dataset.img_ids
|
||||
_ = custom_dataset[0]
|
||||
|
||||
outputs = convert_db_to_output(custom_dataset.db)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
infos = custom_dataset.evaluate(outputs, tmpdir, 'EPE')
|
||||
assert_almost_equal(infos['EPE'], 0.0)
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
_ = custom_dataset.evaluate(outputs, tmpdir, 'AUC')
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
# Copyright (c) OpenMMLab. All rights reserved.
|
||||
import unittest.mock as mock
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
from torch.utils.data import DataLoader, Dataset
|
||||
|
||||
from mmpose.core import DistEvalHook, EvalHook
|
||||
|
||||
|
||||
class ExampleDataset(Dataset):
|
||||
|
||||
def __init__(self):
|
||||
self.index = 0
|
||||
self.eval_result = [0.1, 0.4, 0.3, 0.7, 0.2, 0.05, 0.4, 0.6]
|
||||
|
||||
def __getitem__(self, idx):
|
||||
results = dict(imgs=torch.tensor([1]))
|
||||
return results
|
||||
|
||||
def __len__(self):
|
||||
return 1
|
||||
|
||||
@mock.create_autospec
|
||||
def evaluate(self, results, res_folder=None, logger=None):
|
||||
pass
|
||||
|
||||
|
||||
def test_old_fashion_eval_hook_parameters():
|
||||
|
||||
data_loader = DataLoader(
|
||||
ExampleDataset(),
|
||||
batch_size=1,
|
||||
sampler=None,
|
||||
num_workers=0,
|
||||
shuffle=False)
|
||||
|
||||
# test argument "key_indicator"
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = EvalHook(data_loader, key_indicator='AP')
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = DistEvalHook(data_loader, key_indicator='AP')
|
||||
|
||||
# test argument "gpu_collect"
|
||||
with pytest.warns(DeprecationWarning):
|
||||
_ = EvalHook(data_loader, save_best='AP', gpu_collect=False)
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
# Copyright (c) OpenMMLab. All rights reserved.
|
||||
# flake8: noqa
|
||||
import pytest
|
||||
|
||||
|
||||
def test_old_fashion_registry_importing():
|
||||
with pytest.warns(DeprecationWarning):
|
||||
from mmpose.models.registry import BACKBONES, HEADS, LOSSES, NECKS, POSENETS # isort: skip
|
||||
with pytest.warns(DeprecationWarning):
|
||||
from mmpose.datasets.registry import DATASETS, PIPELINES # noqa: F401
|
||||
Reference in New Issue
Block a user