Skip to content

Commit

Permalink
Add lite hr net (PaddlePaddle#3793)
Browse files Browse the repository at this point in the history
* add LiteHRNet backbone and config .YML

* test lite18-network param

acc is same with ori-model 1. fix default darkpose=ON, 2. += is not inplace

add new keypoint model Lite-HRNet

* add new keypoint model Lite-HRNet

* 1. Add description of network type; 2. use channel_shuffle in ops.py

* use normal to init conv2d

* add network type description
  • Loading branch information
zoooo0820 authored Aug 4, 2021
1 parent 55fcc1f commit d578628
Show file tree
Hide file tree
Showing 8 changed files with 1,191 additions and 24 deletions.
140 changes: 140 additions & 0 deletions configs/keypoint/lite_hrnet/lite_hrnet_18_256x192_coco.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
use_gpu: true
log_iter: 5
save_dir: output
snapshot_epoch: 10
weights: output/lite_hrnet_18_256x192_coco/model_final
epoch: 210
num_joints: &num_joints 17
pixel_std: &pixel_std 200
metric: KeyPointTopDownCOCOEval
num_classes: 1
train_height: &train_height 256
train_width: &train_width 192
trainsize: &trainsize [*train_width, *train_height]
hmsize: &hmsize [48, 64]
flip_perm: &flip_perm [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16]]


#####model
architecture: TopDownHRNet

TopDownHRNet:
backbone: LiteHRNet
post_process: HRNetPostProcess
flip_perm: *flip_perm
num_joints: *num_joints
width: &width 40
loss: KeyPointMSELoss
use_dark: false

LiteHRNet:
network_type: lite_18
freeze_at: -1
freeze_norm: false
return_idx: [0]

KeyPointMSELoss:
use_target_weight: true
loss_scale: 1.0

#####optimizer
LearningRate:
base_lr: 0.002
schedulers:
- !PiecewiseDecay
milestones: [170, 200]
gamma: 0.1
- !LinearWarmup
start_factor: 0.001
steps: 500

OptimizerBuilder:
optimizer:
type: Adam
regularizer:
factor: 0.0
type: L2


#####data
TrainDataset:
!KeypointTopDownCocoDataset
image_dir: train2017
anno_path: annotations/person_keypoints_train2017.json
dataset_dir: dataset/coco
num_joints: *num_joints
trainsize: *trainsize
pixel_std: *pixel_std
use_gt_bbox: True


EvalDataset:
!KeypointTopDownCocoDataset
image_dir: val2017
anno_path: annotations/person_keypoints_val2017.json
dataset_dir: dataset/coco
num_joints: *num_joints
trainsize: *trainsize
pixel_std: *pixel_std
use_gt_bbox: True
image_thre: 0.0


TestDataset:
!ImageFolder
anno_path: dataset/coco/keypoint_imagelist.txt

worker_num: 2
global_mean: &global_mean [0.485, 0.456, 0.406]
global_std: &global_std [0.229, 0.224, 0.225]
TrainReader:
sample_transforms:
- RandomFlipHalfBodyTransform:
scale: 0.25
rot: 30
num_joints_half_body: 8
prob_half_body: 0.3
pixel_std: *pixel_std
trainsize: *trainsize
upper_body_ids: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
flip_pairs: *flip_perm
- TopDownAffine:
trainsize: *trainsize
- ToHeatmapsTopDown:
hmsize: *hmsize
sigma: 2
batch_transforms:
- NormalizeImage:
mean: *global_mean
std: *global_std
is_scale: true
- Permute: {}
batch_size: 64
shuffle: true
drop_last: false

EvalReader:
sample_transforms:
- TopDownAffine:
trainsize: *trainsize
batch_transforms:
- NormalizeImage:
mean: *global_mean
std: *global_std
is_scale: true
- Permute: {}
batch_size: 16

TestReader:
inputs_def:
image_shape: [3, *train_height, *train_width]
sample_transforms:
- Decode: {}
- TopDownEvalAffine:
trainsize: *trainsize
- NormalizeImage:
mean: *global_mean
std: *global_std
is_scale: true
- Permute: {}
batch_size: 1
140 changes: 140 additions & 0 deletions configs/keypoint/lite_hrnet/lite_hrnet_30_256x192_coco.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
use_gpu: true
log_iter: 5
save_dir: output
snapshot_epoch: 10
weights: output/lite_hrnet_30_256x192_coco/model_final
epoch: 210
num_joints: &num_joints 17
pixel_std: &pixel_std 200
metric: KeyPointTopDownCOCOEval
num_classes: 1
train_height: &train_height 256
train_width: &train_width 192
trainsize: &trainsize [*train_width, *train_height]
hmsize: &hmsize [48, 64]
flip_perm: &flip_perm [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16]]


