(net: PlaneRecNet, dataset, writer: SummaryWriter, iteration, eval_nums)
| 130 | print('Stopping...') |
| 131 | |
| 132 | def tensorborad_visual_log(net: PlaneRecNet, dataset, writer: SummaryWriter, iteration, eval_nums): |
| 133 | dataset_indices = list(range(len(dataset))) |
| 134 | random.shuffle(dataset_indices) |
| 135 | dataset_indices = dataset_indices[:eval_nums] |
| 136 | |
| 137 | try: |
| 138 | # Main eval loop |
| 139 | for it, image_idx in enumerate(dataset_indices): |
| 140 | image, _, _ = dataset.pull_item(image_idx) |
| 141 | frame_ori = dataset.pull_image(image_idx) |
| 142 | frame_tensor = torch.from_numpy(frame_ori).cuda().float() |
| 143 | batch = Variable(image.unsqueeze(0)).cuda() |
| 144 | |
| 145 | batched_result = net(batch) # if batch_size = 1, result = batched_result[0] |
| 146 | seg_on_frame_numpy, pred_depth = display_on_frame(batched_result[0], frame_tensor, mask_alpha=0.35) |
| 147 | |
| 148 | pred_depth = pred_depth[20:460,20:620] |
| 149 | vmin = np.percentile(pred_depth, 1) |
| 150 | vmax = np.percentile(pred_depth, 99) |
| 151 | pred_depth = pred_depth.clip(min=vmin, max=vmax) |
| 152 | pred_depth = ((pred_depth - pred_depth.min()) / (pred_depth.max() - pred_depth.min()) * 255).astype(np.uint8) |
| 153 | pred_depth_color = cv2.applyColorMap(pred_depth, cv2.COLORMAP_VIRIDIS) |
| 154 | |
| 155 | pred_depth_color = cv2.cvtColor(pred_depth_color, cv2.COLOR_BGR2RGB) |
| 156 | seg_on_frame_numpy = cv2.cvtColor(seg_on_frame_numpy, cv2.COLOR_BGR2RGB) |
| 157 | writer.add_image("depth/pred/{}".format(it), pred_depth_color, iteration, dataformats='HWC') |
| 158 | writer.add_image("seg/pred/{}".format(it), seg_on_frame_numpy, iteration, dataformats='HWC') |
| 159 | |
| 160 | except KeyboardInterrupt: |
| 161 | print('Stopping...') |
| 162 | |
| 163 | |
| 164 | def compute_depth_metrics(pred_depth, gt_depth, median_scaling=True): |
no test coverage detected