MCPcopy Create free account
hub / github.com/RozDavid/UnScene3D / save_visualizations

Method save_visualizations

trainer/trainer.py:197–357  ·  view source on GitHub ↗
(self, target_full, full_res_coords,
                            sorted_masks, sort_classes, file_name, original_colors, original_normals,
                            sort_scores_values, point_size=40, sorted_heatmaps=None,
                            query_pos=None, backbone_features=None, topk=10)

Source from the content-addressed store, hash-verified

195 self.test_epoch_end(outputs)
196
197 def save_visualizations(self, target_full, full_res_coords,
198 sorted_masks, sort_classes, file_name, original_colors, original_normals,
199 sort_scores_values, point_size=40, sorted_heatmaps=None,
200 query_pos=None, backbone_features=None, topk=10):
201
202 full_res_coords -= full_res_coords.mean(axis=0)
203
204 gt_pcd_pos = []
205 gt_pcd_normals = []
206 gt_pcd_color = []
207 gt_inst_pcd_color = []
208 gt_boxes = []
209
210 if 'labels' in target_full:
211 scannet_colors = np.stack(list(SCANNET_COLOR_MAP_200.values()))[1:]
212 instances_colors = torch.from_numpy( scannet_colors[:target_full['labels'].shape[0]] )
213
214 for instance_counter, (label, mask) in enumerate(zip(target_full['labels'], target_full['masks'])):
215 if label == 255:
216 continue
217
218 mask_tmp = mask.detach().cpu().numpy()
219 mask_coords = full_res_coords[mask_tmp.astype(bool), :]
220
221 if len(mask_coords) == 0:
222 continue
223
224 gt_pcd_pos.append(mask_coords)
225 mask_coords_min = full_res_coords[mask_tmp.astype(bool), :].min(axis=0)
226 mask_coords_max = full_res_coords[mask_tmp.astype(bool), :].max(axis=0)
227 size = mask_coords_max - mask_coords_min
228 mask_coords_middle = mask_coords_min + size / 2
229
230 gt_boxes.append({"position": mask_coords_middle, "size": size,
231 "color": self.validation_dataset.map2color([label])[0]})
232
233 gt_pcd_color.append(
234 self.validation_dataset.map2color([label]).repeat(gt_pcd_pos[-1].shape[0], 1)
235 )
236 gt_inst_pcd_color.append(instances_colors[instance_counter % len(instances_colors)].unsqueeze(0).repeat(gt_pcd_pos[-1].shape[0], 1))
237
238 gt_pcd_normals.append(original_normals[mask_tmp.astype(bool), :])
239
240 gt_pcd_pos = np.concatenate(gt_pcd_pos)
241 gt_pcd_normals = np.concatenate(gt_pcd_normals)
242 gt_pcd_color = np.concatenate(gt_pcd_color)
243 gt_inst_pcd_color = np.concatenate(gt_inst_pcd_color)
244
245 v = vis.Visualizer()
246
247 v.add_points("RGB Input", full_res_coords,
248 colors=original_colors,
249 normals=original_normals,
250 visible=True,
251 point_size=point_size)
252
253 if backbone_features is not None:
254 v.add_points("PCA", full_res_coords,

Callers 1

eval_instance_stepMethod · 0.95

Calls 4

maxFunction · 0.50
minFunction · 0.50
map2colorMethod · 0.45

Tested by

no test coverage detected