赞
踩
# 深度学习还没开始就想放弃系列 #
环境: win7+python 3.5+ tensorflow 1.9.0 + keras 2.2.4
参考博客: U-net源码讲解(Keras)源码解析很棒很细!
全卷积神经网络图像分割(U-net)-keras实现代码根本来源于该博主的Github
深度学习数据增强(data_augmentation):Keras ImageDataGenerator : keras的图像增强讲解,方便理解源码函数;
Keras中文文档——图片预处理 : 无意中翻到的,学习keras可以留存。
目的 : 利用U-Net (keras)实现自己数据集的分割任务,二类。
数据集准备:
样本: size: 256*256 位深为8,.png格式;
标签: size: 256*256 ,.png格式,使用photoshop软件标注控制位深为8,图片名于样本名字相同。
存储位置: 同一个根目录下的两个文件夹中,文件名为:image, label
测试图片:位深为8,
主要代码:model.py:存放U-Net网络模型,keras写起来真的很简单!!
- # model.py
- import numpy as np
- import os
- import skimage.io as io
- import skimage.transform as trans
- import numpy as np
- from keras.models import *
- from keras.layers import *
- from keras.optimizers import *
- from keras.callbacks import ModelCheckpoint, LearningRateScheduler
- from keras import backend as keras
-
- def unet(pretrained_weights = None,input_size = (256,256,1)):
- inputs = Input(input_size)
- conv1 = Conv2D(64, 3, activation = 'relu', padding = 'same', kernel_initializer = 'he_normal')(inputs)
- conv1 = Conv2D(64, 3, activation = 'relu', padding = 'same', kernel_initializer = 'he_normal')(conv1)
- pool1 = MaxPooling2D(pool_size=(2, 2))(conv1)
- conv2 = Conv2D(128, 3, activation = 'relu', padding = 'same', kernel_initializer = 'he_normal')(pool1)
- conv2 = Conv2D(128, 3, activation = 'relu', padding = 'same', kernel_initializer = 'he_normal')(conv2)
- pool2 = MaxPooling2D(pool_size=(2, 2))(conv2)
- conv3 = Conv2D(256, 3, activation = 'relu', padding = 'same', kernel_initializer = 'he_normal')(pool2)
- conv3 = Conv2D(256, 3, activation = 'relu', padding = 'same', kernel_initializer = 'he_normal')(conv3)
- pool3 = MaxPooling2D(pool_size=(2, 2))(conv3)
- conv4 = Conv2D(512, 3, activation = 'relu', padding = 'same', kernel_initializer = 'he_normal')(pool3)
- conv4 = Conv2D(512, 3, activation = 'relu', padding = 'same', kernel_initializer = 'he_normal')(conv4)
- drop4 = Dropout(0.5)(conv4)
- pool4 = MaxPooling2D(pool_size=(2, 2))(drop4)
-
- conv5 = Conv
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。