Datasets and readers
Use this sub-skill when a user needs to turn imaging files or tabular labels
into a nitrain.Dataset, infer a reader from nested Python objects, load the
built-in example fixture, or connect a dataset to Google Cloud storage.
What belongs here
Datasetcreation from local filesystem paths or in-memory objects.- Reader selection for image files, CSV/TSV columns, folder names, nested
reader composition, and automatic inference.
fetch_data('example-01')and the local tiny fixture it creates.GoogleCloudDatasetand reader behavior that depends on cloud storage.
What does not belong here
- Transforms, samplers,
Loader, or Keras batching: use
sub-skills/preprocessing-and-loading/.
- Architectures, trainers, pretrained weights, or framework training logic: use
sub-skills/models-training/.
- Prediction and explanation post-processing: use
sub-skills/prediction-and-explanation/.
Typical user requests
- "Build a dataset from images and participants.csv"
- "Read labels from folder names"
- "Infer readers from nested lists or dictionaries"
- "Create the example-01 fixture"
- "Use GoogleCloudDataset for a bucket-backed dataset"
Working pattern
- Decide whether the input source is local files, in-memory data, or Google
Cloud storage.
- Pick the smallest reader that matches the data shape.
- Use
base_dirfor directory-relative files andbase_filefor CSV/TSV
columns.
- Use
infer_reader()when the user already has nested lists, arrays, or
dictionaries and does not want to spell out reader classes manually.
- Keep output labels explicit so later transforms and samplers can route by
name.
Read these references
- references/api-reference.md for verified
constructor signatures and return behavior.
- references/workflows.md for canonical
dataset-building patterns and example snippets.
- references/troubleshooting.md for missing
files, mismatched lengths, malformed patterns, and GCS credential issues.
Smoke check
After installing dependencies, run the bundled helper scripts/check_install.py:
python scripts/check_install.py --mode datasets
Use this when you want to confirm the reader and dataset surface before moving
on to preprocessing or training.
Key decision points
- Use
ImageReaderfor file patterns that should resolve to ANTs images. - Use
ColumnReaderfor scalar labels or image paths stored in a table. - Use
FolderNameReaderwhen folder names carry labels or classes. - Use
MemoryReaderwhen data is already in memory. - Use
ComposeReaderfor multiple inputs that should stay aligned. - Use
GoogleCloudDatasetonly when bucket access and credentials are real.
Common outcomes
Dataset.__getitem__returns(x, y)pairs, and slices return sequences.Dataset.split()returns train/test or train/test/val partitions.ImageReader,ColumnReader,FolderNameReader, andMemoryReaderall
support select() for subset reuse.
Watch for these signals
- "No file found" or "No filepaths found" usually means the pattern, base
path, or exclude filter is wrong.
- Length mismatch warnings mean the reader mappings did not align.
- GCS failures usually come from credentials or object-path errors, not from
the core Nitrain API.
Before handing off
If the request grows into sampling, augmentation, batching, or model training,
hand off to the relevant sibling sub-skill instead of expanding this one.