use crate::dataset::{CocoDataset, CocoDetections};
use crate::error::EvalError;
use crate::evaluate::EvalKernel;
use crate::parity::ParityMode;
use crate::similarity::{BboxIou, BoundaryIou, SegmIou};
use super::assignment::{assign_bins, DtBin};
use super::cross_class::compute_cross_class_ious;
use super::params::TideParams;
use super::report::KernelMarker;
#[derive(Debug, Clone)]
pub struct FpIouHistogram {
pub iou_same: Vec<f64>,
pub iou_cross: Vec<f64>,
pub kernel: KernelMarker,
pub t_f: f64,
pub n_total_dts: usize,
pub n_fps: usize,
}
pub fn compute_fp_iou_histogram_with<K: EvalKernel>(
gt: &CocoDataset,
dt: &CocoDetections,
kernel: &K,
kernel_marker: KernelMarker,
params: TideParams<'_>,
parity_mode: ParityMode,
) -> Result<FpIouHistogram, EvalError> {
let cross_class =
compute_cross_class_ious(gt, dt, kernel, parity_mode, params.max_dets_per_image)?;
let assignment = assign_bins(gt, dt, &cross_class, ¶ms)?;
let mut iou_same = Vec::new();
let mut iou_cross = Vec::new();
let n_total_dts = assignment.dt_labels.len();
for label in assignment.dt_labels.values() {
match label.bin {
DtBin::Tp | DtBin::Ignore => continue,
DtBin::Cls | DtBin::Loc | DtBin::Both | DtBin::Dupe | DtBin::Bkg => {
iou_same.push(label.iou_same);
iou_cross.push(label.iou_cross);
}
}
}
let n_fps = iou_same.len();
Ok(FpIouHistogram {
iou_same,
iou_cross,
kernel: kernel_marker,
t_f: params.t_f,
n_total_dts,
n_fps,
})
}
pub fn compute_fp_iou_histogram_bbox(
gt: &CocoDataset,
dt: &CocoDetections,
params: TideParams<'_>,
parity_mode: ParityMode,
) -> Result<FpIouHistogram, EvalError> {
compute_fp_iou_histogram_with(gt, dt, &BboxIou, KernelMarker::Bbox, params, parity_mode)
}
pub fn compute_fp_iou_histogram_segm(
gt: &CocoDataset,
dt: &CocoDetections,
params: TideParams<'_>,
parity_mode: ParityMode,
) -> Result<FpIouHistogram, EvalError> {
compute_fp_iou_histogram_with(gt, dt, &SegmIou, KernelMarker::Segm, params, parity_mode)
}
pub fn compute_fp_iou_histogram_boundary(
gt: &CocoDataset,
dt: &CocoDetections,
params: TideParams<'_>,
parity_mode: ParityMode,
dilation_ratio: f64,
) -> Result<FpIouHistogram, EvalError> {
let kernel = BoundaryIou { dilation_ratio };
compute_fp_iou_histogram_with(gt, dt, &kernel, KernelMarker::Boundary, params, parity_mode)
}