Package: segmed
SegMedThis is a collection of Deep Learning semantic segmentation models to use for
specific tasks, namely medical images, cells, histological data and related.ModelsThe models here presented are just two, namely theU-Netand theMultiResUNet. 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.ImplementationEverything is implemented withTensorFlow 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.DependenciesThere are several ways to install this package.UsingpipThe easiest way to install this package is usingpipwith the following commandpip install segmedalthough it ishighly encouragedto do this inside a virtual environment.If usingColaboratorythen this is thepreferredway to use the package.IMPORTANT: When using Colaboratory one must always installTensorFlow 2.0first and then installsegmed,
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 tensorflowUsingpoetrypoetryis supported, by following theinstallationinstructions to getpoetryinstalled, the following
command should installsegmedin a virtual environment:# clone the repositorygitclonehttps://github.com/DCI-NET/segmed# run poetry and installpoetryinstallpoetryis a next-gen dependecy manager and makes everything a lot easier.UsingcondaThis package also comes with aconda environmentfor those that use theAnaconda distribution.To install the environment make sure you havecondainstalled, then run the followingconda env create -f segmed_env.ymlthis should ask you to confirm the installation, say yes and proceed with the installation. After that, activate the newly
created environmentconda activate segmedand now you are ready to run the code within this repository.Unit testsThis 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 withgitlike so:git clone https://github.com/DCI-NET/segmed.gitThen, you installpytestand just run the following commandpytestand the test suite should start running, with a few import and API warnings, but everything should pass
if the badge above sayspassingin green.ExamplesThis 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 atutorialfor the package,
just to have a basic idea of how to run and create an image segmentation pipeline withsegmed,
but you willnotbe able to rerun the notebooks.The reason for this is that most of the datasets areverylarge, so they cannot be bundled
with this repository; some other datasetscannotbe redistributed as per request of the original authors.Either way,allof the trained models and weights arefreely availableupon request.DemoFor 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:fromsegmed.trainimporttrain_unetfromsegmed.modelsimportUnet# Define some example hyperparametersbatch_size=8epochs=50steps_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_generatordata_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 normalizationcustom_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!DatasetsThe datasets employed in some of the parts of this repository are the following:ISBI 2012 ChallengeMotion-based Segmentation and Recognition DatasetDRIVE: Digital Retinal Images for Vessel ExtractionFast and Robust Segmentation of White Blood Cell Images by Self-supervised Learning