training_data_source
anomaly_match.datasets.training_data_source
¶
Abstract data source for training with multiple storage backends.
Provides a TrainingDataSource ABC that decouples image loading from the
dataset labeling/splitting logic in AnomalyDetectionDataset. Concrete
implementations handle image folders, Zarr arrays, and Cutana catalogues.
DataSourceType
¶
Bases: str, Enum
Storage backend types for training data.
TrainingDataSource(cfg)
¶
Bases: ABC
Abstract base class for loading training data from various storage formats.
Each implementation handles a different storage backend (filesystem images,
Zarr arrays, Cutana catalogues). The source delivers
preprocessed numpy arrays that AnomalyDetectionDataset can label and split.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg
|
DotMap
|
AnomalyMatch configuration with normalisation settings. |
required |
Source code in anomaly_match/datasets/training_data_source.py
get_labeled_images(label_df)
abstractmethod
¶
Load images whose filenames appear in the label DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label_df
|
DataFrame
|
DataFrame with at least |
required |
Returns:
| Type | Description |
|---|---|
list[tuple[str, ndarray]]
|
List of (filename, image_array) tuples. image_array is HWC numpy, |
list[tuple[str, ndarray]]
|
already resized and normalised per cfg. |
Source code in anomaly_match/datasets/training_data_source.py
get_unlabeled_batch(n, exclude)
abstractmethod
¶
Load a batch of up to n unlabeled images.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Maximum number of images to return. |
required |
exclude
|
set[str]
|
Filenames to skip (already labeled). |
required |
Returns:
| Type | Description |
|---|---|
list[tuple[str, ndarray]]
|
List of (filename, image_array) tuples. |
Source code in anomaly_match/datasets/training_data_source.py
get_total_count()
abstractmethod
¶
detect_num_channels()
abstractmethod
¶
Detect the number of image channels from a sample.
Returns:
| Type | Description |
|---|---|
int | None
|
Number of channels, or |
int | None
|
(e.g. FITS files where channels depend on configuration). |
Source code in anomaly_match/datasets/training_data_source.py
get_last_unlabeled_sizes()
¶
Source sizes (diameters) of the most recent unlabeled batch.
Only Cutana catalogues carry a per-source size; other backends have no
such column and return None. The training subprocess uses this to
surface a size-distribution histogram of the sampled unlabeled pool.
Returns:
| Type | Description |
|---|---|
ndarray | None
|
Finite source diameters from the last |
ndarray | None
|
or |
Source code in anomaly_match/datasets/training_data_source.py
get_last_unlabeled_size_unit()
¶
Unit of :meth:get_last_unlabeled_sizes ("pixel" / "arcsec").
Returns:
| Type | Description |
|---|---|
str | None
|
The size unit, or |
Source code in anomaly_match/datasets/training_data_source.py
get_last_unlabeled_population_sizes()
¶
Candidate-population diameters of the last unlabeled batch's tiles.
The population is every source in the tiles the sampler drew from — the
baseline the training screen overlays the sampled pool against to show
whether size stratification flattened the pool. Only Cutana exposes it;
other backends return None.
Returns:
| Type | Description |
|---|---|
ndarray | None
|
Finite population diameters, or |
Source code in anomaly_match/datasets/training_data_source.py
ImageFolderSource(cfg)
¶
Bases: TrainingDataSource
Load training data from a directory of image files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg
|
DotMap
|
Configuration; |
required |
Source code in anomaly_match/datasets/training_data_source.py
all_filenames
property
¶
All discovered image filenames (shuffled).
get_labeled_images(label_df)
¶
Load all images whose filenames appear in label_df.
Returns:
| Type | Description |
|---|---|
list[tuple[str, ndarray]]
|
List of (filename, image_array) tuples for matched files. |
Source code in anomaly_match/datasets/training_data_source.py
get_unlabeled_batch(n, exclude)
¶
Load up to n images that are not in exclude.
Returns:
| Type | Description |
|---|---|
list[tuple[str, ndarray]]
|
List of (filename, image_array) tuples. |
Source code in anomaly_match/datasets/training_data_source.py
get_total_count()
¶
detect_num_channels()
¶
Auto-detect channels from a sample image.
Returns:
| Type | Description |
|---|---|
int | None
|
Number of channels detected from the first image. |
Source code in anomaly_match/datasets/training_data_source.py
create_training_data_source(cfg, *, lazy=False)
¶
Create the appropriate data source from configuration.
Uses cfg.training_data_source if set explicitly, otherwise auto-detects
from cfg.data_dir.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg
|
DotMap
|
AnomalyMatch configuration. |
required |
lazy
|
bool
|
If True, skip O(N) indexing for container sources. Labeled
images must come from a |
False
|
Returns:
| Type | Description |
|---|---|
TrainingDataSource
|
A concrete |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the source type is unknown. |