From f0150da571683aaecd56814ea7a805f3c3287e46 Mon Sep 17 00:00:00 2001 From: lorenzo Date: Tue, 2 Jul 2019 11:59:55 +0200 Subject: [PATCH] evaluation on bottom center --- src/eval/generate_kitti.py | 5 ++++- src/models/trainer.py | 1 - src/utils/camera.py | 9 ++++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/eval/generate_kitti.py b/src/eval/generate_kitti.py index b10be9a..400f662 100644 --- a/src/eval/generate_kitti.py +++ b/src/eval/generate_kitti.py @@ -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] @@ -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() diff --git a/src/models/trainer.py b/src/models/trainer.py index 27bc238..711d69e 100644 --- a/src/models/trainer.py +++ b/src/models/trainer.py @@ -216,7 +216,6 @@ class Trainer: # 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 diff --git a/src/utils/camera.py b/src/utils/camera.py index a8e43c2..619939f 100644 --- a/src/utils/camera.py +++ b/src/utils/camera.py @@ -76,7 +76,7 @@ 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': @@ -84,6 +84,13 @@ def get_keypoints(keypoints, mode): 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)