这里的网络架构和论文中插图中的网络架构是相一致的。对了,忘了说了,这里使用的keras版本是1.2.2,等源码读完之后,我自己改一个2.0.6版本上传到github上面。可别直接粘贴复制,里面有些中文的解释,不一定可行的。#defint input shapeinput_shape = (300,300,3)#defint the number of classes
num_classes = 21
#Here the network is wrapped in to a dictory because it more easy to make some operations.
net = {}
# Block 1
input_tensor = Input(shape=input_shape)#defint the image hight and wight
img_size = (input_shape[1], input_shape[0])
net['input'] = input_tensor
net['conv1_1'] = Convolution2D(64, 3, 3,activation='relu',border_mode='same',name='conv1_1')(net['input'])
net['conv1_2'] = Convolution2D(64, 3, 3,activation='relu',border_mode='same',name='conv1_2')(net['conv1_1'])
net['pool1'] = MaxPooling2D((2, 2), strides=(2, 2), border_mode='same',name='pool1')(net['conv1_2'])
# Block 2
net['conv2_1'] = Convolution2D(128, 3, 3,activation='relu',border_mode='same',name='conv2_1')(net['pool1'])
net['conv2_2'] = Convolution2D(128, 3, 3,activation='relu',border_mode='same',name='conv2_2')(net['conv2_1'])
net['pool2'] = MaxPooling2D((2, 2), strides=(2, 2), border_mode='same',name='pool2')(net['conv2_2'])
# Block 3
net['conv3_1'] = Convolution2D(256, 3, 3,activation='relu',border_mode='same',name='conv3_1')(net['pool2'])
net['conv3_2'] = Convolution2D(256, 3, 3,activation='relu',border_mode='same',name='conv3_2')(net['conv3_1'])
net['conv3_3'] = Convolution2D(256, 3, 3,activation='relu',border_mode='same',name='conv3_3')(net['conv3_2'])
net['pool3'] = MaxPooling2D((2, 2), strides=(2, 2), border_mode='same',name='pool3')(net['conv3_3'])
# Block 4
net['conv4_1'] = Convolution2D(512, 3, 3,activation='relu',border_mode='same',name='conv4_1')(net['pool3'])
net['conv4_2'] = Convolution2D(512, 3, 3,activation='relu',border_mode='same',name='conv4_2')(net['conv4_1'])#the first layer be operated
net['conv4_3'] = Convolution2D(512, 3, 3,activation='relu',border_mode='same',name='conv4_3')(net['conv4_2'])
net['pool4'] = MaxPooling2D((2, 2), strides=(2, 2), border_mode='same',name='pool4')(net['conv4_3'])
# Block 5
net['conv5_1'] = Convolution2D(512, 3, 3,activation='relu',border_mode='same',name='conv5_1')(net['pool4'])
net['conv5_2'] = Convolution2D(512, 3, 3,activation='relu',border_mode='same',name='conv5_2')(net['conv5_1'])
net['conv5_3'] = Convolution2D(512, 3, 3,activation='relu',border_mode='same',name='conv5_3')(net['conv5_2'])
net['pool5'] = MaxPooling2D((3, 3), strides=(1, 1), border_mode='same',name='pool5')(net['conv5_3'])#here is the FC6 in the orginal VGG16 Network,There move to Atrous Convolution for the reason i don't know.
# FC6
net['fc6'] = AtrousConvolution2D(1024, 3, 3, atrous_rate=(6, 6),activation='relu', border_mode='same',name='fc6')(net['pool5'])#the second layer to be operated
# FC7
net['fc7'] = Convolution2D(1024, 1, 1, activation='relu',border_mode='same', name='fc7')(net['fc6'])
# x = Dropout(0.5, name='drop7')(x)
# Block 6
net['conv6_1'] = Convolution2D(256, 1, 1, activation='relu',border_mode='same',name='conv6_1')(net['fc7'])#the third layer to be opreated
net['conv6_2'] = Convolution2D(512, 3, 3, subsample=(2, 2),activation='relu', border_mode='same',name='conv6_2')(net['conv6_1'])
# Block 7
net['conv7_1'] = Convolution2D(128, 1, 1, activation='relu',border_mode='same',name='conv7_1')(net['conv6_2'])
net['conv7_2'] = ZeroPadding2D()(net['conv7_1'])#the forth layer to be operated
net['conv7_2'] = Convolution2D(256, 3, 3, subsample=(2, 2),activation='relu', border_mode='valid',name='conv7_2')(net['conv7_2'])
# Block 8
net['conv8_1'] = Convolution2D(128, 1, 1, activation='relu',border_mode='same',name='conv8_1')(net['conv7_2'])#the fifth layer to be operated
net['conv8_2'] = Convolution2D(256, 3, 3, subsample=(2, 2),activation='relu', border_mode='same',name='conv8_2')(net['conv8_1'])# the last layer to be operated
# Last Pool
net['pool6'] = GlobalAveragePooling2D(name='pool6')(net['conv8_2'])

