Per-Class Score Threshold
SkillMediaApply class-specific confidence thresholds by inferring the dominant class per image and indexing into a per-class threshold array
Available today. Use it from your connected AI after setup.
No other account needed.
Connect ahel once, and every AI you use reads what you have installed.
Then ask your AI: use the Per-Class Score Threshold skill
What this skill tells your AI
The instructions your AI receives, as published by wenmin-wu/ds-skills in skills/cv/per-class-score-threshold/SKILL.md and read by ahel’s review.
Overview
Different object classes have different score distributions — small dense cells score lower than large isolated ones. A single global threshold under-filters easy classes and over-filters hard ones. Infer the dominant class per image (mode of predicted classes), then apply that class's optimized threshold. Common in cell segmentation where cell types have very different morphologies.
Quick Start
import torch
import numpy as np
THRESHOLDS = [0.15, 0.35, 0.55] # per class, tuned on validation
MIN_PIXELS = [75, 150, 75] # per class minimum area
def filter_predictions(predictions):
scores = predictions['scores']
classes = predictions['pred_classes']
masks = predictions['pred_masks']
# Infer dominant class for this image
dominant_class = torch.mode(classes)[0].item()
# Apply class-specific threshold
keep = scores >= THRESHOLDS[dominant_class]
return masks[keep], scores[keep], dominant_class
masks, scores, cls = filter_predictions(output['instances'])
Workflow
- Run inference to get per-instance scores, classes, and masks
- Compute the mode of predicted classes to determine dominant image class
- Index into per-class threshold and min-area arrays
- Filter predictions by the class-specific threshold
- Optionally apply class-specific min-area filtering post-overlap-resolution
Key Decisions
- Mode vs majority:
torch.modeis simple; for mixed-class images, consider per-instance thresholds instead - Threshold tuning: sweep thresholds per class on validation set, optimize for mAP@IoU
- Homogeneous assumption: works best when images contain mostly one class; for mixed scenes, apply per-instance class thresholds
- Min-area coupling: pair with per-class min_pixels to also filter by class-specific size
References
Signals
- GitHub stars
- 60
- Forks
- 4
- Last commit
- Apr 2026
Advanced
- Catalog kind
- skill
- Gateway key
cv-per-class-score-threshold- Source
- github.com/wenmin-wu/ds-skills