From dfdddae43aca3a7c7cbc21cf4e2e41b4a4c0ce06 Mon Sep 17 00:00:00 2001 From: lorenzo Date: Fri, 24 May 2019 16:11:38 +0200 Subject: [PATCH] remove y_scale parameter --- README.md | 2 +- src/main.py | 3 +-- src/predict/predict_monoloco.py | 7 ++----- src/visuals/printer.py | 36 +++++++++++++++------------------ 4 files changed, 20 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 3c03269..175a336 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ If it does not find the file, it will generate images with all the predictions without ground-truth matching. Below an example with and without ground-truth matching. They have been created (adding or removing `--path_gt`) with: -`python3 src/main.py predict --networks monoloco --glob docs/002282.png --output_types combined --scale 2 --y_scale 1.85 +`python3 src/main.py predict --networks monoloco --glob docs/002282.png --output_types combined --scale 2 --model data/models/monoloco-190513-1437.pkl --n_dropout 100 --z_max 30` With ground truth matching (only matching people): diff --git a/src/main.py b/src/main.py index 649e76e..9da7f57 100644 --- a/src/main.py +++ b/src/main.py @@ -64,8 +64,7 @@ def cli(): predict_parser.add_argument('--transform', help='transformation for the pose', default='None') predict_parser.add_argument('--draw_kps', help='to draw kps in the images', action='store_true') predict_parser.add_argument('--predict', help='whether to make prediction', action='store_true') - predict_parser.add_argument('--z_max', type=int, help='', default=22) - predict_parser.add_argument('--y_scale', type=float, help='', default=1) + predict_parser.add_argument('--z_max', type=int, help='maximum meters distance for predictions', default=22) predict_parser.add_argument('--n_dropout', type=int, help='Epistemic uncertainty evaluation', default=0) predict_parser.add_argument('--combined', help='to print combined images', action='store_true') diff --git a/src/predict/predict_monoloco.py b/src/predict/predict_monoloco.py index e46d618..a9655b0 100644 --- a/src/predict/predict_monoloco.py +++ b/src/predict/predict_monoloco.py @@ -35,7 +35,6 @@ class PredictMonoLoco: self.output_path = output_path self.device = args.device self.draw_kps = args.draw_kps - self.y_scale = args.y_scale # y_scale = 1.85 for kitti combined self.z_max = args.z_max self.output_types = args.output_types self.show = args.show @@ -72,8 +71,7 @@ class PredictMonoLoco: except (KeyError, TypeError): self.dic_names = None # kk = [[718.3351, 0., 600.3891], [0., 718.3351, 181.5122], [0., 0., 1.]] # Kitti standard - #kk = [[1266.4, 0., 816.27], [0, 1266.4, 491.5], [0., 0., 1.]] # Nuscenes standard - kk = [[1266.4, 0., 816.27], [0, 1266.4, 491.5], [0., 0., 1.]] + kk = [[1266.4, 0., 816.27], [0, 1266.4, 491.5], [0., 0., 1.]] # Nuscenes standard print("Ground-truth annotations for the image not found\n" "Using a standard calibration matrix...\n" + '-' * 120) @@ -151,8 +149,7 @@ class PredictMonoLoco: dic_out['uv_shoulders'].append(uv_shoulders[idx]) if any((xx in self.output_types for xx in ['front', 'bird', 'combined'])): - printer = Printer(self.image_path, self.output_path, dic_out, kk, - y_scale=self.y_scale, output_types=self.output_types, + printer = Printer(self.image_path, self.output_path, dic_out, kk, output_types=self.output_types, show=self.show, z_max=self.z_max, epistemic=self.epistemic) printer.print() diff --git a/src/visuals/printer.py b/src/visuals/printer.py index 97cbd65..f83dc1b 100644 --- a/src/visuals/printer.py +++ b/src/visuals/printer.py @@ -17,11 +17,10 @@ class Printer: Print results on images: birds eye view and computed distance """ - def __init__(self, image_path, output_path, dic_ann, kk, output_types, y_scale=1, show=False, + def __init__(self, image_path, output_path, dic_ann, kk, output_types, show=False, draw_kps=False, text=True, legend=True, epistemic=False, z_max=30, fig_width=10): self.kk = kk - self.y_scale = y_scale # 1.85 for kitti combined self.output_types = output_types self.show = show self.draw_kps = draw_kps @@ -57,13 +56,8 @@ class Printer: with open(image_path, 'rb') as f: self.im = Image.open(f).convert('RGB') - # Resize image for aesthetic proportions - if y_scale >= 1.02 or y_scale <= 0.98: - ww = self.im.size[0] - hh = self.im.size[1] - self.im = self.im.resize((ww, round(hh * y_scale))) - self.uv_camera = (int(self.im.size[0] / 2), self.im.size[1]) + self.hh = self.im.size[1] def print(self): """ @@ -79,10 +73,17 @@ class Printer: textcolor = 'darkorange' color_kps = 'yellow' - # Initialize combined + # Resize image for aesthetic proportions in combined visualization if 'combined' in self.output_types: + ww = self.im.size[0] + hh = self.im.size[1] + y_scale = ww / (hh * 1.8) # Defined proportion + self.im = self.im.resize((ww, round(hh * y_scale))) + print(y_scale) width = self.fig_width + 0.6 * self.fig_width height = self.fig_width * self.im.size[1] / self.im.size[0] + print(width) + print() fig_ar_1 = 1.7 # 1.3 before width_ratio = 1.9 ext = '.combined.png' @@ -98,6 +99,7 @@ class Printer: # Initialize front elif 'front' in self.output_types: + y_scale = 1 width = self.fig_width height = self.fig_width * self.im.size[1] / self.im.size[0] @@ -120,15 +122,15 @@ class Printer: for idx, uv in enumerate(self.uv_shoulders): if self.draw_kps: - ax0 = self.show_kps(ax0, self.uv_kps[idx], self.y_scale, radius_kps, color_kps) + ax0 = self.show_kps(ax0, self.uv_kps[idx], y_scale, radius_kps, color_kps) elif min(self.zz_pred[idx], self.zz_gt[idx]) > 0: color = cmap((self.zz_pred[idx] % self.z_max) / self.z_max) - circle = Circle((uv[0], uv[1] * self.y_scale), radius=radius, color=color, fill=True) + circle = Circle((uv[0], uv[1] * y_scale), radius=radius, color=color, fill=True) ax0.add_patch(circle) if self.text: - ax0.text(uv[0]+radius, uv[1] * self.y_scale - radius, str(num), + ax0.text(uv[0]+radius, uv[1] * y_scale - radius, str(num), fontsize=fontsize, color=textcolor, weight='bold') num += 1 @@ -160,8 +162,7 @@ class Printer: # Create bird or combine it with front) if any(xx in self.output_types for xx in ['bird', 'combined']): - im_height = 375 # TODO change it - uv_max = np.array([0, im_height, 1]) + uv_max = np.array([0, self.hh, 1]) xyz_max = self.pixel_to_camera(uv_max, self.kk, self.z_max) x_max = abs(xyz_max[0]) # shortcut to avoid oval circles in case of different kk @@ -212,12 +213,7 @@ class Printer: ax1.plot([0, x_max], [0, self.z_max], 'k--') ax1.plot([0, -x_max], [0, self.z_max], 'k--') ax1.set_ylim(0, self.z_max+1) - # ax1.set_xmin([-10, 10]) - # ax1.set_ymin([0, 20]) - # x_max_field = min(x_max, z_max / 1.55) # ! Shortcut to avoid oval circles in case of different k - # plt.axis([-x_max_field, x_max_field, 0, z_max]) - # plt.xticks([]) - # plt.title('Birds eye view') + ax1.set_xlim(-self.z_max+2, self.z_max-2) ax1.set_xlabel("X [m]") ax1.set_ylabel("Z [m]")