Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Support ViTPose #1937

Merged
merged 18 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
change the resize_upsample4 to upsample
  • Loading branch information
Annbless committed Jan 17, 2023
commit dde90047398121d0fb831552f8ed8a6744c4efd9
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,10 @@
keypoint_head=dict(
type='TopdownHeatmapSimpleHead',
in_channels=768,
input_transform='resize_upsample4',
num_deconv_layers=0,
num_deconv_filters=[],
num_deconv_kernels=[],
extra=dict(final_conv_kernel=3, ),
num_deconv_layers=2,
num_deconv_filters=(256, 256),
num_deconv_kernels=(4, 4),
extra=dict(final_conv_kernel=1, ),
out_channels=channel_cfg['num_output_channels'],
loss_keypoint=dict(type='JointsMSELoss', use_target_weight=True)),
train_cfg=dict(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@
keypoint_head=dict(
type='TopdownHeatmapSimpleHead',
in_channels=768,
num_deconv_layers=2,
num_deconv_filters=(256, 256),
num_deconv_kernels=(4, 4),
extra=dict(final_conv_kernel=1, ),
upsample=4,
num_deconv_layers=0,
num_deconv_filters=[],
num_deconv_kernels=[],
extra=dict(final_conv_kernel=3, ),
out_channels=channel_cfg['num_output_channels'],
loss_keypoint=dict(type='JointsMSELoss', use_target_weight=True)),
train_cfg=dict(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
keypoint_head=dict(
type='TopdownHeatmapSimpleHead',
in_channels=1280,
input_transform='resize_upsample4',
upsample=4,
num_deconv_layers=0,
num_deconv_filters=[],
num_deconv_kernels=[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
keypoint_head=dict(
type='TopdownHeatmapSimpleHead',
in_channels=1024,
input_transform='resize_upsample4',
upsample=4,
num_deconv_layers=0,
num_deconv_filters=[],
num_deconv_kernels=[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
keypoint_head=dict(
type='TopdownHeatmapSimpleHead',
in_channels=384,
input_transform='resize_upsample4',
upsample=4,
num_deconv_layers=0,
num_deconv_filters=[],
num_deconv_kernels=[],
Expand Down
14 changes: 9 additions & 5 deletions mmpose/models/heads/topdown_heatmap_simple_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class TopdownHeatmapSimpleHead(TopdownHeatmapBaseHead):
If num_deconv_layers > 0, the length of
num_deconv_kernels (list|tuple): Kernel sizes.
in_index (int|Sequence[int]): Input feature index. Default: 0
upsample (int): Directly upsample ratio of input features. Default: 0
input_transform (str|None): Transformation type of input features.
Options: 'resize_concat', 'multiple_select', None.
Default: None.
Expand All @@ -53,6 +54,7 @@ def __init__(self,
num_deconv_kernels=(4, 4, 4),
extra=None,
in_index=0,
upsample=0,
input_transform=None,
align_corners=False,
loss_keypoint=None,
Expand All @@ -71,6 +73,10 @@ def __init__(self,
self.in_index = in_index
self.align_corners = align_corners

self.upsample = upsample
if self.upsample > 0:
assert isinstance(in_index, int)

if extra is not None and not isinstance(extra, dict):
raise TypeError('extra should be dict or None.')

Expand Down Expand Up @@ -247,9 +253,7 @@ def _init_inputs(self, in_channels, in_index, input_transform):
"""

if input_transform is not None:
assert input_transform in [
'resize_concat', 'multiple_select', 'resize_upsample4'
]
assert input_transform in ['resize_concat', 'multiple_select']
self.input_transform = input_transform
self.in_index = in_index
if input_transform is not None:
Expand All @@ -275,10 +279,10 @@ def _transform_inputs(self, inputs):
Tensor: The transformed inputs
"""
if not isinstance(inputs, list):
if self.input_transform == 'resize_upsample4':
if self.upsample > 0:
inputs = resize(
input=torch.nn.functional.relu(inputs),
scale_factor=4,
scale_factor=self.upsample,
mode='bilinear',
align_corners=self.align_corners)
return inputs
Expand Down
2 changes: 1 addition & 1 deletion tests/test_models/test_top_down_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def test_top_down_simple_head():
out_channels=3,
in_channels=512,
num_deconv_layers=0,
input_transform='resize_upsample4',
upsample=4,
loss_keypoint=dict(type='JointsMSELoss', use_target_weight=True))
input_shape = (1, 512, 32, 32)
inputs = _demo_inputs(input_shape)
Expand Down