skills/cv/prediction-map-stitching-averaging/SKILL.md
Stitch overlapping tile predictions into a full-resolution output by accumulating probabilities and dividing by per-pixel overlap counts
npx skillsauth add wenmin-wu/ds-skills cv-prediction-map-stitching-averagingInstall 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 running patch-based inference on large images, overlapping tiles produce multiple predictions for each pixel. Instead of taking the last prediction, accumulate all predictions into a sum array and maintain a parallel count array. Dividing sum by count produces a smooth, averaged prediction map that reduces tile-boundary artifacts.
import numpy as np
import torch
def stitch_predictions(predictions, xyxys, output_shape):
pred_map = np.zeros(output_shape, dtype=np.float32)
count_map = np.zeros(output_shape, dtype=np.float32)
for pred, (x1, y1, x2, y2) in zip(predictions, xyxys):
pred_map[y1:y2, x1:x2] += pred.squeeze()
count_map[y1:y2, x1:x2] += 1.0
count_map = np.maximum(count_map, 1.0)
return pred_map / count_map
# During inference loop:
all_preds, all_xyxys = [], []
for images, coords in test_loader:
with torch.no_grad():
preds = torch.sigmoid(model(images.cuda())).cpu().numpy()
all_preds.extend(preds)
all_xyxys.extend(coords)
result = stitch_predictions(all_preds, all_xyxys, (H, W))
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