# Prediction from conv4_3# net['conv4_3']._shape = (?, 38, 38, 512)# 算了还是说中文吧,这个层是用来对输入数据进行正则化的层,有参数需要学习,输出的数据形式和输入输入形式是一致的。
net['conv4_3_norm'] = Normalize(20, name='conv4_3_norm')(net['conv4_3'])
num_priors = 3
#here is *4 because the box need 4 number to define,here is only predice the box coordinate
x = Convolution2D(num_priors * 4, 3, 3, border_mode='same',name='conv4_3_norm_mbox_loc')(net['conv4_3_norm'])
net['conv4_3_norm_mbox_loc'] = x
flatten = Flatten(name='conv4_3_norm_mbox_loc_flat')
net['conv4_3_norm_mbox_loc_flat'] = flatten(net['conv4_3_norm_mbox_loc'])#the box coordinate is finished now it will perdice the classes
name = 'conv4_3_norm_mbox_conf'
if num_classes != 21:name += '_{}'.format(num_classes)# here is start predict the classes
x = Convolution2D(num_priors * num_classes, 3, 3, border_mode='same',name=name)(net['conv4_3_norm'])
net['conv4_3_norm_mbox_conf'] = x
flatten = Flatten(name='conv4_3_norm_mbox_conf_flat')
net['conv4_3_norm_mbox_conf_flat'] = flatten(net['conv4_3_norm_mbox_conf'])#这里是用来对conv4_3层的feature map生成论文中所说的default box,对没错,就是直接使用Feature map来进行default box的生成#当然这里要指定一些参数,这些参数是需要好好斟酌的。
priorbox = PriorBox(img_size, 30.0, aspect_ratios=[2],variances=[0.1, 0.1, 0.2, 0.2],name='conv4_3_norm_mbox_priorbox')
net['conv4_3_norm_mbox_priorbox'] = priorbox(net['conv4_3_norm'])
#好了,到这里第一个层的操作就完成了,下面其他层的操作都是相类似的啦。
# Prediction from fc7
num_priors = 6
net['fc7_mbox_loc'] = Convolution2D(num_priors * 4, 3, 3,border_mode='same',name='fc7_mbox_loc')(net['fc7'])
flatten = Flatten(name='fc7_mbox_loc_flat')
net['fc7_mbox_loc_flat'] = flatten(net['fc7_mbox_loc'])
name = 'fc7_mbox_conf'
if num_classes != 21:name += '_{}'.format(num_classes)
net['fc7_mbox_conf'] = Convolution2D(num_priors * num_classes, 3, 3,border_mode='same',name=name)(net['fc7'])
flatten = Flatten(name='fc7_mbox_conf_flat')
net['fc7_mbox_conf_flat'] = flatten(net['fc7_mbox_conf'])
priorbox = PriorBox(img_size, 60.0, max_size=114.0, aspect_ratios=[2, 3],variances=[0.1, 0.1, 0.2, 0.2],name='fc7_mbox_priorbox')
net['fc7_mbox_priorbox'] = priorbox(net['fc7'])
# Prediction from conv6_2
num_priors = 6
x = Convolution2D(num_priors * 4, 3, 3, border_mode='same',name='conv6_2_mbox_loc')(net['conv6_2'])
net['conv6_2_mbox_loc'] = x
flatten = Flatten(name='conv6_2_mbox_loc_flat')
net['conv6_2_mbox_loc_flat'] = flatten(net['conv6_2_mbox_loc'])
name = 'conv6_2_mbox_conf'
if num_classes != 21:name += '_{}'.format(num_classes)
x = Convolution2D(num_priors * num_classes, 3, 3, border_mode='same',name=name)(net['conv6_2'])
net['conv6_2_mbox_conf'] = x
flatten = Flatten(name='conv6_2_mbox_conf_flat')
net['conv6_2_mbox_conf_flat'] = flatten(net['conv6_2_mbox_conf'])
priorbox = PriorBox(img_size, 114.0, max_size=168.0, aspect_ratios=[2, 3],variances=[0.1, 0.1, 0.2, 0.2],name='conv6_2_mbox_priorbox')
net['conv6_2_mbox_priorbox'] = priorbox(net['conv6_2'])
# Prediction from conv7_2
num_priors = 6
x = Convolution2D(num_priors * 4, 3, 3, border_mode='same',name='conv7_2_mbox_loc')(net['conv7_2'])
net['conv7_2_mbox_loc'] = x
flatten = Flatten(name='conv7_2_mbox_loc_flat')
net['conv7_2_mbox_loc_flat'] = flatten(net['conv7_2_mbox_loc'])
name = 'conv7_2_mbox_conf'
if num_classes != 21:name += '_{}'.format(num_classes)
x = Convolution2D(num_priors * num_classes, 3, 3, border_mode='same',name=name)(net['conv7_2'])
net['conv7_2_mbox_conf'] = x
flatten = Flatten(name='conv7_2_mbox_conf_flat')
net['conv7_2_mbox_conf_flat'] = flatten(net['conv7_2_mbox_conf'])
priorbox = PriorBox(img_size, 168.0, max_size=222.0, aspect_ratios=[2, 3],variances=[0.1, 0.1, 0.2, 0.2],name='conv7_2_mbox_priorbox')
net['conv7_2_mbox_priorbox'] = priorbox(net['conv7_2'])
# Prediction from conv8_2
num_priors = 6
x = Convolution2D(num_priors * 4, 3, 3, border_mode='same',name='conv8_2_mbox_loc')(net['conv8_2'])
net['conv8_2_mbox_loc'] = x
flatten = Flatten(name='conv8_2_mbox_loc_flat')
net['conv8_2_mbox_loc_flat'] = flatten(net['conv8_2_mbox_loc'])
name = 'conv8_2_mbox_conf'
if num_classes != 21:name += '_{}'.format(num_classes)
x = Convolution2D(num_priors * num_classes, 3, 3, border_mode='same',name=name)(net['conv8_2'])
net['conv8_2_mbox_conf'] = x
flatten = Flatten(name='conv8_2_mbox_conf_flat')
net['conv8_2_mbox_conf_flat'] = flatten(net['conv8_2_mbox_conf'])
priorbox = PriorBox(img_size, 222.0, max_size=276.0, aspect_ratios=[2, 3],variances=[0.1, 0.1, 0.2, 0.2],name='conv8_2_mbox_priorbox')
net['conv8_2_mbox_priorbox'] = priorbox(net['conv8_2'])
# Prediction from pool6
num_priors = 6
x = Dense(num_priors * 4, name='pool6_mbox_loc_flat')(net['pool6'])
net['pool6_mbox_loc_flat'] = x
name = 'pool6_mbox_conf_flat'
if num_classes != 21:name += '_{}'.format(num_classes)
x = Dense(num_priors * num_classes, name=name)(net['pool6'])
net['pool6_mbox_conf_flat'] = x
priorbox = PriorBox(img_size, 276.0, max_size=330.0, aspect_ratios=[2, 3],variances=[0.1, 0.1, 0.2, 0.2],name='pool6_mbox_priorbox')#由于这里的维数不对,因此要修改Feature map层对应的维数信息
if K.image_dim_ordering() == 'tf':target_shape = (1, 1, 256)
else:target_shape = (256, 1, 1)
net['pool6_reshaped'] = Reshape(target_shape,name='pool6_reshaped')(net['pool6'])
net['pool6_mbox_priorbox'] = priorbox(net['pool6_reshaped'])#好啦,到这里位置,所有的信息都已经生成了,下一步就是根据这些信息来进行训练或者是预测了。
# Gather all predictions
net['mbox_loc'] = merge([net['conv4_3_norm_mbox_loc_flat'],net['fc7_mbox_loc_flat'],net['conv6_2_mbox_loc_flat'],net['conv7_2_mbox_loc_flat'],net['conv8_2_mbox_loc_flat'],net['pool6_mbox_loc_flat']],mode='concat', concat_axis=1, name='mbox_loc')
net['mbox_conf'] = merge([net['conv4_3_norm_mbox_conf_flat'],net['fc7_mbox_conf_flat'],net['conv6_2_mbox_conf_flat'],net['conv7_2_mbox_conf_flat'],net['conv8_2_mbox_conf_flat'],net['pool6_mbox_conf_flat']],mode='concat', concat_axis=1, name='mbox_conf')
net['mbox_priorbox'] = merge([net['conv4_3_norm_mbox_priorbox'],net['fc7_mbox_priorbox'],net['conv6_2_mbox_priorbox'],net['conv7_2_mbox_priorbox'],net['conv8_2_mbox_priorbox'],net['pool6_mbox_priorbox']],mode='concat', concat_axis=1,name='mbox_priorbox')
if hasattr(net['mbox_loc'], '_keras_shape'):num_boxes = net['mbox_loc']._keras_shape[-1] // 4
elif hasattr(net['mbox_loc'], 'int_shape'):num_boxes = K.int_shape(net['mbox_loc'])[-1] // 4
net['mbox_loc'] = Reshape((num_boxes, 4),name='mbox_loc_final')(net['mbox_loc'])
net['mbox_conf'] = Reshape((num_boxes, num_classes),name='mbox_conf_logits')(net['mbox_conf'])
net['mbox_conf'] = Activation('softmax',name='mbox_conf_final')(net['mbox_conf'])
net['predictions'] = merge([net['mbox_loc'],net['mbox_conf'],net['mbox_priorbox']],mode='concat', concat_axis=2,name='predictions')
model = Model(net['input'], net['predictions'])

