image_cache
anomaly_match.prediction.image_cache
¶
Least Recently Used (LRU) image cache for on-demand loading of prediction source images.
Images are loaded from disk using the same fitsbolt pipeline used during training, ensuring visual consistency between training and prediction views.
ImageCache(cfg, search_dir, cache_size=200)
¶
LRU cache that loads source images on demand.
Keeps up to cache_size images in memory. When the cache is full the least-recently-used entry is evicted. Images are loaded from search_dir using the fitsbolt pipeline configured in cfg.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg
|
DotMap
|
Configuration object with |
required |
search_dir
|
str
|
Root directory to search for image files. |
required |
cache_size
|
int
|
Maximum number of images to keep in memory. |
200
|
Source code in anomaly_match/prediction/image_cache.py
size
property
¶
Return number of currently cached images.
Returns:
| Type | Description |
|---|---|
int
|
Current cache occupancy. |
max_size
property
¶
Return maximum cache capacity.
Returns:
| Type | Description |
|---|---|
int
|
Maximum number of images the cache can hold. |
get_image(filename)
¶
Return the image for filename, loading from disk if needed.
On cache hit the entry is promoted to most-recently-used. On
cache miss the image is loaded via fitsbolt's
load_and_process_single_wrapper and inserted into the cache,
evicting the LRU entry if the cache is full.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Source filename (basename or relative path). |
required |
Returns:
| Type | Description |
|---|---|
ndarray | None
|
HWC uint8 numpy array, or |
ndarray | None
|
loaded. |
Source code in anomaly_match/prediction/image_cache.py
prefetch(filenames)
¶
Pre-load a batch of images into the cache.
Already-cached filenames are skipped.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filenames
|
list[str]
|
List of filenames to pre-load. |
required |
Source code in anomaly_match/prediction/image_cache.py
put(filename, image)
¶
Manually insert an image into the cache.
Useful for caching images loaded via alternative paths (e.g.
Cutana cutouts) that bypass get_image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Cache key. |
required |
image
|
ndarray
|
HWC uint8 numpy array. |
required |