skills/cv/two-stage-classify-then-detect/SKILL.md
Chain a study-level classifier with an image-level detector, merging class probabilities and bounding boxes into a unified prediction
npx skillsauth add wenmin-wu/ds-skills cv-two-stage-classify-then-detectInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
When predictions span multiple granularities (e.g., study-level disease type + image-level lesion boxes), use a two-stage pipeline: first classify the overall case, then detect specific regions. Merge both outputs into a unified submission. Common in medical imaging where diagnosis (classification) and localization (detection) are both required.
import numpy as np
# Stage 1: Study-level classification (e.g., EfficientNet)
study_preds = np.zeros((len(studies), n_classes))
for model in fold_models:
study_preds += model.predict(study_dataset)
study_preds /= len(fold_models)
# Stage 2: Image-level detection (e.g., YOLOv5, Cascade RCNN)
image_detections = {}
for img_id, img_path in images:
boxes, scores = detector.predict(img_path)
image_detections[img_id] = (boxes, scores)
# Merge: study gets class probabilities, images get bounding boxes
results = []
for study_id, preds in zip(study_ids, study_preds):
pred_str = " ".join(
f"{cls} {prob:.4f} 0 0 1 1" for cls, prob in zip(class_names, preds)
)
results.append({"id": f"{study_id}_study", "prediction": pred_str})
for img_id in study_images[study_id]:
boxes, scores = image_detections.get(img_id, ([], []))
if boxes:
pred_str = " ".join(
f"opacity {s:.4f} {b[0]} {b[1]} {b[2]} {b[3]}"
for b, s in zip(boxes, scores)
)
else:
pred_str = "none 1 0 0 1 1"
results.append({"id": f"{img_id}_image", "prediction": pred_str})
data-ai
Scaled Pinball Loss (SPL) metric for evaluating quantile forecasts, normalized by mean absolute successive differences of training data
data-ai
Walk backward through a time series and multiplicatively rescale segments when jumps exceed a fraction of the running mean to correct data collection anomalies
testing
Transform forecasting target to next/current ratio minus one so that optimizing MAE or squared error implicitly minimizes SMAPE
tools
Convert point forecasts to prediction intervals by scaling with logit-transformed quantile ratios passed through a Normal CDF