skills/cv/bbox-augmentation-retry-loop/SKILL.md
Wrap albumentations bbox transforms in a 10-attempt retry loop that re-rolls the augmentation when all boxes get cropped out, preventing empty-target samples from poisoning the detection loss with NaN gradients
npx skillsauth add wenmin-wu/ds-skills cv-bbox-augmentation-retry-loopInstall 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.
Albumentations' bbox-aware transforms (RandomCrop, RandomSizedBBoxSafeCrop, big rotations) silently drop bounding boxes that fall outside the new canvas. For dense scenes this is fine, but for sparse-label data — one or two boxes per image — a single unlucky crop wipes the entire ground truth and you feed an "image with no targets" into a detector that expects at least one box. EfficientDet, FasterRCNN, and YOLO all behave badly on empty targets: silent NaN losses, KL collapse, or skipped batches that bias the optimizer. The fix is a 10-iteration retry loop: rerun the transform until at least one box survives, fall through to the un-augmented sample as a last resort.
def __getitem__(self, idx):
image, target, labels = self._load(idx)
if self.transforms is not None:
for _ in range(10): # up to 10 attempts
sample = self.transforms(
image=image,
bboxes=target['boxes'],
labels=labels,
)
if len(sample['bboxes']) > 0: # at least one box survived
image = sample['image']
boxes = torch.stack(
tuple(map(torch.tensor, zip(*sample['bboxes'])))
).permute(1, 0)
# xyxy -> yxyx for EfficientDet (skip if your model uses xyxy)
boxes[:, [0, 1, 2, 3]] = boxes[:, [1, 0, 3, 2]]
target['boxes'] = boxes
break
# else: fall through with the un-augmented image+target
return image, target, labels
self.transforms(...) call inside a for _ in range(10) looplen(sample['bboxes']) > 0 — if true, accept and break__getitem__, not the collate_fn: collate runs after batching, so you'd have to redo the entire batch — wasteful.min_visibility parameter: min_visibility=0.3 reduces but doesn't eliminate empty-box outcomes; the retry is the safety net.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