skills/cv/two-stage-slice-localization-then-organ-crop/SKILL.md
Use a lightweight slice-classifier to find the Z-range containing an organ in a CT volume, then crop and trilinear-resample that sub-volume into a fixed shape for a heavier 3D classifier — replaces "use the whole volume" with "use only the relevant slab" at a fraction of the FLOPs
npx skillsauth add wenmin-wu/ds-skills cv-two-stage-slice-localization-then-organ-cropInstall 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.
Whole-body CT volumes are 80% irrelevant for any single-organ task. Feeding all 300+ slices to a 3D CNN wastes both compute and capacity on background. The fix is a two-stage pipeline: stage 1 is a tiny 2D-or-shallow-3D model that outputs per-slice "is this slice inside the organ?" probabilities; stage 2 is a real 3D classifier that only sees the cropped Z-range above threshold, resampled to a fixed (D, H, W) shape. This gives the heavy model a tight field of view, lets you reuse one stage-1 detector for all organs, and turns variable-length volumes into fixed-shape tensors.
import torch
import torch.nn.functional as F
# Stage 1: per-slice organ presence
slice_prob = slice_net(image) # (D,) probabilities
mask = slice_prob > 0.5
z = torch.where(mask)[0]
z0, z1 = (z.min().item(), z.max().item() + 1) if len(z) else (0, image.shape[0])
# Stage 2: crop, resample to fixed shape, classify
sub = image[z0:z1] # (d, H, W)
sub = F.interpolate(sub[None, None],
size=(96, 256, 256),
mode='trilinear',
align_corners=False)[0, 0]
liver_logits = liver_net(sub.unsqueeze(0))
(D, H, W)[0, D] is safer than skipping the patient.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