Core

bioMONAI core functions

Imports

Main imports from other libraries.


source

DataBlock

 DataBlock (blocks:list=None, dl_type:TfmdDL=None, getters:list=None,
            n_inp:int=None, item_tfms:list=None, batch_tfms:list=None,
            get_items=None, splitter=None, get_y=None, get_x=None)

Generic container to quickly build Datasets and DataLoaders.

Type Default Details
blocks list None One or more TransformBlocks
dl_type TfmdDL None Task specific TfmdDL, defaults to block’s dl_type orTfmdDL
getters list None Getter functions applied to results of get_items
n_inp int None Number of inputs
item_tfms list None ItemTransforms, applied on an item
batch_tfms list None Transforms or RandTransforms, applied by batch
get_items NoneType None
splitter NoneType None
get_y NoneType None
get_x NoneType None

source

DataLoaders

 DataLoaders (*loaders, path:str|pathlib.Path='.', device=None)

Basic wrapper around several DataLoaders.


source

Learner

Group together a model, some dls and a loss_func to handle training


source

ShowGraphCallback

 ShowGraphCallback (after_create=None, before_fit=None, before_epoch=None,
                    before_train=None, before_batch=None, after_pred=None,
                    after_loss=None, before_backward=None,
                    after_cancel_backward=None, after_backward=None,
                    before_step=None, after_cancel_step=None,
                    after_step=None, after_cancel_batch=None,
                    after_batch=None, after_cancel_train=None,
                    after_train=None, before_validate=None,
                    after_cancel_validate=None, after_validate=None,
                    after_cancel_epoch=None, after_epoch=None,
                    after_cancel_fit=None, after_fit=None)

Update a graph of training and validation loss


source

CSVLogger

 CSVLogger (fname='history.csv', append=False)

Log the results displayed in learn.path/fname


cells3d

 cells3d ()

*3D fluorescence microscopy image of cells.

The returned data is a 3D multichannel array with dimensions provided in (z, c, y, x) order. Each voxel has a size of (0.29 0.26 0.26) micrometer. Channel 0 contains cell membranes, channel 1 contains nuclei.*

Engine

Core engine for model training. See tutorials for usage examples.


source

fastTrainer

 fastTrainer (dataloaders:fastai.data.core.DataLoaders, model:<built-
              infunctioncallable>, loss_fn:typing.Any|None=None, optimizer
              :fastai.optimizer.Optimizer|fastai.optimizer.OptimWrapper=<f
              unction Adam>, lr:float|slice=0.001, splitter:<built-
              infunctioncallable>=<function trainable_params>, callbacks:U
              nion[fastai.callback.core.Callback,MutableSequence,NoneType]
              =None, metrics:Union[Any,MutableSequence,NoneType]=None,
              csv_log:bool=False, show_graph:bool=True,
              show_summary:bool=False, find_lr:bool=False,
              find_lr_fn=<function valley>,
              path:str|pathlib.Path|None=None,
              model_dir:str|pathlib.Path='models', wd:float|int|None=None,
              wd_bn_bias:bool=False, train_bn:bool=True,
              moms:tuple=Ellipsis, default_cbs:bool=True)

A custom implementation of the FastAI Learner class for training models in bioinformatics applications.

Type Default Details
dataloaders DataLoaders The DataLoader objects containing training and validation datasets.
model callable A callable model that will be trained on the dataset.
loss_fn typing.Any | None None The loss function to optimize during training. If None, defaults to a suitable default.
optimizer fastai.optimizer.Optimizer | fastai.optimizer.OptimWrapper Adam The optimizer function to use. Defaults to Adam if not specified.
lr float | slice 0.001 Learning rate for the optimizer. Can be a float or a slice object for learning rate scheduling.
splitter callable trainable_params
callbacks Union None A callable that determines which parameters of the model should be updated during training.
metrics Union None Optional list of callback functions to customize training behavior.
csv_log bool False Metrics to evaluate the performance of the model during training.
show_graph bool True Whether to log training history to a CSV file. If True, logs will be appended to ‘history.csv’.
show_summary bool False The base directory where models are saved or loaded from. Defaults to None.
find_lr bool False Subdirectory within the base path where trained models are stored. Default is ‘models’.
find_lr_fn function valley Weight decay factor for optimization. Defaults to None.
path str | pathlib.Path | None None Whether to apply weight decay to batch normalization and bias parameters.
model_dir str | pathlib.Path models Whether to update the batch normalization statistics during training.
wd float | int | None None
wd_bn_bias bool False
train_bn bool True
moms tuple Ellipsis Tuple of tuples representing the momentum values for different layers in the model. Defaults to FastAI’s default settings if not specified.
default_cbs bool True Automatically include default callbacks such as ShowGraphCallback and CSVLogger.

