farabio

farabio is a minimal PyTorch toolkit for out-of-the-box deep learning support in biomedical imaging. out-of-the-box deep learning support in biomedical imaging.

Features:

  • Biomedical datasets

  • Common DL models

  • Flexible trainers (in progress)

Overview

Getting started

How to install

1. Activate conda environment

$ conda create -n myenv python=3.8
$ conda activate myenv

2. Install farabio

A. With pip:
$ pip install farabio -f https://download.pytorch.org/whl/torch_stable.html
B. Setup from source:
$ git clone https://github.com/tuttelikz/farabio.git && cd farabio
$ python -m pip install --upgrade pip setuptools wheel
$ pip install . -f https://download.pytorch.org/whl/torch_stable.html

Reference

data Package

biodatasets Module

biodatasets module provides classes to load public biomedical datasets in a PyTorch friendly manner.

ChestXrayDataset class
class farabio.data.biodatasets.ChestXrayDataset(root: str = '.', download: bool = False, mode: str = 'train', shape: int = 256, transform: Optional[Callable] = None, target_transform: Optional[Callable] = None, show: bool = True)[source]

PyTorch friendly ChestXrayDataset class

Dataset is loaded using Kaggle API. For further information on raw dataset and pneumonia detection, please refer to [1].

References

1(1,2)

https://www.kaggle.com/paultimothymooney/chest-xray-pneumonia

Examples

>>> valid_dataset = ChestXrayDataset(root=_path, download=True, mode="val", show=True)
_images/ChestXrayDataset.png
visualize_batch()[source]
DSB18Dataset class
class farabio.data.biodatasets.DSB18Dataset(root: str = '.', download: bool = False, mode: str = 'train', shape: int = 512, transform: Optional[Callable] = None, target_transform: Optional[Callable] = None, show: bool = True)[source]

PyTorch friendly DSB18Dataset class

Dataset is loaded using Kaggle API. For further information on raw dataset and nuclei segmentation, please refer to [1].

References

1(1,2)

https://www.kaggle.com/c/data-science-bowl-2018/overview

Examples

>>> train_dataset = DSB18Dataset(_path, transform=None, download=False, show=True)
_images/DSB18Dataset.png
visualize_batch()[source]
HistocancerDataset class
class farabio.data.biodatasets.HistocancerDataset(root: str = '.', mode: str = 'train', transform: Optional[Callable] = None, target_transform: Optional[Callable] = None, download: bool = False, show: bool = True)[source]

PyTorch friendly HistocancerDataset class

Dataset is loaded using Kaggle API. For further information on raw dataset and tumor classification, please refer to [1].

References

1(1,2)

<https://www.kaggle.com/c/histopathologic-cancer-detection/data>`_

Examples

>>> train_dataset = HistocancerDataset(root=".", download=False, mode="train")
_images/HistocancerDataset.png
visualize_batch()[source]
RANZCRDataset class
class farabio.data.biodatasets.RANZCRDataset(root: str = '.', mode: str = 'train', shape: int = 256, transform: Optional[Callable] = None, target_transform: Optional[Callable] = None, download: bool = False, show: bool = True)[source]

PyTorch friendly RANZCRDataset class

Dataset is loaded using Kaggle API. For further information on raw dataset and catheters presence, please refer to [1].

References

1(1,2)

https://www.kaggle.com/c/ranzcr-clip-catheter-line-classification/data

Examples

>>> train_dataset = RANZCRDataset(_path_ranzcr, show=True, shape=512)
_images/RANZCRDataset.png
visualize_batch()[source]
RetinopathyDataset class
class farabio.data.biodatasets.RetinopathyDataset(root: str = '.', mode: str = 'train', shape: int = 256, transform: Optional[Callable] = None, target_transform: Optional[Callable] = None, download: bool = False, show: bool = True)[source]

PyTorch friendly RetinopathyDataset class

Dataset is loaded using Kaggle API. For further information on raw dataset and blindness detection, please refer to [1].

References

1(1,2)

<https://www.kaggle.com/c/aptos2019-blindness-detection/data>`_

Examples

>>> train_dataset = RetinopathyDataset(".", mode="train", show=True)
_images/RetinopathyDataset.png
visualize_batch()[source]

Handbook

Overview

Deep learning has transformed many aspects of industrial pipelines recently. Scientists involved in biomedical imaging research are also benefiting from the power of AI to tackle complex challenges. Although academic community has widely accepted image processing tools, such as scikit-image, ImageJ, there is still a need for a tool which integrates deep learning into biomedical image analysis. We propose a minimal, but convenient Python package based on PyTorch with biomedical datasets, common deep learning models, and extended by flexible trainers.

What can I do with this package?
  • Load public biomedical datasets

  • Load common deep learning models

  • Do basic image preprocessing and transformations

  • Customize training loops to your own needs

