Skip to main content

Build PyPI - version PyPI - Downloads license

Share:
Twitter URL LinkedIn URL

About

Helper package with multiple U-Net implementations in Keras as well as useful utility tools helpful when working with image segmentation tasks

Features:

  • U-Net models implemented in Keras
  • Utility functions:
    • Plotting images and masks with overlay
    • Plotting images masks and predictions with overlay (prediction on top of original image)
    • Plotting training history for metrics and losses
    • Cropping smaller patches out of bigger image (e.g. satellite imagery) using sliding window technique (also with overlap if needed)
    • Plotting smaller patches to visualize the cropped big image
    • Reconstructing smaller patches back to a big image
    • Data augmentation helper function
  • Notebooks (examples):
    • Training custom U-Net for whale tails segmentation
    • Semantic segmentation for satellite images
    • Semantic segmentation for medical images ISBI challenge 2015

Installation:

pip install git+https://github.com/karolzak/keras-unet

or

pip install keras-unet

Usage examples:


Vanilla U-Net

Model scheme can be viewed here

from keras_unet.models import vanilla_unet

model = vanilla_unet(input_shape=(512, 512, 3))

[back to usage examples]


Customizable U-Net

Model scheme can be viewed here

from keras_unet.models import custom_unet

model = custom_unet(
    input_shape=(512, 512, 3),
    use_batch_norm=False,
    num_classes=1,
    filters=64,
    dropout=0.2,
    output_activation='sigmoid')

[back to usage examples]


U-Net for satellite images

Model scheme can be viewed here

from keras_unet.models import satellite_unet

model = satellite_unet(input_shape=(512, 512, 3))

[back to usage examples]


Plot training history

history = model.fit_generator(...)

from keras_unet.utils import plot_segm_history

plot_segm_history(
    history, # required - keras training history object
    metrics=['iou', 'val_iou'], # optional - metrics names to plot
    losses=['loss', 'val_loss']) # optional - loss names to plot

Output:
metric history loss history

[back to usage examples]


Plot images and segmentation masks

from keras_unet.utils import plot_imgs

plot_imgs(
    org_imgs=x_val, # required - original images
    mask_imgs=y_val, # required - ground truth masks
    pred_imgs=y_pred, # optional - predicted masks
    nm_img_to_plot=9) # optional - number of images to plot

Output:
plotted images, masks and predictions

[back to usage examples]


Get smaller patches/crops from bigger image

from PIL import Image
import numpy as np
from keras_unet.utils import get_patches

x = np.array(Image.open("../docs/sat_image_1.jpg"))
print("x shape: ", str(x.shape))

x_crops = get_patches(
    img_arr=x, # required - array of images to be cropped
    size=100, # default is 256
    stride=100) # default is 256

print("x_crops shape: ", str(x_crops.shape))

Output:

x shape:  (1000, 1000, 3)   
x_crops shape:  (100, 100, 100, 3)

[back to usage examples]


Plot small patches into single big image

from keras_unet.utils import plot_patches

print("x_crops shape: ", str(x_crops.shape))         
plot_patches(
    img_arr=x_crops, # required - array of cropped out images
    org_img_size=(1000, 1000), # required - original size of the image
    stride=100) # use only if stride is different from patch size

Output:

x_crops shape:  (100, 100, 100, 3)

plotted patches

[back to usage examples]


Reconstruct a bigger image from smaller patches/crops

import matplotlib.pyplot as plt
from keras_unet.utils import reconstruct_from_patches

print("x_crops shape: ", str(x_crops.shape))

x_reconstructed = reconstruct_from_patches(
    img_arr=x_crops, # required - array of cropped out images
    org_img_size=(1000, 1000), # required - original size of the image
    stride=100) # use only if stride is different from patch size

print("x_reconstructed shape: ", str(x_reconstructed.shape))

plt.figure(figsize=(10,10))
plt.imshow(x_reconstructed[0])
plt.show()

Output:

x_crops shape:  (100, 100, 100, 3)
x_reconstructed shape:  (1, 1000, 1000, 3)

reconstructed image

[back to usage examples]

Metadata

Release files for keras-unet 0.1.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 keras-unet 0.1.2
File Size Uploaded Provenance Actions
keras-unet-0.1.2.tar.gz 14.4 kB Without provenance Details for keras-unet-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for keras-unet 0.1.2
File Interpreter ABI Platform Actions
keras_unet-0.1.2-py3-none-any.whl Python 3 none any Details for keras_unet-0.1.2-py3-none-any.whl

Total release size: 31.3 kB

Release files / keras-unet-0.1.2.tar.gz

Download URL keras-unet-0.1.2.tar.gz
Size 14.4 kB
Tags Source
SHA-256 checksum
How to use checksums
ed3999e4beea836b47856c777992a509b051c4d72c9ebc69c96cf4001dc7bf46
BLAKE2b-256 checksum
How to use checksums
995aa7282e456db59c4f2a31db75e2943cab3ab71da88a6b2085cd8f08df9979
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

Release files / keras_unet-0.1.2-py3-none-any.whl

Download URL keras_unet-0.1.2-py3-none-any.whl
Size 17.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8b62b31fd63db9d895a3c3ffd86539e98f04ed58c22967962199de9c8767a162
BLAKE2b-256 checksum
How to use checksums
b0f6783d69bd0c5b250abcf0d0f187ce7b3e2cc2332315068d2fd14662b0471e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

Security for keras-unet 0.1.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