source

visionTrainer

 visionTrainer (dataloaders:fastai.data.core.DataLoaders, model:<built-
                infunctioncallable>, normalize=True, n_out=None,
                pretrained=True, weights=None,
                loss_fn:typing.Any|None=None, optimizer:fastai.optimizer.O
                ptimizer|fastai.optimizer.OptimWrapper=<function Adam>,
                lr:float|slice=0.001, splitter:<built-
                infunctioncallable>=<function trainable_params>, callbacks
                :Union[fastai.callback.core.Callback,MutableSequence,NoneT
                ype]=None,
                metrics:Union[Any,MutableSequence,NoneType]=None,
                csv_log:bool=False, show_graph:bool=True,
                show_summary:bool=False, find_lr:bool=False,
                find_lr_fn=<function valley>,
                path:str|pathlib.Path|None=None,
                model_dir:str|pathlib.Path='models',
                wd:float|int|None=None, wd_bn_bias:bool=False,
                train_bn:bool=True, moms:tuple=Ellipsis,
                default_cbs:bool=True, cut=None, init=<function
                kaiming_normal_>, custom_head=None, concat_pool=True,
                pool=True, lin_ftrs=None, ps=0.5, first_bn=True,
                bn_final=False, lin_first=False, y_range=None, n_in=3)

Build a vision trainer from dataloaders and model

Type Default Details
dataloaders DataLoaders The DataLoader objects containing training and validation datasets.
model callable A callable model that will be trained on the dataset.
normalize bool True
n_out NoneType None
pretrained bool True
weights NoneType None
loss_fn typing.Any | None None The loss function to optimize during training. If None, defaults to a suitable default.
optimizer fastai.optimizer.Optimizer | fastai.optimizer.OptimWrapper Adam The optimizer function to use. Defaults to Adam if not specified.
lr float | slice 0.001 Learning rate for the optimizer. Can be a float or a slice object for learning rate scheduling.
splitter callable trainable_params
callbacks Union None A callable that determines which parameters of the model should be updated during training.
metrics Union None Optional list of callback functions to customize training behavior.
csv_log bool False Metrics to evaluate the performance of the model during training.
show_graph bool True Whether to log training history to a CSV file. If True, logs will be appended to ‘history.csv’.
show_summary bool False The base directory where models are saved or loaded from. Defaults to None.
find_lr bool False Subdirectory within the base path where trained models are stored. Default is ‘models’.
find_lr_fn function valley Weight decay factor for optimization. Defaults to None.
path str | pathlib.Path | None None Whether to apply weight decay to batch normalization and bias parameters.
model_dir str | pathlib.Path models Whether to update the batch normalization statistics during training.
wd float | int | None None
wd_bn_bias bool False
train_bn bool True
moms tuple Ellipsis Tuple of tuples representing the momentum values for different layers in the model. Defaults to FastAI’s default settings if not specified.
default_cbs bool True Automatically include default callbacks such as ShowGraphCallback and CSVLogger.
cut NoneType None model & head args
init function kaiming_normal_
custom_head NoneType None
concat_pool bool True
pool bool True
lin_ftrs NoneType None
ps float 0.5
first_bn bool True
bn_final bool False
lin_first bool False
y_range NoneType None
n_in int 3

Utils

Utility functions.


source

attributesFromDict

 attributesFromDict (d)

source

get_device

 get_device ()

source

img2float

 img2float (image, force_copy=False)

source

img2Tensor

 img2Tensor (image)