dataset-loading
Load, inspect, and validate MedMNIST 2D and 3D datasets from local NPZ files with the standard split, size, metadata, and transform contracts.
- License 许可
- Apache-2.0
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- dataset-loading
- license
- Apache 2.0
- metadata
- { "disco-role": "operating" }
- description
- Load, inspect, and validate MedMNIST 2D and 3D datasets from local NPZ files with the standard split, size, metadata, and transform contracts.
- disable-model-invocation
- true
02 资源文件 6
- 参考文档references/api-reference.md5.5 KB
- 参考文档references/data-formats.md6.1 KB
- 参考文档references/no-pytorch.md4.1 KB
- 参考文档references/troubleshooting.md5.8 KB
- 参考文档references/workflows.md5.8 KB
- 脚本scripts/npz_without_pytorch.py10.9 KB
03 SKILL.md 正文
MedMNIST dataset loading
Use this sub-skill for installing or importing MedMNIST, choosing one of the 18
registered subsets, reading INFO, loading a local NPZ, selecting train,
val, or test, using MedMNIST+ resolutions, controlling mmap_mode,
converting grayscale images to RGB, applying transforms, and consuming the
standardized arrays without PyTorch.
Route before acting
- Read the API reference before choosing a class, split, size, or expected return type.
- Read the data format reference before opening an NPZ directly or building a fixture.
- Follow the normal workflows for installation, metadata inspection, local loading, and deterministic smoke checks.
- Use the no-PyTorch guide and the bundled NPZ inspection script when torch is not wanted.
- Use troubleshooting for missing roots/files, invalid arguments, broken NPZ keys, and download recovery.
Do not use this sub-skill for evaluator metrics, result CSV parsing/naming,
figure export, or montage generation. Route those requests to the sibling
evaluation-and-export sub-skill. Do not
teach model training, bulk downloads, or clinical decisions.
Operating procedure
- Install or verify the package. Run
python -m pip install medmnistin the caller's selected environment, then verify with:python -c "import medmnist; print(medmnist.__version__)". The expected inspected release is3.0.2. Do not silently install a second environment. - Choose a registry flag. Inspect
medmnist.INFOand select an exact lowercase flag such aspathmnistororganmnist3d; do not infer a class from a filename alone. There are 18 registry entries, with 12 2D and 6 3D subsets. See the complete table in the API reference. - Inspect metadata before interpreting labels. Use
INFO[flag]["task"],INFO[flag]["label"],n_channels,n_samples, andlicense. Labels are not uniformly multiclass: tasks include binary, multiclass, multilabel, and ordinal regression. - Create the root explicitly.
rootmust be an existing directory. For a controlled run useroot = Path("./medmnist-data")and callroot.mkdir(parents=True, exist_ok=True)before construction. The package does not create an arbitrary missing caller-provided root. - Load one split and one size. Construct the class named in
INFOwith a requiredsplitoftrain,val, ortest.size=Noneandsize=28select the 28 variant. 2D accepts 28, 64, 128, 224; 3D accepts 28, 64. Dataset files are named<flag>.npzfor 28 and<flag>_<size>.npzfor larger variants. - Check one sample before downstream use. For 2D, expect a PIL image and
an integer NumPy target. For 3D, expect a normalized channel-first NumPy
array and an integer NumPy target. Check
len(dataset),dataset.imgs.shape,dataset.labels.shape, and the first sample's type/shape. - Use local files by default.
download=Falseis the safe default. To use automatic download, passdownload=Trueonly with an existing writable root and an intentional network approval; the official source is Zenodo. For offline checks, use a local NPZ or the bundled no-PyTorch fixture mode. - Use
mmap_modedeliberately. The constructor forwards the value tonumpy.load;mmap_mode="r"is useful for large arrays. Check the resulting array type and actual access behavior rather than assuming every NPZ member is a livememmap. - Keep labels task-aware. Every standard label array is
N x L. Preserve the target vector and consultINFObefore converting it to a scalar, one-hot vector, threshold, or ordinal value.
Canonical commands
List registry entries and metadata without downloading:
python - <<'PY'
import medmnist
from medmnist.info import INFO
print(medmnist.__version__)
print(len(INFO), sorted(INFO))
print(INFO["pathmnist"]["task"], INFO["pathmnist"]["n_channels"])
PY
Expected output starts with 3.0.2, then 18, includes pathmnist, and prints
multi-class 3 for the final line. Load an already-present file:
mkdir -p ./medmnist-data
python - <<'PY'
from medmnist import PathMNIST
ds = PathMNIST(split="train", root="./medmnist-data", size=28,
download=False, mmap_mode="r")
image, target = ds[0]
print(len(ds), type(image).__name__, image.size, image.mode,
target.shape, target.dtype)
PY
The command succeeds only if ./medmnist-data/pathmnist.npz exists; otherwise
follow troubleshooting, not a blind retry.
For a no-download synthetic check covering both 2D and 3D return contracts, run these commands (the fixture is temporary and contains no real medical data):
python scripts/npz_without_pytorch.py --fixture 2d --split train --size 28 --as-rgb --mmap-mode r
python scripts/npz_without_pytorch.py --fixture 3d --split test --size 28 --as-rgb --mmap-mode r
Each command prints the six-key schema, the selected split, size=28, and a
sample shape of (28, 28, 3) for 2D or (3, 28, 28, 28) for 3D, with a target
shape of (1,). See the script guide for the
expected output and local-NPZ form.
Return handoff
When handing a loading result to another sub-skill, report: package version;
flag and class; root and exact NPZ filename; split and size; download and
mmap_mode; NPZ keys and image/label shapes; task and label interpretation;
2D/3D sample type and shape; RGB and transform choices; checks run; and any
missing file, backend, or data-quality limitation. State explicitly when a
synthetic fixture was used instead of official data.
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).