技能创建器
skill-creator
创建、改进和评估自定义技能,把专业流程转化为可重复使用的 AI 能力。
framework-integration【数据与研究】Integrate Albumentations with PyTorch-style datasets, tensor conversion, optional extras, and DataLoader reproducibility.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Use this sub-skill when a task involves PyTorch dataset integration, tensor outputs, optional framework extras, or errors importing ToTensorV2 / ToTensor3D.
torch.utils.data.Dataset.__getitem__ while keeping augmentation before tensor conversion.ToTensorV2 or ToTensor3D.pip install albumentations[pytorch], albumentations[hub], and albumentations[text] optional dependencies.A.ToTensorV2, HWC/CHW confusion, mask transposition, Normalize ordering, dtype/range issues, or DataLoader worker reproducibility.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.Compose, ReplayCompose, strict, additional_targets, and seed mechanics beyond PyTorch workers, use ../pipeline-composition/.../transform-catalog/.../targets-and-formats/.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
pip install "albumentations[pytorch]" or install compatible torch separately.H,W,C images, H,W or H,W,C masks, and D,H,W[,C] volumes until the final tensor transform.Normalize before ToTensorV2; ToTensorV2 does not scale or normalize values by itself.transpose_mask=True only when channel-first masks are expected by downstream code.ToTensorV2 converts image/mask targets, not bbox/keypoint lists.