Package structure
graph farabioOverview {

node [shape=box, colorscheme=set32 , style=rounded];

farabio -- core;
farabio -- data;
farabio -- models;
farabio -- utils;

farabio  [fillcolor=1, style="rounded"]
core  [fillcolor=2, style="rounded"]
data  [fillcolor=2, style="rounded"]
models  [fillcolor=2, style="rounded"]
utils  [fillcolor=2, style="rounded"]
}
How to contribute?

You can contribute to this package by reporting issues and/or by sending pull request.

If you find a bug, please report it by opening an issue on Git.

Machine learning for Biomedical Engineers

Activation functions
Binary Step
\[\begin{split}f(x) = \left\{ \begin{array}{lll} 0 & for & x < x_{min} \\ mx+b & for & x_{min} \leq x \leq x_{max} \\ 1 & for & x > x_{max} \end{array} \right.\end{split}\]
\[\begin{split}f'(x) = \left\{ \begin{array}{lll} 0 & for & x \neq 0 \\ ? & for & x = 0 \end{array} \right.\end{split}\]

(Source code, png, hires.png, pdf)

_images/binary_step.png
Piecewise Linear
\[\begin{split}f(x) = \left\{ \begin{array}{lll} 0 & for & x < x_{min} \\ mx+b & for & x_{min} \leq x \leq x_{max} \\ 1 & for & x > x_{max} \end{array} \right.\end{split}\]
\[\begin{split}f'(x) = \left\{ \begin{array}{lll} 0 & for & x < x_{min} \\ m & for & x_{min} \leq x \leq x_{max} \\ 0 & for & x > x_{max} \end{array} \right.\end{split}\]

(Source code, png, hires.png, pdf)

_images/piecewise_linear.png
Bipolar
\[\begin{split}f(x) = \left\{ \begin{array}{lll} -1 & for & x \leq 0 \\ 1 & for & x > 0 \end{array} \right.\end{split}\]
\[\begin{split}f'(x) = \left\{ \begin{array}{lll} 0 & for & x \neq 0 \\ ? & for & x = 0 \end{array} \right.\end{split}\]

(Source code, png, hires.png, pdf)

_images/bipolar.png
Sigmoid
\[f(x)={\frac {1}{1+e^{-x}}}\]
\[f'(x)=f(x)(1-f(x))\]

(Source code, png, hires.png, pdf)

_images/sigmoid.png
Bipolar Sigmoid
\[f(x)={\frac {1-e^{-x}}{1+e^{-x}}}\]
\[f'(x)={\frac {2e^x}{(e^x+1)^2}}\]

(Source code, png, hires.png, pdf)

_images/bipolar_sigmoid.png
Hyperbolic Tangent, TanH
\[f(x)={\frac {2}{1+e^{-2x}}}-1\]
\[f'(x)=1-f(x)^2\]

(Source code, png, hires.png, pdf)

_images/tanh.png
Arctangent, ArcTan
\[f(x)=tan^{-1}(x)\]
\[f'(x)={\frac {1}{1+x^2}}\]

(Source code, png, hires.png, pdf)

_images/arctan.png
Rectified Linear Units, ReLU
\[\begin{split}f(x) = \left\{ \begin{array}{lll} 0 & for & x \leq 0 \\ x & for & x > 0 \end{array} \right.\end{split}\]
\[\begin{split}f'(x) = \left\{ \begin{array}{lll} 0 & for & x \leq 0 \\ 1 & for & x > 0 \end{array} \right.\end{split}\]

(Source code, png, hires.png, pdf)

_images/relu.png
Leaky Rectified Linear Units, Leaky ReLU
\[\begin{split}f(x) = \left\{ \begin{array}{lll} ax & for & x \leq 0 \\ x & for & x > 0 \end{array} \right.\end{split}\]
\[\begin{split}f'(x) = \left\{ \begin{array}{lll} a & for & x \leq 0 \\ 1 & for & x > 0 \end{array} \right.\end{split}\]

(Source code, png, hires.png, pdf)

_images/leaky_relu.png
Exponential Linear Units, ELU
\[\begin{split}f(x) = \left\{ \begin{array}{lll} a(e^x-1) & for & x \leq 0 \\ x & for & x > 0 \end{array} \right.\end{split}\]
\[\begin{split}f'(x) = \left\{ \begin{array}{lll} f(x)+a & for & x \leq 0 \\ 1 & for & x > 0 \end{array} \right.\end{split}\]

(Source code, png, hires.png, pdf)

_images/elu.png
SoftPlus
\[f(x)=ln(1+e^x)\]
\[f'(x)={\frac {1}{1+e^{-x}}}\]

(Source code, png, hires.png, pdf)

_images/softplus.png

Changelog

Recent Changes
  • fix on spacings by San Askaruly at 2021-08-18 08:56:55

  • hide members except visu_batch in biodatasets by San Askaruly at 2021-08-17 18:14:16

  • biodatasets images change in docs by San Askaruly at 2021-08-17 17:56:41

Commit

1acf1452f4

Warning

There were uncommitted changes when this was compiled.

FAQ

Indices and tables