zarr_source
anomaly_match.datasets.zarr_source
¶
Zarr data source for training from pixel-array containers.
ZarrSource(cfg, *, lazy=False)
¶
Bases: TrainingDataSource
Load training data from one or more Zarr arrays with optional metadata.
Supports two layouts:
- Single store --
cfg.data_dirpoints directly to a.zarrdirectory containing animagesarray. - Multi-store directory --
cfg.data_dirpoints to a parent directory containing multiple.zarrstores, each with animagesarray. All stores are indexed transparently.
When lazy=True, the expensive O(N) filename index and shuffled-index
permutation are skipped. Unlabeled sampling uses random (store, index)
generation instead. Labeled images must come from a LabeledDataCache,
not from this source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg
|
DotMap
|
Configuration; |
required |
lazy
|
bool
|
If True, skip O(N) indexing for billion-scale sources. |
False
|
Source code in anomaly_match/datasets/zarr_source.py
get_labeled_images(label_df)
¶
Load images for filenames present in label_df.
Not available in lazy mode -- use a LabeledDataCache instead.
Returns:
| Type | Description |
|---|---|
list[tuple[str, ndarray]]
|
List of (filename, image_array) tuples. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If called in lazy mode. |
Source code in anomaly_match/datasets/zarr_source.py
get_unlabeled_batch(n, exclude=None, exclude_positions=None)
¶
Load up to n unlabeled images.
In normal mode, skips filenames in exclude. In lazy mode, skips
(store_idx, local_idx) pairs in exclude_positions using
random sampling without a pre-computed permutation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Maximum number of images to return. |
required |
exclude
|
set[str] | None
|
Filenames to skip (normal mode). |
None
|
exclude_positions
|
set[tuple[int, int]] | None
|
|
None
|
Returns:
| Type | Description |
|---|---|
list[tuple[str, ndarray]]
|
List of (filename, image_array) tuples. |
Source code in anomaly_match/datasets/zarr_source.py
get_total_count()
¶
Return total number of images across all Zarr stores.
Returns:
| Type | Description |
|---|---|
int
|
Image count. |
detect_num_channels()
¶
Infer channel count from the first store's array shape.
Returns:
| Type | Description |
|---|---|
int | None
|
Number of channels, or |