elektronn3.data.utils module¶
- elektronn3.data.utils.calculate_class_weights(targets, mode='inverse')[source]¶
Calulate class weights that assign more weight to less common classes.
The weights can then be used for loss function rebalancing (e.g. for CrossEntropyLoss it’s very important to do this when training on datasets with high class imbalance.
- Return type:
ndarray
- elektronn3.data.utils.calculate_nd_slice(src, coords_lo, coords_hi)[source]¶
Calculate the
slice
object list that is used as indices for reading from a data source.Unfortunately, this kind of slice list is not yet supported by h5py. It only works with numpy arrays.
- elektronn3.data.utils.get_class_counts(targets)[source]¶
Get a dict that maps each target class to its number of labeled pixels/voxels
- Return type:
Dict
[int
,str
]
- elektronn3.data.utils.save_to_h5(data, path, hdf5_names=None, overwrite=False, compression=True)[source]¶
Saves data to HDF5 File.
- Parameters:
data (list or dict of np.arrays) – if list, hdf5_names has to be set.
path (str) – forward-slash separated path to file
hdf5_names (list of str) – has to be the same length as data
overwrite (bool) – determines whether existing files are overwritten
compression (bool) – True: compression=’gzip’ is used which is recommended for sparse and ordered data
- Return type:
nothing