转载于:https://www.cnblogs.com/andyniu/p/7469090.html

SSD Network Architecture--keras version相关推荐

  1. 文献阅读(part1)--A Survey of Clustering With Deep Learning From the Perspective of Network Architecture

    论文学习 文章目录 摘要 介绍 前言 NEURAL NETWORK ARCHITECTURE FOR DEEP CLUSTERING LOSS FUNCTIONS RELATED TO CLUSTER ...

  2. Clearing the Skies: A deep network architecture for single-image rain removal解读

    Clearing the Skies: A deep network architecture for single-image rain removal解读 Abstract 1.Introduct ...

  3. 2016 ECCV-Gated Siamese Convolutional Neural Network Architecture for Human Re-ID

    论文地址 第一篇论文笔记,希望大家能多提些意见来帮助我提高论文笔记模型的性能.相关方向的童鞋可以加qq:396543018一起交流~ Motivation 现在的Siamese CNN对每个照片仅在f ...

  4. 【Network Architecture】Densely Connected Convolutional Networks 论文解析

    [Network Architecture]Densely Connected Convolutional Networks 论文解析 目录 0. Paper link 1. Overview 2. ...

  5. Fat-tree:A Scalable, Commodity Data Center Network Architecture 解读

    Fat-tree:A Scalable, Commodity Data Center Network Architecture 解读 title: 一种可扩展的.商品化的数据中心网络体系结构 第一部分 ...

  6. 【论文翻译】HEMET: A Homomorphic-Encryption-Friendly Privacy-Preserving Mobile Neural Network Architecture

    [原文链接]HEMET: A Homomorphic-Encryption-Friendly Privacy-Preserving Mobile Neural Network Architecture ...

  7. Nested Named Entity Recognition from Medical Texts: An Adaptive Shared Network Architecture with Att

    论文名称:Nested Named Entity Recognition from Medical Texts: An Adaptive Shared Network Architecture wit ...

  8. 网络结构搜索 (NAS: Network Architecture Search)

    NAS Definition 基于搜索策略,并结合约束条件 (如accuracy.latency),在搜索空间内 (set of candidate operations or blocks)探索最优 ...

  9. [Network Architecture]DPN(Dual Path Network)算法详解(转)

    https://blog.csdn.net/u014380165/article/details/75676216 论文:Dual Path Networks 论文链接:https://arxiv.o ...

