framework-integration
Integrate Albumentations with PyTorch-style datasets, tensor conversion, optional extras, and DataLoader reproducibility.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- framework-integration
- license
- MIT
- metadata
- { "disco-role": "operating" }
- description
- Integrate Albumentations with PyTorch-style datasets, tensor conversion, optional extras, and DataLoader reproducibility.
- disable-model-invocation
- true
02 资源文件 4
- 参考文档references/optional-dependencies.md3.5 KB
- 参考文档references/pytorch-integration.md5.9 KB
- 参考文档references/troubleshooting.md4.6 KB
- 脚本scripts/pytorch_dataset_template.py4.8 KB
03 SKILL.md 正文
Framework Integration
Use this sub-skill when a task involves PyTorch dataset integration, tensor outputs, optional framework extras, or errors importing ToTensorV2 / ToTensor3D.
Route Here For
- Adding Albumentations to a
torch.utils.data.Dataset.__getitem__while keeping augmentation before tensor conversion. - Fixing image, mask, batch, or volume tensor shapes produced by
ToTensorV2orToTensor3D. - Explaining
pip install albumentations[pytorch],albumentations[hub], andalbumentations[text]optional dependencies. - Debugging missing
A.ToTensorV2, HWC/CHW confusion, mask transposition,Normalizeordering, dtype/range issues, or DataLoader worker reproducibility.
Start With These References
references/pytorch-integration.md: PyTorch dataset placement,ToTensorV2,ToTensor3D, shapes, dtypes, normalization, bboxes/keypoints, and worker seeding.references/optional-dependencies.md: Optional extras, import checks, and safe install guidance for PyTorch, Hub, and text features.references/troubleshooting.md: Symptom-to-fix playbooks for import, shape, dtype/range, mask, and reproducibility failures.scripts/pytorch_dataset_template.py: A tiny self-contained template/checker for dataset-style Albumentations pipelines.
Boundaries
- For
Compose,ReplayCompose,strict,additional_targets, and seed mechanics beyond PyTorch workers, use../pipeline-composition/. - For selecting transforms such as crops, flips, color, dropout, or text augmentations, use
../transform-catalog/. - For bbox/keypoint coordinate formats, labels, volumes, and target validation contracts, use
../targets-and-formats/. - Keep model training loops, loss functions, optimizers, schedulers, and framework-specific trainer code out of scope unless they affect augmentation placement or returned sample format.
Minimal Pattern
import albumentations as A
from albumentations.pytorch import ToTensorV2
train_transform = A.Compose(
[
A.Resize(256, 256),
A.HorizontalFlip(p=0.5),
A.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)),
ToTensorV2(),
],
strict=True,
)
sample = train_transform(image=image_np, mask=mask_np)
image_tensor = sample["image"] # C,H,W torch.Tensor
mask_tensor = sample["mask"] # H,W torch.Tensor unless transpose_mask=True
Checklist
- Install PyTorch support explicitly when tensor transforms are needed:
pip install "albumentations[pytorch]"or install compatibletorchseparately. - Keep Albumentations inputs as NumPy arrays in
H,W,Cimages,H,WorH,W,Cmasks, andD,H,W[,C]volumes until the final tensor transform. - Put
NormalizebeforeToTensorV2;ToTensorV2does not scale or normalize values by itself. - Use
transpose_mask=Trueonly when channel-first masks are expected by downstream code. - Return bbox/keypoint values from Albumentations as metadata/list fields;
ToTensorV2converts image/mask targets, not bbox/keypoint lists.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).