Detector-independent bounding-box evaluation for MoonBit
Dependencies
///|
fn main {
let box = @moondeteval.Box::from_xywh(0.0, 0.0, 10.0, 10.0) catch {
error => abort(error.message())
}
let dataset = @moondeteval.Dataset::new(
[@moondeteval.Image::new(1, 20, 20)],
[@moondeteval.Category::new(7, "object")],
[@moondeteval.GroundTruth::new(9L, 1, 7, box, area=100.0)],
) catch {
error => abort(error.message())
}
let prediction = @moondeteval.Detection::new(0, 1, 7, box, 0.9) catch {
error => abort(error.message())
}
let report = @moondeteval.evaluate(dataset, [prediction]) catch {
error => abort(error.message())
}
println("AP50=\{report.summary().ap50()}")
}moon run cli --target native -- examples/ground-truth.json examples/detections.json
moon run cli --target native -- examples/ground-truth.json examples/detections.json --diagnostics --min-ap50 0.8
moon run cli --target native -- examples/ground-truth.json examples/detections.json --output report.json
python examples/compare_demo.py{"schema_version":"0.1.0","summary":{"ap":1,"ap50":1,"ap75":1,"ap_small":1,"ap_medium":-1,"ap_large":-1,"ar1":0,"ar10":1,"ar100":1,"ar_small":1,"ar_medium":-1,"ar_large":-1}}moon run cli --target native -- examples/compare-ground-truth.json examples/compare-baseline.json --compare examples/compare-candidate.json --diagnostics
moon run cli --target native -- examples/compare-ground-truth.json examples/compare-baseline.json --compare examples/compare-candidate.json --image-ranking
moon run cli --target native -- examples/compare-ground-truth.json examples/compare-baseline.json --compare examples/compare-candidate.json --pr-curves{
"category_ids": [42, 7],
"images": [
{"image_id": 12, "file": "labels/image-12.txt"},
{"image_id": 9, "file": "labels/image-9.txt"}
]
}moon run cli --target native -- examples/yolo/ground-truth.json examples/yolo/manifest.json --prediction-format yolo --diagnostics
moon run cli --target native -- examples/yolo/ground-truth.json examples/yolo/detections.json --compare examples/yolo/manifest.json --compare-format yolo --diagnostics
moon run cli --target native -- examples/yolo/ground-truth.json examples/yolo/manifest.json --prediction-format yolo --min-ap50 0.8 --output failed-gate.json///|
let dataset = @moondeteval.parse_coco_dataset(ground_truth_json)
///|
let predictions = @moondeteval.parse_coco_detections(detections_json)
///|
let report = @moondeteval.evaluate(dataset, predictions)
///|
let ap50 = report.summary().ap50()
///|
let config = @moondeteval.EvalConfig::new([0.5, 0.75], include_diagnostics=true)
///|
let custom = @moondeteval.evaluate_with_config(dataset, predictions, config)
///|
let comparison = @moondeteval.compare_predictions(
dataset, predictions, other_predictions,
)
///|
let ap50_change = comparison.metrics()[1].delta()
///|
let yolo_predictions = @moondeteval.parse_yolo_detections(
yolo_txt,
dataset,
9,
[42, 7],
first_detection_id=100,
)
///|
let manifest = @moondeteval.parse_yolo_manifest(manifest_json, dataset)
///|
let retained = report.counts().evaluated_detections()
///|
let warnings = report.quality_warnings()
///|
let explicit_ignore = @moondeteval.EvalConfig::new(
[0.5],
ignore_policy="respect_explicit",
)moon fmt --check
moon check --target all --deny-warn
moon test --target all --deny-warn
python examples/compare_demo.py
python examples/yolo_manifest_demo.py
python -m pip install numpy==1.26.4 pycocotools==2.0.7
python reference_compare.pypub(all) suberror EvalError {
InvalidBox(String)
InvalidInput(String)
InvalidConfig(String)
} derive(Debug)pub struct ComparisonReport {
schema_version : String
baseline : EvaluationReport
candidate : EvaluationReport
metrics : Array[MetricChange]
classes : Array[ClassComparison]
image_changes : Array[ImageChange]
} derive(ToJson)fn EvalConfig::new(iou_thresholds : Array[Double], include_diagnostics? : Bool, ignore_policy? : String, include_image_summaries? : Bool, include_pr_curves? : Bool) -> EvalConfig raise EvalErrorpub struct EvaluationReport {
schema_version : String
evaluator_version : String
config : EvalConfig
counts : InputCounts
summary : Metrics
classes : Array[ClassMetrics]
diagnostics : Array[MatchDiagnostic]
image_summaries : Array[ImageSummary]
recall_thresholds : Array[Double]
pr_curves : Array[PrecisionRecallCurve]
quality_warnings : Array[QualityWarning]
} derive(ToJson)fn GroundTruth::new(id : Int64, image_id : Int, category_id : Int, bbox : Box, area~ : Double, iscrowd? : Bool, ignore? : Bool) -> GroundTruth raise EvalErrorpub struct ImageChange {
image_id : Int
baseline_errors : Int
candidate_errors : Int
error_delta : Int
} derive(ToJson)pub struct ImageSummary {
image_id : Int
tp : Int
fp : Int
fn_count : Int
ignored : Int
} derive(ToJson)pub struct InputCounts {
images : Int
categories : Int
ground_truths : Int
detections : Int
evaluated_detections : Int
} derive(ToJson)pub struct MatchDiagnostic {
iou_threshold : Double
image_id : Int
category_id : Int
detection_id : Int?
ground_truth_id : Int64?
iou : Double
status : String
reason : String
}impl ToJson for MatchDiagnosticpub struct MetricChange {
name : String
baseline : Double?
candidate : Double?
delta : Double?
}impl ToJson for MetricChangepub struct QualityWarning {
source : String
record_id : Int64
image_id : Int
category_id : Int
kind : String
}impl ToJson for QualityWarningpub struct YoloFile {
image_id : Int
file : String
}fn compare_predictions_with_config(dataset : Dataset, baseline : Array[Detection], candidate : Array[Detection], config : EvalConfig) -> ComparisonReport raise EvalErrorfn evaluate_with_config(dataset : Dataset, predictions : Array[Detection], config : EvalConfig) -> EvaluationReport raise EvalErrorfn evaluate_with_diagnostics(dataset : Dataset, predictions : Array[Detection]) -> EvaluationReport raise EvalErrorInstall
Download zipDetector-independent bounding-box evaluation for MoonBit
Dependencies