最新文章

  1. 共面阻抗对高频PCB 设计中传输线阻抗控制的影响
  2. OC第二节 继承、初始化⽅法、便利构造器
  3. [转载]HTTP PUSH技术原理,结合ASP.NET实现以及评述
  4. 蓝桥备赛第一周2021.1.11 递归 枚举 位运算
  5. C .Adding Powers codeforces(位运算思维)
  6. Flutter下拉刷新,上拉加载更多数据
  7. Kubernetes学习总结(13)—— Kubernetes 各个组件的概念
  8. HTML批量转换jpg,html转换为图片(html to jpg)
  9. gradle 编译失败,出现 permgen space的问题
  10. C#笔记04 数组和循环
  11. c++中#pragma用法详解
  12. caffe安装编译问题-ImportError: No module named caffe
  13. Redis开源文档《Redis设计与实现》
  14. 苹果4s刷linux,苹果4s降级教程【图解】
  15. php 音频上传之ogg格式,如何快速将MP3格式转化成ogg格式
  16. 【物联网】Arduino Uno开发板连接阿里云实现云端远程控制LED灯开关
  17. 05-SparkRDD原理和编程接口
  18. 不等式的格式(python)
  19. TI单芯片毫米波雷达代码走读(二十五)—— 角度维(3D)处理流程
  20. docker替换阿里云镜像源

热门文章

  1. python进阶03UnboundLocalError和NameError错误
  2. 港股打新之卖出策略(暗盘和首日)
  3. 使用青云主机的GPU主机教程(不完整版)
  4. linux下mongo工具,linux – 从另一台机器上使用mongodb工具(mongodump,mongorestore)
  5. java语言c语言基础_新手入门选什么:有些人说C语言要比Java更难!你应该怎么办?...
  6. 得到选择框句柄 怎么操作_怎么选择小前锋才能在NBA2kol2中使自己的阵容得到提升...
  7. python参数的解包(拆包)(一分钟读懂)
  8. Aizu ITP2_6_A 二分
  9. pytorch学习笔记(十三):Dropout
  10. 李宏毅机器学习 1.Machine Learning_introduction