• Stars
    star
    334
  • Rank 126,264 (Top 3 %)
  • Language
    Python
  • License
    MIT License
  • Created over 5 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Helper package with multiple U-Net implementations in Keras as well as useful utility tools helpful when working with image semantic segmentation tasks. This library and underlying tools come from multiple projects I performed working on semantic segmentation tasks

Build PyPI - version Downloads Downloads/Month 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]

More Repositories

1

ipyplot

IPyPlot is a small python package offering fast and efficient plotting of images inside Python Notebooks. It's using IPython with HTML for faster, richer and more interactive way of displaying big numbers of images.
Python
381
star
2

support-tickets-classification

This case study shows how to create a model for text analysis and classification and deploy it as a web service in Azure cloud in order to automatically classify support tickets. This project is a proof of concept made by Microsoft (Commercial Software Engineering team) in collaboration with Endava http://endava.com/en
Python
167
star
3

boxdetect

BoxDetect is a Python package based on OpenCV which allows you to easily detect rectangular shapes like character or checkbox boxes on scanned forms.
Python
88
star
4

conv3d-video-action-recognition

My experimentation around action recognition in videos. Contains Keras implementation for C3D network based on original paper "Learning Spatiotemporal Features with 3D Convolutional Networks", Tran et al. and it includes video processing pipelines coded using mPyPl package. Model is being benchmarked on popular UCF101 dataset and achieves results similar to those reported by authors
Python
51
star
5

cntk-hotel-pictures-classificator

This POC is using CNTK 2.1 to train model for multiclass classification of images. Our model is able to recognize specific objects (i.e. toilet, tap, sink, bed, lamp, pillow) connected with picture types we are looking for. It plays a big role in a process which will be used to classify pictures from different hotels and determine whether it's a picture of bathroom, bedroom, hotel front, swimming pool, bar, etc.
Python
38
star
6

cntk-python-web-service-on-azure

This sample project shows off how to prepare and deploy to Azure Web Apps a simple Python web service with an image classifying model produced in CNTK (Cognitive Toolkit) using FasterRCNN
Python
25
star
7

images-vector-search

Simple implementation of search for visually similar images using deep learning and vector search. It's based on pretrained ImageNet weights so it doesnt require any additional training
Python
8
star
8

mobile-app-documentdb-offlinesync-sample

This is a proof of concept project where we tight up a DocumentDB instance with complex (nested) types with several SQLite mobile clients using Azure Mobile Apps with Offline Sync.
C#
7
star
9

xamarin-mvvmcross-and-web-service-sample

This is a sample LOB application for iOS, Android and Windows UWP, written with Xamarin Native approach
C#
2
star
10

adventofcode

Jupyter Notebook
1
star
11

xaml-blend-tutorial

C#
1
star