import keras
from keras import layers
def U_netModel(num_classes,input_shape=(512,512,1)):
inputs = layers.Input(shape=input_shape)
conv1_1 = layers.Conv2D(filters=64,kernel_size=(3,3),padding="same",kernel_initializer="he_normal",activation="relu")(inputs)
conv1_2 = layers.Conv2D(filters=64,kernel_size=(3,3),padding="same",kernel_initializer="he_normal",activation="relu")(conv1_1)
pool1 = layers.MaxPooling2D(pool_size=(2,2))(conv1_2)
conv2_1 = layers.Conv2D(filters=128, kernel_size=(3, 3), padding="same", kernel_initializer="he_normal",activation="relu")(pool1)
conv2_2 = layers.Conv2D(filters=128, kernel_size=(3, 3), padding="same", kernel_initializer="he_normal",activation="relu")(conv2_1)
pool2 = layers.MaxPooling2D(pool_size=(2,2))(conv2_2)
conv3_1 = layers.Conv2D(filters=256, kernel_size=(3, 3), padding="same", kernel_initializer="he_normal",activation="relu")(pool2)
conv3_2 = layers.Conv2D(filters=256, kernel_size=(3, 3), padding="same", kernel_initializer="he_normal",activation="relu")(conv3_1)
pool3 = layers.MaxPooling2D(pool_size=(2,2))(conv3_2)
conv4_1 = layers.Conv2D(filters=512, kernel_size=(3, 3), padding="same", kernel_initializer="he_normal",activation="relu")(pool3)
conv4_2 = layers.Conv2D(filters=512, kernel_size=(3, 3), padding="same", kernel_initializer="he_normal",activation="relu")(conv4_1)
pool4 = layers.MaxPooling2D(pool_size=(2, 2))(conv4_2)
conv5_1 = layers.Conv2D(filters=1024, kernel_size=(3, 3), padding="same", kernel_initializer="he_normal",activation="relu")(pool4)
conv5_2 = layers.Conv2D(filters=1024, kernel_size=(3, 3), padding="same", kernel_initializer="he_normal",activation="relu")(conv5_1)
deconv6_up = layers.Conv2D(filters=512,kernel_size=(3,3),padding="same",kernel_initializer="he_normal",activation="relu")(layers.UpSampling2D((2,2))(conv5_2))
merge6 = layers.concatenate([conv4_2,deconv6_up])
deconv6_1 = layers.Conv2D(filters=512,kernel_size=(3,3),padding="same",kernel_initializer="he_normal",activation="relu")(merge6)
deconv6_2 = layers.Conv2D(filters=512,kernel_size=(3,3),padding="same",kernel_initializer="he_normal",activation="relu")(deconv6_1)
deconv7_up = layers.Conv2D(filters=256,kernel_size=(3,3),padding="same",kernel_initializer="he_normal",activation="relu")(layers.UpSampling2D((2,2))(deconv6_2))
merge7 = layers.concatenate([conv3_2,deconv7_up])
deconv7_1 = layers.Conv2D(filters=256,kernel_size=(3,3),padding="same",kernel_initializer="he_normal",activation="relu")(merge7)
deconv7_2 = layers.Conv2D(filters=256,kernel_size=(3,3),padding="same",kernel_initializer="he_normal",activation="relu")(deconv7_1)
deconv8_up = layers.Conv2D(filters=128, kernel_size=(3, 3), padding="same", kernel_initializer="he_normal",activation="relu")(layers.UpSampling2D((2, 2))(deconv7_2))
merge8 = layers.concatenate([conv2_2, deconv8_up])
deconv8_1 = layers.Conv2D(filters=128, kernel_size=(3, 3), padding="same", kernel_initializer="he_normal", activation="relu")(merge8)
deconv8_2 = layers.Conv2D(filters=128, kernel_size=(3, 3), padding="same", kernel_initializer="he_normal",activation="relu")(deconv8_1)
deconv9_up = layers.Conv2D(filters=64, kernel_size=(3, 3), padding="same", kernel_initializer="he_normal",activation="relu")(layers.UpSampling2D((2, 2))(deconv8_2))
merge9 = layers.concatenate([conv1_2, deconv9_up])
deconv9_1 = layers.Conv2D(filters=64, kernel_size=(3, 3), padding="same", kernel_initializer="he_normal",activation="relu")(merge9)
deconv9_2 = layers.Conv2D(filters=64, kernel_size=(3, 3), padding="same", kernel_initializer="he_normal",activation="relu")(deconv9_1)
###########num_classes的值根据有多少类别决定
###########激活函数sigmoid,因为labels是用one_hot编码
outputs = layers.Conv2D(filters=num_classes, kernel_size=(3, 3), padding="same", kernel_initializer="he_normal",activation="sigmoid")(deconv9_2)
model = keras.models.Model(inputs=inputs,outputs=outputs)
return model
model = U_netModel(2)
print(model.summary())
Keras实现U-Net网络结构
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 原文链接https://blog.csdn.net/qq_33037903/article/details/887...
- 背景简介 在 LeNet 问世后的第4年,2012年, AlexNet 在 ImageNet LSVRC-2010...
- 背景简介 要深入理解卷积神经网络的结构,我们需要追根溯源,只有这样才能更好的理解 CNN 网络。 1998年 Le...
- 十天的学习弹指一挥间。现在再来回顾整理,我为什么加入定位模块学习?这些天收获有哪些?之后如何去行动呢? 一、定位的...