技能创建器
skill-creator
创建、改进和评估自定义技能,把专业流程转化为可重复使用的 AI 能力。
data-preparation【数据与研究】Prepare and route BigGAN-PyTorch ImageFolder, CIFAR10/CIFAR100, ImageNet HDF5, and Inception-moment data with the repository's exact mappings, transforms, and resource safeguards.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Use this sub-skill when preparing a dataset for train.py, building an
ImageNet HDF5 cache, checking a cache, or generating the reference Inception
moments used by FID. This is runtime guidance for the checked-out
BigGAN-PyTorch repository. Run repository commands from the repository root;
invoke bundled helpers through the root skill directory, and keep large data
and metric outputs in an explicit data/output location.
Set SKILL_ROOT to the directory containing the root SKILL.md and
REPO_ROOT to the BigGAN-PyTorch checkout before using the commands below.
download=False only after the archive has been installed and verified.scripts/utils/prepare_data.sh is a recipe, not a safe smoke
test. Inspect with --help or use the bundled metadata-only validator
before approving a conversion.calculate_inception_moments.py hard-codes device = 'cuda', walks the full
dataset, and accumulates activations in host RAM. It is a full metric job,
not a quick validation.I32, I64, I128, or I256: ImageFolder/ImageNet directories.I32_hdf5, I64_hdf5, I128_hdf5, or I256_hdf5: preprocessed
ILSVRC_HDF5 files.C10 or C100: the repository's CIFAR loaders at native 32x32.Read references/data-formats.md for schemas and root mappings,
references/workflows.md for command sequences and resource choices, and
references/troubleshooting.md for failure diagnosis. The references are
relative to this data-preparation sub-skill directory. Use the validator via
$SKILL_ROOT/sub-skills/data-preparation/scripts/validate_hdf5.py so the
command remains resolvable when copied from the skill root.
From the checkout, after an ImageNet tree has been deliberately provisioned
under data/ImageNet, the README's default 128px recipe is:
python make_hdf5.py --dataset I128 --batch_size 256 --data_root data
python calculate_inception_moments.py --dataset I128_hdf5 --data_root data
The first command creates data/ILSVRC128.hdf5; the second reads that file
and writes I128_inception_moments.npz in the current working directory.
The recipe does not download ImageNet. Confirm free disk, RAM, CUDA, and
whether the output moment file should instead be moved to the configured
metrics root before starting either expensive command.
For a small, already-installed dataset, first inspect a loader or run a
one-batch diagnostic with num_workers=0, then scale batch_size and workers.
Do not claim a full data-preparation verification from --help alone.
utils.get_data_loaders() appends root_dict[dataset] to data_root, builds
one training DataLoader, and returns it in a one-element list. The dataset
key controls resolution, class count, root name, and model metadata. Use
--shuffle for training unless deliberately reproducing ordered traversal;
drop_last=True is the default in normal loader use. pin_memory is enabled
by default and can be disabled with --no_pin_memory.
.jpg, .jpeg,
.png, .ppm, .bmp, and .pgm. Class directories and nested image files
are traversed in sorted order, so classes receive stable lexicographic
indices. An index listing is cached as <dataset>_imgs.npz in the process's
current working directory; remove the cache after changing classes or files.C10 has 10 classes and C100 has 100. The custom CIFAR loader reads
the archive arrays into memory regardless of its load_in_mem argument.
val_split and train='validate' are supported by the class but are not
exposed by the normal get_data_loaders convenience call.ILSVRC_HDF5 to float tensors with ((pixel / 255) - 0.5) * 2, i.e.
approximately [-1, 1]. The HDF5 loader intentionally ignores the
torchvision transform argument; --augment therefore does not add random
crops or flips to an _hdf5 dataset.For non-HDF5 ImageNet, no augmentation means center-crop the shorter square
from the image's long-edge geometry, resize to the selected resolution, then
ToTensor() and normalize each channel with mean/std [0.5, 0.5, 0.5].
With --augment, use a random long-edge square crop, resize to the selected
resolution, and random horizontal flip before the same tensor conversion and
normalization. CIFAR without augmentation applies only tensor conversion and
that normalization; CIFAR augmentation is RandomCrop(32, padding=4) plus
RandomHorizontalFlip().
Run the bundled checker from the repository root as
python "$SKILL_ROOT/sub-skills/data-preparation/scripts/validate_hdf5.py" "$REPO_ROOT/data/ILSVRC128.hdf5" --resolution 128 --check-label-range;
it is metadata-only unless label range checking is requested.
--load_in_mem has different practical consequences:
imgs and labels arrays into RAM. Omitting it causes the
loader to open the HDF5 file and read the requested sample for each
__getitem__; this saves RAM but can make I/O and multi-worker behavior
slower. The README reports roughly a 64GB I128 file and recommends about
96GB+ RAM for the training recipe that loads it.num_workers can hide image decode/I/O latency, but each worker adds
process overhead and HDF5 access pressure. Start HDF5 with 0 or a small
worker count, then increase only after measuring. pin_memory improves
host-to-CUDA transfer at the cost of pinned host memory.For a custom dataset, add a loader in datasets.py and keep dset_dict,
imsize_dict, root_dict, nclass_dict, and classes_per_sheet_dict in
utils.py synchronized. Verify root, image size, channels, class ids, and
normalization before training or moments generation.