wenmin-wu/ds-skills/bbox-augmentation-retry-loop
Claude Code and agent skill by wenmin-wu/ds-skills
- community
Checking that the SKILL.md file is still in the repository.
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
Install
npx vskill@latest install wenmin-wu/ds-skills/bbox-augmentation-retry-loopSKILL.md
Overview
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.
Quick Start
Workflow
- Wrap the entire
self.transforms(...)call inside afor _ in range(10)loop - After each call, check
len(sample['bboxes']) > 0— if true, accept and break - If the loop exhausts without a hit, return the un-augmented original (don't raise — empty targets crash training)
- Convert albumentations' list-of-tuples bbox format to the tensor layout your model expects (xyxy, yxyx, cxcywh)
- Apply only to the training dataset — validation should always pass through un-augmented
Key Decisions
- 10 retries, not 100: any aug pipeline that fails 10 times in a row is mis-tuned (e.g., crop too small for the smallest box); silently looping forever hides the bug.
- Fall through, don't raise: a missed augmentation on one sample is fine; crashing the whole epoch is not.
- Belongs in `__getitem__`, not the collate_fn: collate runs after batching, so you'd have to redo the entire batch — wasteful.
- vs. `min_visibility` parameter:
min_visibility=0.3reduces but doesn't eliminate empty-box outcomes; the retry is the safety net. - Apply per-sample, not per-batch: identical aug across a batch is much weaker regularization.
References
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/cv/bbox-augmentation-retry-loop/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/wenmin-wu/ds-skills/bbox-augmentation-retry-loop)