def track(self, model: model_interface.TrackerInterface, **kwargs): """ Add current model predictions (usually the result of a batch) to the tracking """ super().track(model) outputs = self._convert(model.get_output()) targets = self._convert(model.get_labels()) batch_idx = self._convert(model.get_batch()) if batch_idx is None: raise ValueError( "Your model need to set the batch_idx variable in its set_input function." ) nb_batches = batch_idx.max() + 1 # pred to the groundtruth classes (selected by seg_classes[cat]) for b in range(nb_batches): segl = targets[batch_idx == b] cat = self._seg_to_class[segl[0]] logits = outputs[batch_idx == b, :] # (num_points, num_classes) segp = logits[:, self._class_seg_map[cat]].argmax( 1) + self._class_seg_map[cat][0] part_ious = np.zeros(len(self._class_seg_map[cat])) for l in self._class_seg_map[cat]: if np.sum((segl == l) | (segp == l)) == 0: # part is not present in this shape part_ious[l - self._class_seg_map[cat][0]] = 1 else: part_ious[l - self._class_seg_map[cat][0]] = float( np.sum((segl == l) & (segp == l))) / float( np.sum((segl == l) | (segp == l))) self._shape_ious[cat].append(np.mean(part_ious)) self._miou_per_class, self._Cmiou, self._Imiou = self._get_metrics_per_class( )
def track(self, model: model_interface.TrackerInterface, **kwargs): """ Add current model predictions (usually the result of a batch) to the tracking """ if not self._dataset.has_labels(self._stage): return super().track(model) outputs = model.get_output() targets = model.get_labels() # Mask ignored label mask = targets != self._ignore_label outputs = outputs[mask] targets = targets[mask] outputs = self._convert(outputs) targets = self._convert(targets) if len(targets) == 0: return assert outputs.shape[0] == len(targets) self._confusion_matrix.count_predicted_batch(targets, np.argmax(outputs, 1)) self._acc = 100 * self._confusion_matrix.get_overall_accuracy() self._macc = 100 * self._confusion_matrix.get_mean_class_accuracy() self._miou = 100 * self._confusion_matrix.get_average_intersection_union()
def track(self, model: model_interface.TrackerInterface, full_res: bool = False, data: Data = None, **kwargs): """ Add current model predictions (usually the result of a batch) to the tracking """ super().track(model) self._conv_type = model.conv_type outputs = self._convert(model.get_output()) targets = self._convert(model.get_labels()) batch_idx = self._convert(model.get_batch()) if batch_idx is None: raise ValueError( "Your model need to set the batch_idx variable in its set_input function." ) nb_batches = batch_idx.max() + 1 if self._stage != "train" and full_res: self._add_votes(data, outputs, batch_idx) # pred to the groundtruth classes (selected by seg_classes[cat]) for b in range(nb_batches): segl = targets[batch_idx == b] cat = self._seg_to_class[segl[0]] logits = outputs[batch_idx == b, :] # (num_points, num_classes) segp = logits[:, self._class_seg_map[cat]].argmax( 1) + self._class_seg_map[cat][0] part_ious = self._compute_part_ious(segl, segp, cat) self._shape_ious[cat].append(np.mean(part_ious)) self._miou_per_class, self._Cmiou, self._Imiou = ShapenetPartTracker._get_metrics_per_class( self._shape_ious)
def track(self, model: model_interface.TrackerInterface, **kwargs): """ Add current model predictions (usually the result of a batch) to the tracking """ super().track(model) outputs = model.get_output() # targets = model.get_labels().flatten() targets = model.get_labels() avg_loss_dimensions, avg_loss_epsilons, avg_loss_offsets, mae_a1, mae_a2, mae_a3, mae_x0, mae_y0, mae_z0, mae_e1, mae_e2 = self.compute_loss_by_components( outputs, targets) self._loss_dimension.add(avg_loss_dimensions.detach().cpu().numpy()) self._loss_epsilon.add(avg_loss_epsilons.detach().cpu().numpy()) self._loss_offset.add(avg_loss_offsets.detach().cpu().numpy()) self._loss_mae_a1.add(mae_a1.detach().cpu().numpy()) self._loss_mae_a2.add(mae_a2.detach().cpu().numpy()) self._loss_mae_a3.add(mae_a3.detach().cpu().numpy()) self._loss_mae_x0.add(mae_x0.detach().cpu().numpy()) self._loss_mae_y0.add(mae_y0.detach().cpu().numpy()) self._loss_mae_z0.add(mae_z0.detach().cpu().numpy()) self._loss_mae_e1.add(mae_e1.detach().cpu().numpy()) self._loss_mae_e2.add(mae_e2.detach().cpu().numpy())
def track(self, model: model_interface.TrackerInterface, **kwargs): """ Add current model predictions (usually the result of a batch) to the tracking """ super().track(model) outputs = model.get_output() targets = model.get_labels().flatten() self._acc.add(100 * self.compute_acc(outputs, targets))
def track(self, model: TrackerInterface, **kwargs): """ Track metrics for panoptic segmentation """ BaseTracker.track(self, model) outputs: PanopticResults = model.get_output() labels: PanopticLabels = model.get_labels() # Track semantic super()._compute_metrics(outputs.semantic_logits, labels.y)
def track(self, model: model_interface.TrackerInterface, **kwargs): """ Add current model predictions (usually the result of a batch) to the tracking """ if not self._dataset.has_labels(self._stage): return super().track(model) outputs = model.get_output() targets = model.get_labels() self._compute_metrics(outputs, targets)
def track(self, model: TrackerInterface, data=None, iou_threshold=0.25, track_instances=True, min_cluster_points=10, **kwargs): """ Track metrics for panoptic segmentation """ self._iou_threshold = iou_threshold BaseTracker.track(self, model) outputs: PanopticResults = model.get_output() labels: PanopticLabels = model.get_labels() # Track semantic super()._compute_metrics(outputs.semantic_logits, labels.y) if not data: return assert data.pos.dim() == 2, "Only supports packed batches" # Object accuracy clusters = PanopticTracker._extract_clusters(outputs, min_cluster_points) if not clusters: return predicted_labels = outputs.semantic_logits.max(1)[1] tp, fp, acc = self._compute_acc(clusters, predicted_labels, labels, data.batch, labels.num_instances, iou_threshold) self._pos.add(tp) self._neg.add(fp) self._acc_meter.add(acc) # Track instances for AP if track_instances: pred_clusters = self._pred_instances_per_scan( clusters, predicted_labels, outputs.cluster_scores, data.batch, self._scan_id_offset) gt_clusters = self._gt_instances_per_scan(labels.instance_labels, labels.y, data.batch, self._scan_id_offset) self._ap_meter.add(pred_clusters, gt_clusters) self._scan_id_offset += data.batch[-1].item() + 1