Skip to content

Commit

Permalink
evaluation on bottom center
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Jul 2, 2019
1 parent 712bdf9 commit f0150da
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/eval/generate_kitti.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ def generate_kitti(model, dir_ann, p_dropout=0.2, n_dropout=0):
outputs, varss = monoloco.forward(keypoints, kk)
dds_geom = eval_geometric(keypoints, kk, average_y=0.48)

if basename == '001782':
aa = 5

# Save the file
all_outputs = [outputs.detach().cpu(), varss.detach().cpu(), dds_geom]
all_inputs = [boxes, keypoints]
Expand All @@ -75,7 +78,7 @@ def save_txts(path_txt, all_inputs, all_outputs, all_params):
uv_boxes, keypoints = all_inputs[:]
kk, tt = all_params[:]

uv_centers = get_keypoints(keypoints, mode='center')
uv_centers = get_keypoints(keypoints, mode='bottom') # Kitti uses the bottom center to calculate depth
xy_centers = pixel_to_camera(uv_centers, kk, 1)
zzs = xyz_from_distance(outputs[:, 0:1], xy_centers)[:, 2].tolist()

Expand Down
1 change: 0 additions & 1 deletion src/models/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ def evaluate(self, load=False, model=None, debug=False):

# To load a model instead of using the trained one
if load:
# self.path_out = os.path.join(self.dir_out, 'best_model_paper.pickle')
self.model.load_state_dict(torch.load(model, map_location=lambda storage, loc: storage))

# Average distance on training and test set after unnormalizing
Expand Down
9 changes: 8 additions & 1 deletion src/utils/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,21 @@ def get_keypoints(keypoints, mode):
keypoints = keypoints.unsqueeze(0)

assert len(keypoints.size()) == 3 and keypoints.size()[1] == 3, "tensor dimensions not recognized"
assert mode in ['center', 'head', 'shoulder', 'hip' , 'ankle']
assert mode in ['center', 'bottom', 'head', 'shoulder', 'hip', 'ankle']

kps_in = keypoints[:, 0:2, :] # (m, 2, 17)
if mode == 'center':
kps_max, _ = kps_in.max(2) # returns value, indices
kps_min, _ = kps_in.min(2)
kps_out = (kps_max - kps_min) / 2 + kps_min # (m, 2) as keepdims is False

elif mode == 'bottom': # bottom center for kitti evaluation
kps_max, _ = kps_in.max(2)
kps_min, _ = kps_in.min(2)
kps_out_x = (kps_max[:, 0:1] - kps_min[:, 0:1]) / 2 + kps_min[:, 0:1]
kps_out_y = kps_max[:, 1:2]
kps_out = torch.cat((kps_out_x, kps_out_y), -1)

elif mode == 'head':
kps_out = kps_in[:, :, 0:5].mean(2)

Expand Down

0 comments on commit f0150da

Please sign in to comment.