Skip to main content

Train Unet

Aim is to create a low-code easy to use python library for training CNN models using Unet architecture with custom metrics like IoU (Intersection over Union) for semantic segmentation of medical images/scans.

Applications in Medical Imaging

  • Many medical applications necessitates finding and accurately labeling things found in medical scans.
  • This is often done using advanced software to assist medical technicians and doctos. However, this task still requires human intervention and such as, can be tedious,slow, expensive and prone to human error.
  • There's huge initiative for use Computer Vision and Deep Learning to automate many of these tasks.

Analyzing medical scans such as

  • CAT scans
  • X-rays
  • Ultra sound
  • PET
  • NMR


U-net - Image segmentation using CNN's.

U-net has become very popular end-to-end encoder-decoder network for Semantic segmentation.

It has a unique Up-down archtiecture which has a contracting path and an expansive path.

U-NET archtiectURE: alt text

U-NET Structure: alt text

Intersection over union(IoU) metrics

IoU is basically a measure of overlap.

IoU = ^Size_of_union/_Size of Intersection

  • Typically IoU over 0.5 is acceptable.
  • higher the IoU better the prediction.

Installation and Usage

Get the required packages

git clone https://github.com/iamlmn/train-unet.git
cd train-unet
pip install -r requirements.txt

or get the dependencies installed

pandas
keras==2.2.4
tensorflow==1.13.1
numpy
spicy
scikit-image
tqdm
docopt

Install train_unet using pip

pip install train-unet

Training sets & test sets (.png) are expected to be in the below folder format.

Input struct on single train and test set: alt text


Sameple dataset is in data folder. Finding the nuclei in Divergent images. #Spot Nuclei. Speed Cures. (The Kaggle Data Science bowl 2018 Challenge).

use it from Python:
# Configure training target images
from train_unet import TrainUnet
# set image/mask sizes
IMG_WIDTH = 128
IMG_HEIGHT = 128
IMG_CHANNELS = 3
TRAIN_PATH = '../data/U_NET/train/'
TEST_PATH = '../data/U_NET/validation/'
MODEL_OUTPUT_PATH = 'py_model.h5'

# Training and prediction
unet_test = TrainUnet(TRAIN_PATH, TEST_PATH, IMG_HEIGHT, IMG_WIDTH, IMG_CHANNELS, MODEL_OUTPUT_PATH) # Create Unet object
X_train, Y_train = unet_test.resize_training_sets(combine_masks = True) # prep training data
X_test = unet_test.resize_target_sets() # prep Target sets
unet_test.train_illustrate() # exports every 10th training and masked images - illustrates
model_path = unet_test.train_model() # Traing
preds_train, preds_val, preds_test = unet_test.load_and_predict() # predict
unet_test.plot_random_comparisons(preds_train_t, preds_val_t, preds_test, _save = True) # comparison plots on random images
unet_test.classification_report(ix=25)

TODOs and completed work :

  • Base module class
  • Pypi setup
  • deploying to AWS as a Lambda service
  • Ideate Model parameeter modification
  • 3d Segmentations?
  • Unit tests

Metadata

Release files for train-unet 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for train-unet 0.0.2
File Size Uploaded Provenance Actions
train_unet-0.0.2.tar.gz 25.6 MB Without provenance Details for train_unet-0.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for train-unet 0.0.2
File Interpreter ABI Platform Actions
train_unet-0.0.2-py3-none-any.whl Python 3 none any Details for train_unet-0.0.2-py3-none-any.whl

Total release size: 25.6 MB

Release files / train_unet-0.0.2.tar.gz

Download URL train_unet-0.0.2.tar.gz
Size 25.6 MB
Tags Source
SHA-256 checksum
How to use checksums
11d2006b3776a06d6ad43d3cfb0c03962d7c63975be51796ce4cc6843d381c79
BLAKE2b-256 checksum
How to use checksums
5e58c20862a484f9390f7fb220e404e6a620918ce2e04811e3b1c890a9b8e650
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.2

Release files / train_unet-0.0.2-py3-none-any.whl

Download URL train_unet-0.0.2-py3-none-any.whl
Size 14.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fc1ed4bd798f484246373f5e2b05e5cf52f975d291048471f766033341d8698f
BLAKE2b-256 checksum
How to use checksums
a61227536be3cfced47d49f360c249572f12aeed9ee5508e0cefa160b4cb7a74
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.2

Security for train-unet 0.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page