How to use the batchgenerators.transforms.AbstractTransform function in batchgenerators

To help you get started, we’ve selected a few batchgenerators examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github delira-dev / delira / delira / data_loading / numba_transform.py View on Github external
from batchgenerators.transforms import AbstractTransform, Compose

import logging
from delira import get_current_debug_mode
import numba

logger = logging.getLogger(__name__)


class NumbaTransformWrapper(AbstractTransform):
    def __init__(self, transform: AbstractTransform, nopython=True,
                 target="cpu", parallel=False, **options):

        if get_current_debug_mode():
            # set options for debug mode
            logging.debug("Debug mode detected. Overwriting numba options "
                          "nopython to False and target to cpu")
            nopython = False
            target = "cpu"

        transform.__call__ = numba.jit(transform.__call__, nopython=nopython,
                                       target=target,
                                       parallel=parallel, **options)
        self._transform = transform

    def __call__(self, **kwargs):
github delira-dev / delira / delira / data_loading / data_manager.py View on Github external
def transforms(self, new_transforms):
        """
        Setter for data transforms, assert if transforms are of valid type
        (either None or instance of ``AbstractTransform``)

        Parameters
        ----------
        new_transforms : None, ``AbstractTransform``
            the new transforms

        """

        if new_transforms is not None or isinstance(new_transforms,
                                                    AbstractTransform):
            raise TypeError

        self._transforms = new_transforms
github MIC-DKFZ / RegRCNN / datasets / prostate / data_loader.py View on Github external
:param shape: target shape, bcxyz or bczyx
    """
    shp = data_dict['orig_shape_data']
    cur_shape = data_dict['data'].shape
    seg_shp = data_dict['orig_shape_seg']
    cur_shape_seg = data_dict['seg'].shape
    
    data_dict['data'] = data_dict['data'].reshape((shp[0], shp[1], shp[2], cur_shape[-2], cur_shape[-1]))
    data_dict['seg'] = data_dict['seg'].reshape((seg_shp[0], seg_shp[1], seg_shp[2], cur_shape_seg[-2], cur_shape_seg[-1]))
    
    if shape=="bcxyz":
        data_dict['data'] = np.transpose(data_dict['data'], axes=(0,1,4,3,2))
        data_dict['seg'] = np.transpose(data_dict['seg'], axes=(0,1,4,3,2)) 
    return data_dict

class Convert3DTo2DTransform(AbstractTransform):
    def __init__(self):
        pass

    def __call__(self, **data_dict):
        return convert_3d_to_2d_generator(data_dict)

class Convert2DTo3DTransform(AbstractTransform):
    def __init__(self):
        pass

    def __call__(self, **data_dict):
        return convert_2d_to_3d_generator(data_dict)

def vector(item):
    """ensure item is vector-like (list or array or tuple)
    :param item: anything
github MIC-DKFZ / RegRCNN / datasets / prostate / data_loader.py View on Github external
data_dict['data'] = data_dict['data'].reshape((shp[0], shp[1], shp[2], cur_shape[-2], cur_shape[-1]))
    data_dict['seg'] = data_dict['seg'].reshape((seg_shp[0], seg_shp[1], seg_shp[2], cur_shape_seg[-2], cur_shape_seg[-1]))
    
    if shape=="bcxyz":
        data_dict['data'] = np.transpose(data_dict['data'], axes=(0,1,4,3,2))
        data_dict['seg'] = np.transpose(data_dict['seg'], axes=(0,1,4,3,2)) 
    return data_dict

class Convert3DTo2DTransform(AbstractTransform):
    def __init__(self):
        pass

    def __call__(self, **data_dict):
        return convert_3d_to_2d_generator(data_dict)

class Convert2DTo3DTransform(AbstractTransform):
    def __init__(self):
        pass

    def __call__(self, **data_dict):
        return convert_2d_to_3d_generator(data_dict)

def vector(item):
    """ensure item is vector-like (list or array or tuple)
    :param item: anything
    """
    if not isinstance(item, (list, tuple, np.ndarray)):
        item = [item]
    return item

class Dataset(dutils.Dataset):
    r"""Load a dict holding memmapped arrays and clinical parameters for each patient,