Skip to content

data_utils

Utility functions needed by dataloader & co.

adjust_for_imbalance_in_fraction_value(val, test, val_fraction, test_fraction, total_size) #

here, val and test are divided almost equally. Here, we need to take into account their respective fractions and pick elements rendomly from one array and put in the other array.

Source code in src/careamics/lvae_training/dataset/utils/data_utils.py
def adjust_for_imbalance_in_fraction_value(
    val: List[int],
    test: List[int],
    val_fraction: float,
    test_fraction: float,
    total_size: int,
):
    """
    here, val and test are divided almost equally. Here, we need to take into account their respective fractions
    and pick elements rendomly from one array and put in the other array.
    """
    if val_fraction == 0:
        test += val
        val = []
    elif test_fraction == 0:
        val += test
        test = []
    else:
        diff_fraction = test_fraction - val_fraction
        if diff_fraction > 0:
            imb_count = int(diff_fraction * total_size / 2)
            val = list(np.random.RandomState(seed=955).permutation(val))
            test += val[:imb_count]
            val = val[imb_count:]
        elif diff_fraction < 0:
            imb_count = int(-1 * diff_fraction * total_size / 2)
            test = list(np.random.RandomState(seed=955).permutation(test))
            val += test[:imb_count]
            test = test[imb_count:]
    return val, test

load_tiff(path) #

Returns a 4d numpy array: num_imgshw*num_channels

Source code in src/careamics/lvae_training/dataset/utils/data_utils.py
def load_tiff(path):
    """
    Returns a 4d numpy array: num_imgs*h*w*num_channels
    """
    data = imread(path, plugin="tifffile")
    return data