Skip to content

Commit

Permalink
No-self-use. (open-mmlab#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
yaochaorui authored Nov 12, 2020
1 parent b0fe89a commit 4e612eb
Show file tree
Hide file tree
Showing 20 changed files with 55 additions and 30 deletions.
6 changes: 4 additions & 2 deletions mmpose/core/fp16/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,17 @@ def before_run(self, runner):
# convert model to fp16
wrap_fp16_model(runner.model)

def copy_grads_to_fp32(self, fp16_net, fp32_weights):
@staticmethod
def copy_grads_to_fp32(fp16_net, fp32_weights):
"""Copy gradients from fp16 model to fp32 weight copy."""
for fp32_param, fp16_param in zip(fp32_weights, fp16_net.parameters()):
if fp16_param.grad is not None:
if fp32_param.grad is None:
fp32_param.grad = fp32_param.data.new(fp32_param.size())
fp32_param.grad.copy_(fp16_param.grad)

def copy_params_to_fp16(self, fp16_net, fp32_weights):
@staticmethod
def copy_params_to_fp16(fp16_net, fp32_weights):
"""Copy updated params from fp32 weight copy to fp16 model."""
for fp16_param, fp32_param in zip(fp16_net.parameters(), fp32_weights):
fp16_param.data.copy_(fp32_param.data)
Expand Down
6 changes: 4 additions & 2 deletions mmpose/core/post_processing/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ def top_k(self, heatmaps, tags):

return ans

def adjust(self, ans, heatmaps):
@staticmethod
def adjust(ans, heatmaps):
"""Adjust the coordinates for better accuracy.
Note:
Expand Down Expand Up @@ -271,7 +272,8 @@ def adjust(self, ans, heatmaps):
0:2] = (x + 0.5, y + 0.5)
return ans

def refine(self, heatmap, tag, keypoints):
@staticmethod
def refine(heatmap, tag, keypoints):
"""Given initial keypoint predictions, we identify missing joints.
Note:
Expand Down
3 changes: 2 additions & 1 deletion mmpose/datasets/datasets/bottom_up/bottom_up_coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ def __init__(self,

print(f'=> num_images: {self.num_images}')

def _get_mapping_id_name(self, imgs):
@staticmethod
def _get_mapping_id_name(imgs):
"""
Args:
imgs (dict): dict of image info.
Expand Down
6 changes: 4 additions & 2 deletions mmpose/datasets/datasets/hand/hand_base_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def __init__(self,

self.pipeline = Compose(self.pipeline)

def _get_mapping_id_name(self, imgs):
@staticmethod
def _get_mapping_id_name(imgs):
"""
Args:
imgs (dict): dict of image info.
Expand Down Expand Up @@ -121,7 +122,8 @@ def evaluate(self, cfg, preds, output_dir, *args, **kwargs):
"""Evaluate keypoint results."""
raise NotImplementedError

def _write_keypoint_results(self, keypoints, res_file):
@staticmethod
def _write_keypoint_results(keypoints, res_file):
"""Write results into a json file."""

with open(res_file, 'w') as f:
Expand Down
6 changes: 4 additions & 2 deletions mmpose/datasets/datasets/hand/interhand2d_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ def __init__(self,
print(f'=> num_images: {self.num_images}')
print(f'=> load {len(self.db)} samples')

def _cam2pixel(self, cam_coord, f, c):
@staticmethod
def _cam2pixel(cam_coord, f, c):
"""Transform the joints from their camera coordinates to their pixel
coordinates.
Expand All @@ -101,7 +102,8 @@ def _cam2pixel(self, cam_coord, f, c):
img_coord = np.concatenate((x[:, None], y[:, None], z[:, None]), 1)
return img_coord

def _world2cam(self, world_coord, R, T):
@staticmethod
def _world2cam(world_coord, R, T):
"""Transform the joints from their world coordinates to their camera
coordinates.
Expand Down
6 changes: 4 additions & 2 deletions mmpose/datasets/datasets/mesh/mesh_h36m_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def evaluate(self, outputs, res_folder, metric='joint_error', logger=None):
name_value = OrderedDict(info_str)
return name_value

def _write_keypoint_results(self, keypoints, res_file):
@staticmethod
def _write_keypoint_results(keypoints, res_file):
"""Write results into a json file."""

with open(res_file, 'w') as f:
Expand Down Expand Up @@ -87,7 +88,8 @@ def _report_metric(self, res_file):
info_str.append(('MPJPE-PA', mpjpe_pa * 1000))
return info_str

def evaluate_kernel(self, pred_joints_3d, joints_3d, joints_3d_visible):
@staticmethod
def evaluate_kernel(pred_joints_3d, joints_3d, joints_3d_visible):
"""Evaluate one example."""
# Only 14 lsp joints are used for evaluation
joint_mapper = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 18]
Expand Down
3 changes: 2 additions & 1 deletion mmpose/datasets/datasets/mesh/mosh_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def __init__(self, ann_file, pipeline, test_mode=False):
self.db = self._get_db(ann_file)
self.pipeline = Compose(self.pipeline)

def _get_db(self, ann_file):
@staticmethod
def _get_db(ann_file):
"""Load dataset."""
data = np.load(ann_file)
_betas = data['shape'].astype(np.float32)
Expand Down
3 changes: 2 additions & 1 deletion mmpose/datasets/datasets/top_down/topdown_coco_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ def __init__(self,
print(f'=> num_images: {self.num_images}')
print(f'=> load {len(self.db)} samples')

def _get_mapping_id_name(self, imgs):
@staticmethod
def _get_mapping_id_name(imgs):
"""
Args:
imgs (dict): dict of image info.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ def __init__(self,
print(f'=> num_images: {self.num_images}')
print(f'=> load {len(self.db)} samples')

def _make_flip_pairs(self):
@staticmethod
def _make_flip_pairs():
body = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14],
[15, 16]]
foot = [[17, 20], [18, 21], [19, 22]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ def evaluate(self, outputs, res_folder, metric='PCKh', **kwargs):

return name_value

def _write_keypoint_results(self, keypoints, res_file):
@staticmethod
def _write_keypoint_results(keypoints, res_file):
"""Write results into a json file."""

with open(res_file, 'w') as f:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ def evaluate(self, outputs, res_folder, metric='mAP', **kwargs):

return name_value

def _write_posetrack18_keypoint_results(self, keypoint_results, gt_folder,
@staticmethod
def _write_posetrack18_keypoint_results(keypoint_results, gt_folder,
pred_folder):
"""Write results into a json file.
Expand Down
6 changes: 4 additions & 2 deletions mmpose/datasets/pipelines/bottom_up_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ def __init__(self, rot_factor, scale_factor, scale_type, trans_factor):
self.scale_type = scale_type
self.trans_factor = trans_factor

def _get_affine_matrix(self, center, scale, res, rot=0):
@staticmethod
def _get_affine_matrix(center, scale, res, rot=0):
"""Generate transformation matrix."""
h = scale
t = np.zeros((3, 3), dtype=np.float32)
Expand All @@ -255,7 +256,8 @@ def _get_affine_matrix(self, center, scale, res, rot=0):
t = np.dot(t_inv, np.dot(rot_mat, np.dot(t_mat, t)))
return t

def _affine_joints(self, joints, mat):
@staticmethod
def _affine_joints(joints, mat):
"""Affine the joints by the transform matrix."""
joints = np.array(joints)
shape = joints.shape
Expand Down
4 changes: 2 additions & 2 deletions mmpose/models/backbones/hrnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def __init__(self,
self.fuse_layers = self._make_fuse_layers()
self.relu = nn.ReLU(inplace=True)

def _check_branches(self, num_branches, num_blocks, in_channels,
num_channels):
@staticmethod
def _check_branches(num_branches, num_blocks, in_channels, num_channels):
"""Check input to avoid ValueError."""
if num_branches != len(num_blocks):
error_msg = f'NUM_BRANCHES({num_branches}) ' \
Expand Down
4 changes: 2 additions & 2 deletions mmpose/models/backbones/regnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ def _make_stem_layer(self, in_channels, base_channels):
self.add_module(self.norm1_name, norm1)
self.relu = nn.ReLU(inplace=True)

def generate_regnet(self,
initial_width,
@staticmethod
def generate_regnet(initial_width,
width_slope,
width_parameter,
depth,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ def __init__(self,
num_deconv_filters, num_deconv_kernels, num_basic_blocks,
cat_output)

def _make_final_layers(self, in_channels, final_layer_output_channels,
extra, num_deconv_layers, num_deconv_filters):
@staticmethod
def _make_final_layers(in_channels, final_layer_output_channels, extra,
num_deconv_layers, num_deconv_filters):
"""Make final layers."""
if extra is not None and 'final_conv_kernel' in extra:
assert extra['final_conv_kernel'] in [1, 3]
Expand Down Expand Up @@ -147,7 +148,8 @@ def _make_deconv_layers(self, in_channels, deconv_layer_output_channels,

return nn.ModuleList(deconv_layers)

def _get_deconv_cfg(self, deconv_kernel):
@staticmethod
def _get_deconv_cfg(deconv_kernel):
"""Get configurations for deconv layers."""
if deconv_kernel == 4:
padding = 1
Expand Down
3 changes: 2 additions & 1 deletion mmpose/models/keypoint_heads/bottom_up_simple_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ def _make_deconv_layer(self, num_layers, num_filters, num_kernels):

return nn.Sequential(*layers)

def _get_deconv_cfg(self, deconv_kernel):
@staticmethod
def _get_deconv_cfg(deconv_kernel):
"""Get configurations for deconv layers."""
if deconv_kernel == 4:
padding = 1
Expand Down
3 changes: 2 additions & 1 deletion mmpose/models/keypoint_heads/top_down_multi_stage_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ def _make_deconv_layer(self, num_layers, num_filters, num_kernels):

return nn.Sequential(*layers)

def _get_deconv_cfg(self, deconv_kernel):
@staticmethod
def _get_deconv_cfg(deconv_kernel):
"""Get configurations for deconv layers."""
if deconv_kernel == 4:
padding = 1
Expand Down
3 changes: 2 additions & 1 deletion mmpose/models/keypoint_heads/top_down_simple_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ def _make_deconv_layer(self, num_layers, num_filters, num_kernels):

return nn.Sequential(*layers)

def _get_deconv_cfg(self, deconv_kernel):
@staticmethod
def _get_deconv_cfg(deconv_kernel):
"""Get configurations for deconv layers."""
if deconv_kernel == 4:
padding = 1
Expand Down
3 changes: 2 additions & 1 deletion mmpose/models/losses/mesh_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@ def __init__(self,
raise NotImplementedError(
f'GAN type {self.gan_type} is not implemented.')

def _wgan_loss(self, input, target):
@staticmethod
def _wgan_loss(input, target):
"""wgan loss.
Args:
Expand Down
3 changes: 2 additions & 1 deletion mmpose/models/losses/multi_loss_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def _make_input(t, requires_grad=False, device=torch.device('cpu')):
class HeatmapLoss(nn.Module):
"""Accumulate the heatmap loss for each image in the batch."""

def forward(self, pred, gt, mask):
@staticmethod
def forward(pred, gt, mask):
"""
Note:
batch_size: N
Expand Down

0 comments on commit 4e612eb

Please sign in to comment.