Skip to main content

Applying Deep Learning to medical image segmentation tasks

Project description

SegMed Build Status

This is a collection of Deep Learning semantic segmentation models to use for specific tasks, namely medical images, cells, histological data and related.

Models

The models here presented are just two, namely the U-Net and the MultiResUNet. These models have been a very good application of Fully Convolutional Networks to the medical image segmentation task, and are very well suited for it.

Implementation

Everything is implemented with TensorFlow 2.0, using the newly acquired Keras API within TensorFlow. This allows for the flexibility and completeness of using the full TensorFlow library while still having very good scripting capabilities with Keras.

Dependencies

There are several ways to install this package.

Using pip

The easiest way to install this package is using pip with the following command

pip install segmed

although it is highly encouraged to do this inside a virtual environment.

If using Colaboratory then this is the preferred way to use the package.

IMPORTANT: When using Colaboratory one must always install TensorFlow 2.0 first and then install segmed, i.e. this package, using the following commands in a cell within a Colaboratory notebook:

!pip install --upgrade pip
!pip install segmed
!pip install --upgrade tensorflow

Using poetry

poetry is supported, by following the installation instructions to get poetry installed, the following command should install segmed in a virtual environment:

# clone the repository
git clone https://github.com/DCI-NET/segmed
# run poetry and install
poetry install

poetry is a next-gen dependecy manager and makes everything a lot easier.

Using conda

This package also comes with a conda environment for those that use the Anaconda distribution.

To install the environment make sure you have conda installed, then run the following

conda env create -f segmed_env.yml

this should ask you to confirm the installation, say yes and proceed with the installation. After that, activate the newly created environment

conda activate segmed

and now you are ready to run the code within this repository.

Unit tests

This repository has some unit tests available that should be running constantly in the background, and the status of the current code build is displayed in the badge above (the one right to the title).

One can manually run the tests, too. You can download this repository with git like so:

git clone https://github.com/DCI-NET/segmed.git

Then, you install pytest and just run the following command

pytest

and the test suite should start running, with a few import and API warnings, but everything should pass if the badge above says passing in green.

Examples

This repository also has some (very) barebones examples of how to use these models. However, they were run in a local machine and most of the data cannot be used. These examples should be used as a tutorial for the package, just to have a basic idea of how to run and create an image segmentation pipeline with segmed, but you will not be able to rerun the notebooks.

The reason for this is that most of the datasets are very large, so they cannot be bundled with this repository; some other datasets cannot be redistributed as per request of the original authors.

Either way, all of the trained models and weights are freely available upon request.

Demo

For completeness, here is a simple example. Assuming you have followed the instructions and everything is installed correctly, you can do the following to train a simple U-Net model:

from segmed.train import train_unet
from segmed.models import Unet

# Define some example hyperparameters
batch_size = 8
epochs = 50
steps_per_epoch=100

# Declare the paths to use (following the Keras convention)
# https://www.tensorflow.org/versions/r2.0/api_docs/python/tf/keras/Model#fit_generator
data_path = "general/path/to/images"
img_path = data_path + "augmented/images/path"
masks_path = data_path + "augmented/masks/path"
model_file = "path/to/save/model/unet_model.h5"

# Create a Unet (custom) model with a regularizer and
# batch normalization
custom_params = {
    "activation": "relu",
    "padding": "same",
    "batch_norm": True,
    "l2_reg": 0.995
}
model = Unet(variant="custom", parameters=custom_params)
# Train the model!
history = train_unet(
    model,
    img_path,
    masks_path,
    batch_size=batch_size,
    epochs=epochs,
    steps_per_epoch=steps_per_epoch,
    model_file=model_file,
)

Now, the training should have started and you're good to go!

Datasets

The datasets employed in some of the parts of this repository are the following:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

segmed-0.6.12.tar.gz (18.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

segmed-0.6.12-py3-none-any.whl (22.0 kB view details)

Uploaded Python 3

File details

Details for the file segmed-0.6.12.tar.gz.

File metadata

  • Download URL: segmed-0.6.12.tar.gz
  • Upload date:
  • Size: 18.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.17 CPython/3.7.5 Linux/5.2.20-130.current

File hashes

Hashes for segmed-0.6.12.tar.gz
Algorithm Hash digest
SHA256 7aadb6c0de183c270e13cb917bf797452e70d1ac9442e8394012d52678b39124
MD5 5f0e738a888e283aeb1d5d732ca5a2e4
BLAKE2b-256 56fbcaf07ce708729a3a10c02cdf999d34c83e5a3412743719bba4b66117af73

See more details on using hashes here.

File details

Details for the file segmed-0.6.12-py3-none-any.whl.

File metadata

  • Download URL: segmed-0.6.12-py3-none-any.whl
  • Upload date:
  • Size: 22.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.17 CPython/3.7.5 Linux/5.2.20-130.current

File hashes

Hashes for segmed-0.6.12-py3-none-any.whl
Algorithm Hash digest
SHA256 2e86e3c8e8607bf8156376fa1724b2b028dc98c57ede350a5bfb890f6a4eb1a7
MD5 0bb9f53491cca81de6e4ff199e1b4b0a
BLAKE2b-256 8e26a716dbc71ef6f0b58df6f894f24cdfc687c979db87aacbb454768f0c2116

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page