#####model
architecture: TopDownHRNet

TopDownHRNet:
backbone: LiteHRNet
post_process: HRNetPostProcess
flip_perm: *flip_perm
num_joints: *num_joints
width: &width 40
loss: KeyPointMSELoss
use_dark: false

LiteHRNet:
network_type: lite_30
freeze_at: -1
freeze_norm: false
return_idx: [0]

KeyPointMSELoss:
use_target_weight: true
loss_scale: 1.0

#####optimizer
LearningRate:
base_lr: 0.002
schedulers:
- !PiecewiseDecay
milestones: [170, 200]
gamma: 0.1
- !LinearWarmup
start_factor: 0.001
steps: 500

OptimizerBuilder:
optimizer:
type: Adam
regularizer:
factor: 0.0
type: L2


#####data
TrainDataset:
!KeypointTopDownCocoDataset
image_dir: train2017
anno_path: annotations/person_keypoints_train2017.json
dataset_dir: dataset/coco
num_joints: *num_joints
trainsize: *trainsize
pixel_std: *pixel_std
use_gt_bbox: True


EvalDataset:
!KeypointTopDownCocoDataset
image_dir: val2017
anno_path: annotations/person_keypoints_val2017.json
dataset_dir: dataset/coco
num_joints: *num_joints
trainsize: *trainsize
pixel_std: *pixel_std
use_gt_bbox: True
image_thre: 0.0


TestDataset:
!ImageFolder
anno_path: dataset/coco/keypoint_imagelist.txt

worker_num: 4
global_mean: &global_mean [0.485, 0.456, 0.406]
global_std: &global_std [0.229, 0.224, 0.225]
TrainReader:
sample_transforms:
- RandomFlipHalfBodyTransform:
scale: 0.25
rot: 30
num_joints_half_body: 8
prob_half_body: 0.3
pixel_std: *pixel_std
trainsize: *trainsize
upper_body_ids: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
flip_pairs: *flip_perm
- TopDownAffine:
trainsize: *trainsize
- ToHeatmapsTopDown:
hmsize: *hmsize
sigma: 2
batch_transforms:
- NormalizeImage:
mean: *global_mean
std: *global_std
is_scale: true
- Permute: {}
batch_size: 64
shuffle: true
drop_last: false

EvalReader:
sample_transforms:
- TopDownAffine:
trainsize: *trainsize
batch_transforms:
- NormalizeImage:
mean: *global_mean
std: *global_std
is_scale: true
- Permute: {}
batch_size: 16

TestReader:
inputs_def:
image_shape: [3, *train_height, *train_width]
sample_transforms:
- Decode: {}
- TopDownEvalAffine:
trainsize: *trainsize
- NormalizeImage:
mean: *global_mean
std: *global_std
is_scale: true
- Permute: {}
batch_size: 1
9 changes: 5 additions & 4 deletions ppdet/modeling/architectures/keypoint_hrnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,20 @@ def __init__(self,
post_process='HRNetPostProcess',
flip_perm=None,
flip=True,
shift_heatmap=True):
shift_heatmap=True,
use_dark=True):
"""
HRNnet network, see https://arxiv.org/abs/1902.09212
HRNet network, see https://arxiv.org/abs/1902.09212
Args:
backbone (nn.Layer): backbone instance
post_process (object): `HRNetPostProcess` instance
flip_perm (list): The left-right joints exchange order list
use_dark(bool): Whether to use DARK in post processing
"""
super(TopDownHRNet, self).__init__()
self.backbone = backbone
self.post_process = HRNetPostProcess()
self.post_process = HRNetPostProcess(use_dark)
self.loss = loss
self.flip_perm = flip_perm
self.flip = flip
Expand Down Expand Up @@ -218,7 +220,6 @@ def get_final_preds(self, heatmaps, center, scale, kernelsize=3):
preds: numpy.ndarray([batch_size, num_joints, 2]), keypoints coords
maxvals: numpy.ndarray([batch_size, num_joints, 1]), the maximum confidence of the keypoints
"""

coords, maxvals = self.get_max_preds(heatmaps)

heatmap_height = heatmaps.shape[2]
Expand Down
2 changes: 2 additions & 0 deletions ppdet/modeling/backbones/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from . import mobilenet_v1
from . import mobilenet_v3
from . import hrnet
from . import lite_hrnet
from . import blazenet
from . import ghostnet
from . import senet
Expand All @@ -31,6 +32,7 @@
from .mobilenet_v1 import *
from .mobilenet_v3 import *
from .hrnet import *
from .lite_hrnet import *
from .blazenet import *
from .ghostnet import *
from .senet import *
Expand Down
Loading

0 comments on commit d578628

Please sign in to comment.