use std::path::Path;
use std::path::PathBuf;
use hotcoco::params::IouType;
use hotcoco::{COCO, COCOeval};
fn load(gt_path: &Path, dt_path: &Path) -> Result<(COCO, COCO), Box<dyn std::error::Error>> {
let coco_gt = COCO::new(gt_path)?;
let coco_dt = coco_gt.load_res(dt_path)?;
Ok((coco_gt, coco_dt))
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let args: Vec<String> = std::env::args().collect();
if args.len() < 5 || args[1] != "--gt" || args[3] != "--dt" {
eprintln!("Usage: custom_params --gt <gt.json> --dt <dt.json>");
std::process::exit(1);
}
let gt_path = PathBuf::from(&args[2]);
let dt_path = PathBuf::from(&args[4]);
println!("=== Subset of categories ===");
let (coco_gt, coco_dt) = load(>_path, &dt_path)?;
let first_cats: Vec<u64> = coco_gt
.get_cat_ids(&[], &[], &[])
.into_iter()
.take(3)
.collect();
println!("Categories: {:?}", first_cats);
let mut ev = COCOeval::new(coco_gt, coco_dt, IouType::Bbox);
ev.params.cat_ids = first_cats;
ev.evaluate();
ev.accumulate();
ev.summarize();
println!("\n=== Custom IoU thresholds [0.5, 0.75] ===");
let (coco_gt, coco_dt) = load(>_path, &dt_path)?;
let mut ev2 = COCOeval::new(coco_gt, coco_dt, IouType::Bbox);
ev2.params.iou_thrs = vec![0.5, 0.75];
ev2.evaluate();
ev2.accumulate();
ev2.summarize();
println!("\n=== Class-agnostic evaluation ===");
let (coco_gt, coco_dt) = load(>_path, &dt_path)?;
let mut ev3 = COCOeval::new(coco_gt, coco_dt, IouType::Bbox);
ev3.params.use_cats = false;
ev3.evaluate();
ev3.accumulate();
ev3.summarize();
Ok(())
}