(self, output, target_low_res, target_full_res, inverse_maps, file_names,
full_res_coords, original_colors, original_normals, raw_coords, idx, first_full_res=False,
backbone_features=None, segment_connectivity=None)
| 477 | return score, result_pred_mask, classes, heatmap |
| 478 | |
| 479 | def eval_instance_step(self, output, target_low_res, target_full_res, inverse_maps, file_names, |
| 480 | full_res_coords, original_colors, original_normals, raw_coords, idx, first_full_res=False, |
| 481 | backbone_features=None, segment_connectivity=None): |
| 482 | label_offset = self.validation_dataset.label_offset |
| 483 | prediction = output['aux_outputs'] |
| 484 | prediction.append({ |
| 485 | 'pred_logits': output['pred_logits'], |
| 486 | 'pred_masks': output['pred_masks'] |
| 487 | }) |
| 488 | |
| 489 | prediction[self.decoder_id]['pred_logits'] = torch.functional.F.softmax( |
| 490 | prediction[self.decoder_id]['pred_logits'], |
| 491 | dim=-1)[..., :-1] |
| 492 | |
| 493 | all_pred_classes = list() |
| 494 | all_pred_masks = list() |
| 495 | all_pred_scores = list() |
| 496 | all_heatmaps = list() |
| 497 | all_query_pos = list() |
| 498 | |
| 499 | offset_coords_idx = 0 |
| 500 | for bid in range(len(prediction[self.decoder_id]['pred_masks'])): |
| 501 | if not first_full_res: |
| 502 | if self.model.train_on_segments: |
| 503 | masks = prediction[self.decoder_id]['pred_masks'][bid].detach().cpu()[target_low_res[bid]['point2segment'].cpu()] |
| 504 | else: |
| 505 | masks = prediction[self.decoder_id]['pred_masks'][bid].detach().cpu() |
| 506 | |
| 507 | if self.config.general.use_dbscan: |
| 508 | new_preds = { |
| 509 | 'pred_masks': list(), |
| 510 | 'pred_logits': list(), |
| 511 | } |
| 512 | |
| 513 | curr_coords_idx = masks.shape[0] |
| 514 | curr_coords = raw_coords[offset_coords_idx:curr_coords_idx + offset_coords_idx] |
| 515 | offset_coords_idx += curr_coords_idx |
| 516 | |
| 517 | for curr_query in range(masks.shape[1]): |
| 518 | curr_masks = masks[:, curr_query] > 0 |
| 519 | |
| 520 | if curr_coords[curr_masks].shape[0] > 0: |
| 521 | clusters = DBSCAN(eps=self.config.general.dbscan_eps, |
| 522 | min_samples=self.config.general.dbscan_min_points, |
| 523 | n_jobs=-1).fit(curr_coords[curr_masks]).labels_ |
| 524 | |
| 525 | new_mask = torch.zeros(curr_masks.shape, dtype=int) |
| 526 | new_mask[curr_masks] = torch.from_numpy(clusters) + 1 |
| 527 | |
| 528 | for cluster_id in np.unique(clusters): |
| 529 | original_pred_masks = masks[:, curr_query] |
| 530 | if cluster_id != -1: |
| 531 | new_preds['pred_masks'].append(original_pred_masks * (new_mask == cluster_id + 1)) |
| 532 | new_preds['pred_logits'].append( |
| 533 | prediction[self.decoder_id]['pred_logits'][bid, curr_query]) |
| 534 | |
| 535 | scores, masks, classes, heatmap = self.get_mask_and_scores( |
| 536 | torch.stack(new_preds['pred_logits']).cpu(), |
no test coverage detected