Skip to content

Instantly share code, notes, and snippets.

View karolzak's full-sized avatar
😷
Working from home

Karol Żak karolzak

😷
Working from home
  • Microsoft
View GitHub Profile
@karolzak
karolzak / unet.py
Last active January 16, 2019 22:26
Simple UNET implementation in Keras
###################### unet ############################
from keras.models import Model
from keras.layers import *
def upsample_conv(filters, kernel_size, strides, padding):
return Conv2DTranspose(filters, kernel_size, strides=strides, padding=padding)
def upsample_simple(filters, kernel_size, strides, padding):
@karolzak
karolzak / plot_segmentation_images.py
Last active January 24, 2019 09:02
Image plotting for semantic segmentation data
import numpy as np
import matplotlib.pyplot as plt
def mask_to_red(mask, img_size=1024):
'''
Converts binary segmentation mask from white to red color.
Also adds alpha channel to make black background transparent.
'''
c1 = mask.reshape(img_size,img_size)
@karolzak
karolzak / get_patches.py
Last active January 16, 2019 22:27
returns crops out of single image (numpy) or array of images
def get_patches(img_arr, size=256, stride=256):
'''
Takes single image or array of images and returns
crops using sliding window method.
If stride < size it will do overlapping.
'''
# check size and stride
if size % stride != 0:
raise ValueError('size % stride must be equal 0')