Skip to content

Commit

Permalink
update libs
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholasli1995 committed Feb 17, 2022
1 parent 522c1e4 commit 18c31ca
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 25 deletions.
20 changes: 10 additions & 10 deletions libs/common/img_proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,18 @@ def jitter_bbox_with_kpts_no_occlu(old_bbox, joints, parameters):
Similar to the function above, but does not produce occluded joints
"""
width, height = old_bbox[2] - old_bbox[0], old_bbox[3] - old_bbox[1]
old_center = [0.5*(old_bbox[0] + old_bbox[2]),
0.5*(old_bbox[1] + old_bbox[3])]
horizontal_scaling = parameters['scaling'][0]*np.random.rand() + 1
vertical_scaling = parameters['scaling'][1]*np.random.rand() + 1
horizontal_shift = 0.5*(horizontal_scaling-1)*width*np_random()
vertical_shift = 0.5*(vertical_scaling-1)*height*np_random()
old_center = [0.5 * (old_bbox[0] + old_bbox[2]),
0.5 * (old_bbox[1] + old_bbox[3])]
horizontal_scaling = parameters['scaling'][0] * np.random.rand() + 1
vertical_scaling = parameters['scaling'][1] * np.random.rand() + 1
horizontal_shift = 0.5 * (horizontal_scaling - 1) * width * np_random()
vertical_shift = 0.5 * (vertical_scaling - 1) * height * np_random()
new_center = [old_center[0] + horizontal_shift,
old_center[1] + vertical_shift]
new_width = width*horizontal_scaling
new_height = height*vertical_scaling
new_bbox = [new_center[0] - 0.5*new_width, new_center[1] - 0.5*new_height,
new_center[0] + 0.5*new_width, new_center[1] + 0.5*new_height]
new_width = width * horizontal_scaling
new_height = height * vertical_scaling
new_bbox = [new_center[0] - 0.5 * new_width, new_center[1] - 0.5 * new_height,
new_center[0] + 0.5 * new_width, new_center[1] + 0.5 * new_height]
return new_bbox, joints

def generate_xy_map(bbox, resolution, global_size):
Expand Down
21 changes: 13 additions & 8 deletions libs/dataset/KITTI/car_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,10 @@ def _prepare_key_points_custom(self, style, interp_params, vis_thresh=0.25):
def _prepare_key_points(self, cfgs):
self.kpts_style = cfgs['dataset']['2d_kpt_style']
self._prepare_key_points_custom(self.kpts_style, cfgs['dataset']['interpolate'])
self.enlarge_factor = 1.1
if 'enlarge_factor' in cfgs['dataset']:
self.enlarge_factor = cfgs['dataset']['enlarge_factor']
else:
self.enlarge_factor = 1.1
return

def _save_cropped_instances(self):
Expand Down Expand Up @@ -1275,13 +1278,15 @@ def __getitem__(self, idx):
parameters = self.hm_para
parameters['boxes'] = self.annot_2dpose['boxes'][idx]
# fs: fully-supervised ss: self-supervised
images_fs, heatmaps_fs, weights_fs, meta_fs = lip.get_tensor_from_img(img_path,
parameters,
joints=kpts,
pth_trans=self.pth_trans,
rf=parameters['rf'],
sf=parameters['sf'],
generate_hm=True)
images_fs, heatmaps_fs, weights_fs, meta_fs = \
lip.get_tensor_from_img(img_path,
parameters,
joints=kpts,
pth_trans=self.pth_trans,
rf=parameters['rf'],
sf=parameters['sf'],
generate_hm=True
)
# use random unlabeled images for data augmentation
if self.split == 'train' and hasattr(self, 'use_ss') and self.use_ss:
images_ss, heatmaps_ss, weights_ss, meta_ss = self.extract_ss_sample(len(images_fs))
Expand Down
12 changes: 6 additions & 6 deletions libs/metric/criterions.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,13 @@ def __init__(self, cfgs, num_joints=None):
else:
self.num_joints = cfgs['heatmapModel']['num_joints']
self.image_size = cfgs['heatmapModel']['input_size']
if 'arg_max' in cfgs['testing_settings']:
if 'arg_max' in cfgs['testing_settings']:
self.arg_max = cfgs['testing_settings']['arg_max']
else:
self.arg_max = None
self.count = 0
self.mean = 0.
self.PCK_counts = np.zeros(len(PCK_THRES))
else:
self.arg_max = None
self.count = 0
self.mean = 0.
self.PCK_counts = np.zeros(len(PCK_THRES))
return

def update(self, prediction, meta_data, ground_truth=None, logger=None):
Expand Down
2 changes: 1 addition & 1 deletion libs/model/heatmapModel/hrnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def __init__(self, cfgs, **kwargs):
nn.Linear(256, 2)
)
elif self.head_type == 'coordinates':
num_chan = 33
num_chan = self.num_joints
self.head1 = nn.Sequential(
nn.Conv2d(
in_channels=pre_stage_channels[0],
Expand Down
1 change: 1 addition & 0 deletions tools/train_IGRs.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def train(model, model_settings, GPUs, cfgs, logger, final_output_dir):
data_cfgs = cfgs['dataset']
train_dataset, valid_dataset = eval('dataset.' + data_cfgs['name'] +
'.car_instance').prepare_data(cfgs, logger)

# get the optimizer and learning rate scheduler
optim, sche = optimizer.prepare_optim(model, cfgs)

Expand Down

0 comments on commit 18c31ca

Please sign in to comment.