Skip to content

Commit d5e1c7c

Browse files
committed
add yolox-s-pose
1 parent 2016609 commit d5e1c7c

File tree

12 files changed

+1231
-0
lines changed

12 files changed

+1231
-0
lines changed

projects/yolox-pose/README.md

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# YOLOX-Pose
2+
3+
> A README.md template for releasing a project.
4+
>
5+
> All the fields in this README are **mandatory** for others to understand what you have achieved in this implementation.
6+
> Please read our [Projects FAQ](../faq.md) if you still feel unclear about the requirements, or raise an [issue](https://github.com/open-mmlab/mmpose/issues) to us!
7+
8+
## Description
9+
10+
This project implements a top-down pose estimator with custom head and loss functions that have been seamlessly inherited from existing modules within MMPose.
11+
12+
## Usage
13+
14+
> For a typical model, this section should contain the commands for training and testing.
15+
> You are also suggested to dump your environment specification to env.yml by `conda env export > env.yml`.
16+
17+
### Prerequisites
18+
19+
- Python 3.7
20+
- PyTorch 1.6 or higher
21+
- [MIM](https://github.com/open-mmlab/mim) v0.33 or higher
22+
- [MMDetection](https://github.com/open-mmlab/mmdetection) v3.0.0rc5 or higher
23+
- [MMYOLO](https://github.com/open-mmlab/mmdetection) v3.0.0rc5 or higher
24+
- [MMPose](https://github.com/open-mmlab/mmpose) v1.0.0rc0 or higher
25+
26+
All the commands below rely on the correct configuration of `PYTHONPATH`, which should point to the project's directory so that Python can locate the module files. In `example_project/` root directory, run the following line to add the current directory to `PYTHONPATH`:
27+
28+
```shell
29+
export PYTHONPATH=`pwd`:$PYTHONPATH
30+
```
31+
32+
### Data Preparation
33+
34+
Prepare the COCO dataset according to the [instruction](https://mmpose.readthedocs.io/en/1.x/dataset_zoo/2d_body_keypoint.html#coco).
35+
36+
### Training commands
37+
38+
**To train with single GPU:**
39+
40+
```shell
41+
mim train mmpose configs/example-head-loss_hrnet-w32_8xb64-210e_coco-256x192.py
42+
```
43+
44+
**To train with multiple GPUs:**
45+
46+
```shell
47+
mim train mmpose configs/example-head-loss_hrnet-w32_8xb64-210e_coco-256x192.py --launcher pytorch --gpus 8
48+
```
49+
50+
**To train with multiple GPUs by slurm:**
51+
52+
```shell
53+
mim train mmpose configs/example-head-loss_hrnet-w32_8xb64-210e_coco-256x192.py --launcher slurm \
54+
--gpus 16 --gpus-per-node 8 --partition $PARTITION
55+
```
56+
57+
### Testing commands
58+
59+
**To test with single GPU:**
60+
61+
```shell
62+
mim test mmpose configs/example-head-loss_hrnet-w32_8xb64-210e_coco-256x192.py $CHECKPOINT
63+
```
64+
65+
**To test with multiple GPUs:**
66+
67+
```shell
68+
mim test mmpose configs/example-head-loss_hrnet-w32_8xb64-210e_coco-256x192.py $CHECKPOINT --launcher pytorch --gpus 8
69+
```
70+
71+
**To test with multiple GPUs by slurm:**
72+
73+
```shell
74+
mim test mmpose configs/example-head-loss_hrnet-w32_8xb64-210e_coco-256x192.py $CHECKPOINT --launcher slurm \
75+
--gpus 16 --gpus-per-node 8 --partition $PARTITION
76+
```
77+
78+
## Results
79+
80+
> List the results as usually done in other model's README. Here is an [Example](https://github.com/open-mmlab/mmpose/blob/dev-1.x/configs/body_2d_keypoint/topdown_heatmap/coco/hrnet_coco.md).
81+
82+
> You should claim whether this is based on the pre-trained weights, which are converted from the official release; or it's a reproduced result obtained from retraining the model in this project
83+
84+
| Model | Backbone | Input Size | AP | AP<sup>50</sup> | AP<sup>75</sup> | AR | AR<sup>50</sup> | Download |
85+
| :-----------------------------------------------------------: | :-------: | :--------: | :---: | :-------------: | :-------------: | :---: | :-------------: | :---------------------------------------------------------------: |
86+
| [ExampleHead + ExampleLoss](./configs/example-head-loss_hrnet-w32_8xb64-210e_coco-256x192.py) | HRNet-w32 | 256x912 | 0.749 | 0.906 | 0.821 | 0.804 | 0.945 | [model](https://download.openmmlab.com/mmpose/v1/body_2d_keypoint/topdown_heatmap/coco/td-hm_hrnet-w32_8xb64-210e_coco-256x192-81c58e40_20220909.pth) \| [log](https://download.openmmlab.com/mmpose/v1/body_2d_keypoint/topdown_heatmap/coco/td-hm_hrnet-w32_8xb64-210e_coco-256x192_20220909.log) |
87+
88+
## Citation
89+
90+
> You may remove this section if not applicable.
91+
92+
```bibtex
93+
@misc{mmpose2020,
94+
title={OpenMMLab Pose Estimation Toolbox and Benchmark},
95+
author={MMPose Contributors},
96+
howpublished = {\url{https://github.com/open-mmlab/mmpose}},
97+
year={2020}
98+
}
99+
```
100+
101+
## Checklist
102+
103+
Here is a checklist of this project's progress. And you can ignore this part if you don't plan to contribute
104+
to MMPose projects.
105+
106+
> The PIC (person in charge) or contributors of this project should check all the items that they believe have been finished, which will further be verified by codebase maintainers via a PR.
107+
108+
> OpenMMLab's maintainer will review the code to ensure the project's quality. Reaching the first milestone means that this project suffices the minimum requirement of being merged into 'projects/'. But this project is only eligible to become a part of the core package upon attaining the last milestone.
109+
110+
> Note that keeping this section up-to-date is crucial not only for this project's developers but the entire community, since there might be some other contributors joining this project and deciding their starting point from this list. It also helps maintainers accurately estimate time and effort on further code polishing, if needed.
111+
112+
> A project does not necessarily have to be finished in a single PR, but it's essential for the project to at least reach the first milestone in its very first PR.
113+
114+
- [ ] Milestone 1: PR-ready, and acceptable to be one of the `projects/`.
115+
116+
- [ ] Finish the code
117+
118+
> The code's design shall follow existing interfaces and convention. For example, each model component should be registered into `mmpose.registry.MODELS` and configurable via a config file.
119+
120+
- [ ] Basic docstrings & proper citation
121+
122+
> Each major class should contains a docstring, describing its functionality and arguments. If your code is copied or modified from other open-source projects, don't forget to cite the source project in docstring and make sure your behavior is not against its license. Typically, we do not accept any code snippet under GPL license. [A Short Guide to Open Source Licenses](https://medium.com/nationwide-technology/a-short-guide-to-open-source-licenses-cf5b1c329edd)
123+
124+
- [ ] Test-time correctness
125+
126+
> If you are reproducing the result from a paper, make sure your model's inference-time performance matches that in the original paper. The weights usually could be obtained by simply renaming the keys in the official pre-trained weights. This test could be skipped though, if you are able to prove the training-time correctness and check the second milestone.
127+
128+
- [ ] A full README
129+
130+
> As this template does.
131+
132+
- [ ] Milestone 2: Indicates a successful model implementation.
133+
134+
- [ ] Training-time correctness
135+
136+
> If you are reproducing the result from a paper, checking this item means that you should have trained your model from scratch based on the original paper's specification and verified that the final result matches the report within a minor error range.
137+
138+
- [ ] Milestone 3: Good to be a part of our core package!
139+
140+
- [ ] Type hints and docstrings
141+
142+
> Ideally *all* the methods should have [type hints](https://www.pythontutorial.net/python-basics/python-type-hints/) and [docstrings](https://google.github.io/styleguide/pyguide.html#381-docstrings). [Example](https://github.com/open-mmlab/mmpose/blob/0fb7f22000197181dc0629f767dd99d881d23d76/mmpose/utils/tensor_utils.py#L53)
143+
144+
- [ ] Unit tests
145+
146+
> Unit tests for the major module are required. [Example](https://github.com/open-mmlab/mmpose/blob/1.x/tests/test_models/test_heads/test_heatmap_heads/test_heatmap_head.py)
147+
148+
- [ ] Code polishing
149+
150+
> Refactor your code according to reviewer's comment.
151+
152+
- [ ] Metafile.yml
153+
154+
> It will be parsed by MIM and Inferencer. [Example](https://github.com/open-mmlab/mmpose/blob/dev-1.x/configs/body_2d_keypoint/topdown_heatmap/coco/hrnet_coco.yml)
155+
156+
- [ ] Move your modules into the core package following the codebase's file hierarchy structure.
157+
158+
> In particular, you may have to refactor this README into a standard one. [Example](https://github.com/open-mmlab/mmpose/blob/dev-1.x/configs/body_2d_keypoint/topdown_heatmap/README.md)
159+
160+
- [ ] Refactor your modules into the core package following the codebase's file hierarchy structure.

projects/yolox-pose/configs/_base_

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../configs/_base_
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Directly inherit the entire recipe you want to use.
2+
_base_ = 'mmyolo::yolox/yolox_s_fast_8xb8-300e_coco.py'
3+
4+
# This line is to import your own modules.
5+
custom_imports = dict(imports=['models', 'datasets'])
6+
7+
# Modify the model to use your own head and loss.
8+
model = dict(
9+
init_cfg=dict(
10+
_delete_=True,
11+
type='Pretrained',
12+
checkpoint='https://download.openmmlab.com/mmyolo/'
13+
'v0/yolox/yolox_s_8xb8-300e_coco/'
14+
'yolox_s_8xb8-300e_coco_20220917_030738-d7e60cb2.pth'),
15+
data_preprocessor=dict(
16+
type='mmdet.DetDataPreprocessor',
17+
batch_augments=[
18+
dict(
19+
type='PoseBatchSyncRandomResize',
20+
random_size_range=(480, 800),
21+
size_divisor=32,
22+
interval=10)
23+
]),
24+
bbox_head=dict(
25+
type='YOLOXPoseHead',
26+
head_module=dict(
27+
type='YOLOXPoseHeadModule',
28+
num_classes=1,
29+
num_keypoints=17,
30+
),
31+
loss_pose=dict(
32+
type='OksLoss',
33+
metainfo='configs/_base_/datasets/coco.py',
34+
loss_weight=50),
35+
),
36+
test_cfg=dict(multi_label=False))
37+
38+
pre_transform = [
39+
dict(type='LoadImageFromFile', file_client_args=_base_.file_client_args),
40+
dict(type='PoseToDetConverter')
41+
]
42+
43+
train_pipeline_stage1 = [
44+
*pre_transform, *_base_.train_pipeline_stage1[2:-2],
45+
dict(type='FilterDetPoseAnnotations', keep_empty=False),
46+
dict(
47+
type='PackDetPoseInputs',
48+
meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape'))
49+
]
50+
51+
for transform in train_pipeline_stage1:
52+
if 'pre_transform' in transform:
53+
transform['pre_transform'] = pre_transform
54+
55+
train_pipeline_stage2 = [
56+
*pre_transform, *_base_.train_pipeline_stage2[2:-2],
57+
dict(type='FilterDetPoseAnnotations', keep_empty=False),
58+
dict(type='PackDetPoseInputs')
59+
]
60+
61+
test_pipeline = [
62+
*pre_transform, *_base_.test_pipeline[1:-2],
63+
dict(
64+
type='PackDetPoseInputs',
65+
meta_keys=('id', 'img_id', 'img_path', 'ori_shape', 'img_shape',
66+
'scale_factor', 'flip_indices'))
67+
]
68+
69+
# base dataset settings
70+
dataset_type = 'CocoDataset'
71+
data_mode = 'bottomup'
72+
data_root = 'data/coco/'
73+
74+
train_dataloader = dict(
75+
dataset=dict(
76+
type=dataset_type,
77+
data_root=data_root,
78+
data_mode=data_mode,
79+
ann_file='annotations/person_keypoints_train2017.json',
80+
pipeline=train_pipeline_stage1))
81+
_base_.train_dataloader.pop('collate_fn')
82+
83+
val_dataloader = dict(
84+
dataset=dict(
85+
type=dataset_type,
86+
data_root=data_root,
87+
data_mode=data_mode,
88+
test_mode=True,
89+
ann_file='annotations/person_keypoints_val2017.json',
90+
pipeline=test_pipeline))
91+
test_dataloader = val_dataloader
92+
93+
# evaluators
94+
val_evaluator = dict(
95+
_delete_=True,
96+
type='mmpose.CocoMetric',
97+
ann_file=data_root + 'annotations/person_keypoints_val2017.json',
98+
nms_mode='none',
99+
# score_mode='keypoint',
100+
)
101+
test_evaluator = val_evaluator
102+
103+
# hooks
104+
default_hooks = dict(checkpoint=dict(save_best='coco/AP', rule='greater'))
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .bbox_keypoint_structure import * # noqa
2+
from .coco_dataset import * # noqa
3+
from .transforms import * # noqa

0 commit comments

Comments
 (0)