skills/cv/point-centered-fixed-patch-cropping/SKILL.md
Convert (x, y, class) point annotations into a CNN classification training set by cropping fixed-size square patches centered on each point, using a numpy shape check to silently reject border-clipped crops
npx skillsauth add wenmin-wu/ds-skills cv-point-centered-fixed-patch-croppingInstall 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.
Once you have point annotations (from dot-annotation-blob-diff-extraction or similar), the cleanest way to build a classification training set is to crop a fixed-size square patch centered on each point. The one gotcha: numpy slicing silently returns smaller arrays when the slice runs off the image edge, so img[y-h:y+h, x-h:x+h] yields a (PATCH-k, PATCH-k, 3) patch near borders without throwing. Check thumb.shape == (PATCH, PATCH, 3) before appending — it doubles as a border filter that avoids fabricating padded context.
import cv2
import numpy as np
PATCH = 32
half = PATCH // 2
X, y = [], []
for fname in file_names:
img = cv2.imread(train_dir + fname)
for cls_idx, cls in enumerate(classes):
for (cx, cy) in coords[cls][fname]:
thumb = img[cy - half:cy + half, cx - half:cx + half, :]
if thumb.shape == (PATCH, PATCH, 3): # reject border clips
X.append(thumb)
y.append(cls_idx)
X = np.stack(X); y = np.array(y)
PATCH to match the typical object diameter (32 for small sea lions, 64-128 for mid-size targets)(x, y, class) point, slice img[y-half:y+half, x-half:x+half, :]thumb.shape == (PATCH, PATCH, 3) — the check filters out any point within half pixels of the bordernp.stack at the end into a contiguous training tensornp.stack is O(N).sparse_categorical_crossentropy eats them directly and saves memory on large N.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