skills/cv/multi-scale-patch-training-pyramid/SKILL.md
Generate count-regression training patches at a geometric pyramid of image scales (0.9^k) so one CNN handles within- and between-image object-size variation without explicit anchors
npx skillsauth add wenmin-wu/ds-skills cv-multi-scale-patch-training-pyramidInstall 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.
Aerial-imagery count datasets suffer from inter-image scale drift — different flights, altitudes, and zoom levels produce the same objects at different pixel sizes. Random rescale augmentation helps but is unprincipled; the deterministic fix is a geometric scale pyramid: for each training image, resize at [1.0, 0.9, 0.81, 0.729, 0.656], rebuild the patch/label grid at each scale, tile, and pool everything into one training set. The CNN then sees the same object instances at every reasonable size and learns a size-invariant mapping. Used alongside patch-grid count regression to win on NOAA Steller Sea Lion.
import cv2
import numpy as np
PATCH = 300
SCALES = [0.9 ** k for k in range(5)] # 1.0, 0.9, 0.81, 0.729, 0.656
patches, labels = [], []
for r in SCALES:
img_r = cv2.resize(img, None, fx=r, fy=r)
grid = build_count_grid(points, scale=r, patch=PATCH, n_classes=n_classes)
h, w = img_r.shape[:2]
for i in range(w // PATCH):
for j in range(h // PATCH):
y = grid[i, j]
x = img_r[j*PATCH:(j+1)*PATCH, i*PATCH:(i+1)*PATCH]
if y.sum() > 0 or np.random.rand() < 0.25: # 1:3 pos:neg
patches.append(x); labels.append(y)
0.9^k for k ∈ [0..4]) covering the expected size rangePATCH × PATCH patches; keep every positive and ~25% of negatives(patches, labels) training set and shuffle0.9^k gives perceptually uniform steps; linear steps crowd the small end.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