• 【659】DeConvNet 模型说明


    [1] DeconvNet 模型说明

    [2] github - dongmeixu/Keras-DeconvNet-Segmentation

      模型结构图

      实现代码:(二分类)

    from keras.models import Model
    from keras.layers import Input, Conv2D, MaxPooling2D, UpSampling2D, BatchNormalization
    from keras.layers.convolutional import Conv2DTranspose
    from keras.callbacks import ModelCheckpoint
    import os
    import tensorflow as tf
    import pandas as pd
    import numpy as np
    import random
    import cv2
    
    
    def get_net(img_size):
        inputs = Input(img_size)
        conv1_1 = Conv2D(filters=64, kernel_size=(3, 3), padding="same", activation="relu")(inputs)
        conv1_2 = Conv2D(filters=64, kernel_size=(3, 3), padding="same", activation="relu")(conv1_1)
        conv1_2 = BatchNormalization()(conv1_2)
        pool1 = MaxPooling2D(pool_size=(2, 2), strides=(2, 2))(conv1_2)
    
        conv2_1 = Conv2D(filters=128, kernel_size=(3, 3), padding="same", activation="relu")(pool1)
        conv2_2 = Conv2D(filters=128, kernel_size=(3, 3), padding="same", activation="relu")(conv2_1)
        conv2_2 = BatchNormalization()(conv2_2)
        pool2 = MaxPooling2D(pool_size=(2, 2), strides=(2, 2))(conv2_2)
    
        conv3_1 = Conv2D(filters=256, kernel_size=(3, 3), padding="same", activation="relu")(pool2)
        conv3_2 = Conv2D(filters=256, kernel_size=(3, 3), padding="same", activation="relu")(conv3_1)
        conv3_3 = Conv2D(filters=256, kernel_size=(3, 3), padding="same", activation="relu")(conv3_2)
        conv3_3 = BatchNormalization()(conv3_3)
        pool3 = MaxPooling2D(pool_size=(2, 2), strides=(2, 2))(conv3_3)
    
        conv4_1 = Conv2D(filters=512, kernel_size=(3, 3), padding="same", activation="relu")(pool3)
        conv4_2 = Conv2D(filters=512, kernel_size=(3, 3), padding="same", activation="relu")(conv4_1)
        conv4_3 = Conv2D(filters=512, kernel_size=(3, 3), padding="same", activation="relu")(conv4_2)
        conv4_3 = BatchNormalization()(conv4_3)
        pool4 = MaxPooling2D(pool_size=(2, 2), strides=(2, 2))(conv4_3)
    
        conv5_1 = Conv2D(filters=512, kernel_size=(3, 3), padding="same", activation="relu")(pool4)
        conv5_2 = Conv2D(filters=512, kernel_size=(3, 3), padding="same", activation="relu")(conv5_1)
        conv5_3 = Conv2D(filters=512, kernel_size=(3, 3), padding="same", activation="relu")(conv5_2)
        conv5_3 = BatchNormalization()(conv5_3)
        pool5 = MaxPooling2D(pool_size=(2, 2), strides=(2, 2))(conv5_3)
    
        fc6 = Conv2D(filters=4096, kernel_size=(5, 5), activation="relu")(pool5)
        fc7 = Conv2D(filters=4096, kernel_size=(1, 1), activation="relu")(fc6)
    
        deconv_fc6 = Conv2DTranspose(filters=512, kernel_size=(5, 5))(fc7)
        deconv_fc6 = BatchNormalization()(deconv_fc6)
        unpool5 = UpSampling2D(size=(2, 2))(deconv_fc6)
    
        deconv5_1 = Conv2DTranspose(filters=512, kernel_size=(3, 3), padding="same", activation="relu")(unpool5)
        deconv5_2 = Conv2DTranspose(filters=512, kernel_size=(3, 3), padding="same", activation="relu")(deconv5_1)
        deconv5_3 = Conv2DTranspose(filters=512, kernel_size=(3, 3), padding="same", activation="relu")(deconv5_2)
        deconv5_3 = BatchNormalization()(deconv5_3)
        unpool4 = UpSampling2D(size=(2, 2))(deconv5_3)
    
        deconv4_1 = Conv2DTranspose(filters=512, kernel_size=(3, 3), padding="same", activation="relu")(unpool4)
        deconv4_2 = Conv2DTranspose(filters=512, kernel_size=(3, 3), padding="same", activation="relu")(deconv4_1)
        deconv4_3 = Conv2DTranspose(filters=256, kernel_size=(3, 3), padding="same", activation="relu")(deconv4_2)
        deconv4_3 = BatchNormalization()(deconv4_3)
        unpool3 = UpSampling2D(size=(2, 2))(deconv4_3)
    
        deconv3_1 = Conv2DTranspose(filters=256, kernel_size=(3, 3), padding="same", activation="relu")(unpool3)
        deconv3_2 = Conv2DTranspose(filters=256, kernel_size=(3, 3), padding="same", activation="relu")(deconv3_1)
        deconv3_3 = Conv2DTranspose(filters=128, kernel_size=(3, 3), padding="same", activation="relu")(deconv3_2)
        deconv3_3 = BatchNormalization()(deconv3_3)
        unpool2 = UpSampling2D(size=(2, 2))(deconv3_3)
    
        deconv2_1 = Conv2DTranspose(filters=128, kernel_size=(3, 3), padding="same", activation="relu")(unpool2)
        deconv2_2 = Conv2DTranspose(filters=64, kernel_size=(3, 3), padding="same", activation="relu")(deconv2_1)
        deconv2_2 = BatchNormalization()(deconv2_2)
        unpool1 = UpSampling2D(size=(2, 2))(deconv2_2)
    
        deconv1_1 = Conv2DTranspose(filters=64, kernel_size=(3, 3), padding="same", activation="relu")(unpool1)
        deconv1_2 = Conv2DTranspose(filters=64, kernel_size=(3, 3), padding="same", activation="relu")(deconv1_1)
        deconv1_2 = BatchNormalization()(deconv1_2)
        output = Conv2D(1, kernel_size=(1, 1), activation='sigmoid')(deconv1_2)
    
        model = Model(inputs=inputs, outputs=output)
        return model
    
    
    model = get_net((512,512,3))
    model.summary() 
    

      summary

    Model: "model"
    _________________________________________________________________
    Layer (type) Output Shape Param #
    =================================================================
    input_3 (InputLayer) [(None, 512, 512, 3)] 0
    _________________________________________________________________
    conv2d_31 (Conv2D) (None, 512, 512, 64) 1792
    _________________________________________________________________
    conv2d_32 (Conv2D) (None, 512, 512, 64) 36928
    _________________________________________________________________
    batch_normalization_22 (Batc (None, 512, 512, 64) 256
    _________________________________________________________________
    max_pooling2d_10 (MaxPooling (None, 256, 256, 64) 0
    _________________________________________________________________
    conv2d_33 (Conv2D) (None, 256, 256, 128) 73856
    _________________________________________________________________
    conv2d_34 (Conv2D) (None, 256, 256, 128) 147584
    _________________________________________________________________
    batch_normalization_23 (Batc (None, 256, 256, 128) 512
    _________________________________________________________________
    max_pooling2d_11 (MaxPooling (None, 128, 128, 128) 0
    _________________________________________________________________
    conv2d_35 (Conv2D) (None, 128, 128, 256) 295168
    _________________________________________________________________
    conv2d_36 (Conv2D) (None, 128, 128, 256) 590080
    _________________________________________________________________
    conv2d_37 (Conv2D) (None, 128, 128, 256) 590080
    _________________________________________________________________
    batch_normalization_24 (Batc (None, 128, 128, 256) 1024
    _________________________________________________________________
    max_pooling2d_12 (MaxPooling (None, 64, 64, 256) 0
    _________________________________________________________________
    conv2d_38 (Conv2D) (None, 64, 64, 512) 1180160
    _________________________________________________________________
    conv2d_39 (Conv2D) (None, 64, 64, 512) 2359808
    _________________________________________________________________
    conv2d_40 (Conv2D) (None, 64, 64, 512) 2359808
    _________________________________________________________________
    batch_normalization_25 (Batc (None, 64, 64, 512) 2048
    _________________________________________________________________
    max_pooling2d_13 (MaxPooling (None, 32, 32, 512) 0
    _________________________________________________________________
    conv2d_41 (Conv2D) (None, 32, 32, 512) 2359808
    _________________________________________________________________
    conv2d_42 (Conv2D) (None, 32, 32, 512) 2359808
    _________________________________________________________________
    conv2d_43 (Conv2D) (None, 32, 32, 512) 2359808
    _________________________________________________________________
    batch_normalization_26 (Batc (None, 32, 32, 512) 2048
    _________________________________________________________________
    max_pooling2d_14 (MaxPooling (None, 16, 16, 512) 0
    _________________________________________________________________
    conv2d_44 (Conv2D) (None, 12, 12, 4096) 52432896
    _________________________________________________________________
    conv2d_45 (Conv2D) (None, 12, 12, 4096) 16781312
    _________________________________________________________________
    conv2d_transpose_28 (Conv2DT (None, 16, 16, 512) 52429312
    _________________________________________________________________
    batch_normalization_27 (Batc (None, 16, 16, 512) 2048
    _________________________________________________________________
    up_sampling2d_10 (UpSampling (None, 32, 32, 512) 0
    _________________________________________________________________
    conv2d_transpose_29 (Conv2DT (None, 32, 32, 512) 2359808
    _________________________________________________________________
    conv2d_transpose_30 (Conv2DT (None, 32, 32, 512) 2359808
    _________________________________________________________________
    conv2d_transpose_31 (Conv2DT (None, 32, 32, 512) 2359808
    _________________________________________________________________
    batch_normalization_28 (Batc (None, 32, 32, 512) 2048
    _________________________________________________________________
    up_sampling2d_11 (UpSampling (None, 64, 64, 512) 0
    _________________________________________________________________
    conv2d_transpose_32 (Conv2DT (None, 64, 64, 512) 2359808
    _________________________________________________________________
    conv2d_transpose_33 (Conv2DT (None, 64, 64, 512) 2359808
    _________________________________________________________________
    conv2d_transpose_34 (Conv2DT (None, 64, 64, 256) 1179904
    _________________________________________________________________
    batch_normalization_29 (Batc (None, 64, 64, 256) 1024
    _________________________________________________________________
    up_sampling2d_12 (UpSampling (None, 128, 128, 256) 0
    _________________________________________________________________
    conv2d_transpose_35 (Conv2DT (None, 128, 128, 256) 590080
    _________________________________________________________________
    conv2d_transpose_36 (Conv2DT (None, 128, 128, 256) 590080
    _________________________________________________________________
    conv2d_transpose_37 (Conv2DT (None, 128, 128, 128) 295040
    _________________________________________________________________
    batch_normalization_30 (Batc (None, 128, 128, 128) 512
    _________________________________________________________________
    up_sampling2d_13 (UpSampling (None, 256, 256, 128) 0
    _________________________________________________________________
    conv2d_transpose_38 (Conv2DT (None, 256, 256, 128) 147584
    _________________________________________________________________
    conv2d_transpose_39 (Conv2DT (None, 256, 256, 64) 73792
    _________________________________________________________________
    batch_normalization_31 (Batc (None, 256, 256, 64) 256
    _________________________________________________________________
    up_sampling2d_14 (UpSampling (None, 512, 512, 64) 0
    _________________________________________________________________
    conv2d_transpose_40 (Conv2DT (None, 512, 512, 64) 36928
    _________________________________________________________________
    conv2d_transpose_41 (Conv2DT (None, 512, 512, 64) 36928
    _________________________________________________________________
    batch_normalization_32 (Batc (None, 512, 512, 64) 256
    _________________________________________________________________
    conv2d_46 (Conv2D) (None, 512, 512, 1) 65
    =================================================================
    Total params: 151,119,681
    Trainable params: 151,113,665
    Non-trainable params: 6,016
    _________________________________________________________________

      模型网络结构:

  • 相关阅读:
    KINDLE 小说下载--超级书库
    修改PR Cs6,PS Cs6,AU Cs6的启动界面
    SQLMAP用户手册
    Burp Suite 实战指南--说明书
    XSS跨站测试代码
    万能密码字典
    python数据结构之队列(一)
    python数据结构之栈
    python实现链表(二)
    python实现链表(一)
  • 原文地址:https://www.cnblogs.com/alex-bn-lee/p/15238042.html
Copyright © 2020-2023  润新知