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.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- data-preparation
- license
- MIT
- metadata
- { "disco-role": "operating" }
- description
- Prepare and route BigGAN-PyTorch ImageFolder, CIFAR10/CIFAR100, ImageNet HDF5, and Inception-moment data with the repository's exact mappings, transforms, and resource safeguards.
- disable-model-invocation
- true
02 资源文件 4
- 参考文档references/data-formats.md4.6 KB
- 参考文档references/troubleshooting.md5.9 KB
- 参考文档references/workflows.md5.8 KB
- 脚本scripts/validate_hdf5.py4.7 KB
03 SKILL.md 正文
BigGAN-PyTorch data preparation
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.
Safety and route selection
- ImageNet downloads and dataset acquisition are network-dependent and
expensive. Do not download ImageNet or CIFAR implicitly as a smoke test.
CIFAR's torchvision download is also network-dependent; use
download=Falseonly after the archive has been installed and verified. - HDF5 conversion is expensive. It reads every source image, writes a
potentially very large file, and consumes substantial time and disk. The
repository's
scripts/utils/prepare_data.shis a recipe, not a safe smoke test. Inspect with--helpor use the bundled metadata-only validator before approving a conversion. - Inception moments require CUDA in the source implementation.
calculate_inception_moments.pyhard-codesdevice = 'cuda', walks the full dataset, and accumulates activations in host RAM. It is a full metric job, not a quick validation. - Choose one representation and make its data root explicit:
I32,I64,I128, orI256: ImageFolder/ImageNet directories.I32_hdf5,I64_hdf5,I128_hdf5, orI256_hdf5: preprocessedILSVRC_HDF5files.C10orC100: 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.
Canonical command sequence
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.
Loader behavior that must be preserved
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.
- ImageFolder data is decoded as RGB with PIL (or accimage when selected by
torchvision), then transformed. Supported suffixes are
.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.npzin the process's current working directory; remove the cache after changing classes or files. - CIFAR10 and CIFAR100 are read from torchvision-style pickle archives. Each
sample becomes a PIL image before the configured transform. Both are native
32x32;
C10has 10 classes andC100has 100. The custom CIFAR loader reads the archive arrays into memory regardless of itsload_in_memargument.val_splitandtrain='validate'are supported by the class but are not exposed by the normalget_data_loadersconvenience call. - HDF5 samples are stored as NCHW uint8 and are converted by
ILSVRC_HDF5to float tensors with((pixel / 255) - 0.5) * 2, i.e. approximately[-1, 1]. The HDF5 loader intentionally ignores the torchvisiontransformargument;--augmenttherefore does not add random crops or flips to an_hdf5dataset.
Transform and resource decisions
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:
- ImageFolder decodes and transforms every image during dataset construction and retains the transformed samples and labels. If the transform is random, its random crop/flip is sampled once at construction rather than anew each epoch. This is fast but can consume far more RAM than the compressed source.
- HDF5 loads both
imgsandlabelsarrays 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. - More
num_workerscan hide image decode/I/O latency, but each worker adds process overhead and HDF5 access pressure. Start HDF5 with0or a small worker count, then increase only after measuring.pin_memoryimproves 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.
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).