在keras中包含多个u-net实现的helper包,以及在处理图像分割任务时有用的实用工具
keras-unet的Python项目详细描述
关于
在keras中包含多个u-net实现的helper包,以及在处理图像分割任务时有用的实用工具
功能:
- [X]在Keras中实现的U-net模型
- [x]基于the original paper 的普通u-net实现
- [X]可定制U-net
- 基于DeepSense.AI Kaggle competition entry 的卫星图像优化u-net
- [X]实用功能:
- [X]使用覆盖图绘制图像和遮罩
- [X]绘制图像蒙版和覆盖预测(原始图像上的预测)
- [X]绘制度量和损失的培训历史记录
- [X]使用滑动窗口技术从更大的图像(例如卫星图像)中裁剪更小的面片(如果需要,还可以重叠)
- [X]绘制较小的面片以显示裁剪的大图像
- [X]将较小的面片重建回大图像
- [X]数据增强助手函数
- [X]笔记本电脑(示例):
- [X]针对鲸鱼尾巴分割的定制U形网培训
- []卫星图像的语义分割
- 医学图像的语义分割ISBI challenge 2015
安装:
pip install git+https://github.com/karolzak/keras-unet
或
pip install keras-unet
用法示例:
- Keras中的U-net实现:
- 实用程序:
香草u形网
Model scheme can be viewed here
fromkeras_unet.modelsimportvanilla_unetmodel=vanilla_unet(input_shape=(512,512,3))
可定制U-net
Model scheme can be viewed here
fromkeras_unet.modelsimportcustom_unetmodel=custom_unet(input_shape=(512,512,3),use_batch_norm=False,num_classes=1,filters=64,dropout=0.2,output_activation='sigmoid')
卫星图像的u-net
Model scheme can be viewed here
fromkeras_unet.modelsimportsatellite_unetmodel=satellite_unet(input_shape=(512,512,3))
绘制训练历史
history=model.fit_generator(...)fromkeras_unet.utilsimportplot_segm_historyplot_segm_history(history,# required - keras training history objectmetrics=['iou','val_iou'],# optional - metrics names to plotlosses=['loss','val_loss'])# optional - loss names to plot
输出:
绘制图像和分割遮罩
fromkeras_unet.utilsimportplot_imgsplot_imgs(org_imgs=x_val,# required - original imagesmask_imgs=y_val,# required - ground truth maskspred_imgs=y_pred,# optional - predicted masksnm_img_to_plot=9)# optional - number of images to plot
输出:
从较大的图像中获取较小的面片/作物
fromPILimportImageimportnumpyasnpfromkeras_unet.utilsimportget_patchesx=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 croppedsize=100,# default is 256stride=100)# default is 256print("x_crops shape: ",str(x_crops.shape))
输出:
x shape: (1000, 1000, 3) x_crops shape: (100, 100, 100, 3)
将小面片绘制成单个大图像
fromkeras_unet.utilsimportplot_patchesprint("x_crops shape: ",str(x_crops.shape))plot_patches(img_arr=x_crops,# required - array of cropped out imagesorg_img_size=(1000,1000),# required - original size of the imagestride=100)# use only if stride is different from patch size
输出:
x_crops shape: (100, 100, 100, 3)
从较小的斑块/作物重建较大的图像
importmatplotlib.pyplotaspltfromkeras_unet.utilsimportreconstruct_from_patchesprint("x_crops shape: ",str(x_crops.shape))x_reconstructed=reconstruct_from_patches(img_arr=x_crops,# required - array of cropped out imagesorg_img_size=(1000,1000),# required - original size of the imagestride=100)# use only if stride is different from patch sizeprint("x_reconstructed shape: ",str(x_reconstructed.shape))plt.figure(figsize=(10,10))plt.imshow(x_reconstructed[0])plt.show()
输出:
x_crops shape: (100, 100, 100, 3) x_reconstructed shape: (1, 1000, 1000, 3)