Exemplo n.º 1
0
 def _evaluate_semisupervised(all_gt_masks, all_res_masks, all_void_masks,
                              metric):
     if all_res_masks.shape[0] > all_gt_masks.shape[0]:
         sys.stdout.write(
             "\nIn your PNG files there is an index higher than the number of objects in the sequence!"
         )
         sys.exit()
     elif all_res_masks.shape[0] < all_gt_masks.shape[0]:
         zero_padding = np.zeros(
             (all_gt_masks.shape[0] - all_res_masks.shape[0],
              *all_res_masks.shape[1:]))
         all_res_masks = np.concatenate([all_res_masks, zero_padding],
                                        axis=0)
     j_metrics_res, f_metrics_res = np.zeros(
         all_gt_masks.shape[:2]), np.zeros(all_gt_masks.shape[:2])
     for ii in range(all_gt_masks.shape[0]):
         if 'J' in metric:
             j_metrics_res[ii, :] = db_eval_iou(all_gt_masks[ii, ...],
                                                all_res_masks[ii, ...],
                                                all_void_masks)
         if 'F' in metric:
             f_metrics_res[ii, :] = db_eval_boundary(
                 all_gt_masks[ii, ...], all_res_masks[ii, ...],
                 all_void_masks)
     return j_metrics_res, f_metrics_res
def test_void_masks():
    gt = np.zeros((2, 200, 200))
    mask = np.zeros((2, 200, 200))
    void = np.zeros((2, 200, 200))

    gt[:, 100:150, 100:150] = 1
    void[:, 50:100, 100:150] = 1
    mask[:, 50:150, 100:150] = 1

    assert np.mean(db_eval_iou(gt, mask, void)) == 1
    assert np.mean(db_eval_boundary(gt, mask, void)) == 1
Exemplo n.º 3
0
 def _evaluate_unsupervised(all_gt_masks,
                            all_res_masks,
                            all_void_masks,
                            metric,
                            max_n_proposals=20):
     if all_res_masks.shape[0] > max_n_proposals:
         sys.stdout.write(
             f"\nIn your PNG files there is an index higher than the maximum number ({max_n_proposals}) of proposals allowed!"
         )
         sys.exit()
     elif all_res_masks.shape[0] < all_gt_masks.shape[0]:
         zero_padding = np.zeros(
             (all_gt_masks.shape[0] - all_res_masks.shape[0],
              *all_res_masks.shape[1:]))
         all_res_masks = np.concatenate([all_res_masks, zero_padding],
                                        axis=0)
     j_metrics_res = np.zeros(
         (all_res_masks.shape[0], all_gt_masks.shape[0],
          all_gt_masks.shape[1]))
     f_metrics_res = np.zeros(
         (all_res_masks.shape[0], all_gt_masks.shape[0],
          all_gt_masks.shape[1]))
     for ii in range(all_gt_masks.shape[0]):
         for jj in range(all_res_masks.shape[0]):
             if 'J' in metric:
                 j_metrics_res[jj,
                               ii, :] = db_eval_iou(all_gt_masks[ii, ...],
                                                    all_res_masks[jj, ...],
                                                    all_void_masks)
             if 'F' in metric:
                 f_metrics_res[jj, ii, :] = db_eval_boundary(
                     all_gt_masks[ii, ...], all_res_masks[jj, ...],
                     all_void_masks)
     if 'J' in metric and 'F' in metric:
         all_metrics = (np.mean(j_metrics_res, axis=2) +
                        np.mean(f_metrics_res, axis=2)) / 2
     else:
         all_metrics = np.mean(j_metrics_res,
                               axis=2) if 'J' in metric else np.mean(
                                   f_metrics_res, axis=2)
     row_ind, col_ind = linear_sum_assignment(-all_metrics)
     return j_metrics_res[row_ind, col_ind, :], f_metrics_res[row_ind,
                                                              col_ind, :]