Cache loader
cache_loader(sample, path_imagedir=None, image_format=None, grayscale=False, two_dim=True, cache=None, **kwargs)
ยค
Cache Loader for passing already loaded images within the AUCMEDI pipeline.
The Cache Loader is an IO_loader function, which have to be passed to the DataGenerator.
The complete data management happens in the memory. Thus, for multiple images or common data set sizes, this is NOT recommended!
Warning
This functions requires to pass a Dictionary to the parameter cache
!
Dictionary structure: key=index as String; value=Image as NumPy array
e.g. cache = {"my_index_001": my_image}
Example
# Import required libraries
from aucmedi import *
from aucmedi.data_processing.io_loader import cache_loader
# Encode information as dictionary
cache = {"sample_a": image_a,
"sample_b": image_b,
"sample_n": image_n}
# Obtain meta data
my_labels = [[1,0], [0,1], [1,0]] # one-hot encoded annotation matrix
sample_list = cache.keys()
# Initialize DataGenerator
data_gen = DataGenerator(sample_list, None, labels=my_labels,
resize=None, grayscale=False, two_dim=True,
loader=cache_loader, cache=cache)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample |
str
|
Sample name/index of an image. |
required |
path_imagedir |
str
|
Path to the directory containing the images. |
None
|
image_format |
str
|
Image format to add at the end of the sample index for image loading. |
None
|
grayscale |
bool
|
Boolean, whether images are grayscale or RGB. |
False
|
two_dim |
bool
|
Boolean, whether image is 2D or 3D. |
True
|
cache |
dict
|
A Python dictionary containing one or multiple images. |
None
|
**kwargs |
dict
|
Additional parameters for the sample loader. |
{}
|
Source code in aucmedi/data_processing/io_loader/cache_loader.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
|