[深度学习从入门到女装]FCN

2023-10-30 08:59
文章标签 学习 入门 深度 fcn 女装

本文主要是介绍[深度学习从入门到女装]FCN,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

论文:Fully Convolutional Networks for Semantic Segmentation

本文简单介绍一下FCN模型,并对caffe源码进行阅读

对于convolution:

output = (input + 2 * padding  - ksize)  / stride + 1;

对于deconvolution:

output = (input - 1) * stride + ksize - 2 * padding;

FCN的整体网络框架是根据VGG16进行修改的,把最后的三层全连接层取消,换上两层conv层,然后最后一层改成上采样也就是deconv,具体的VGG结构请参考VGG

网络结果分为三种FCN-32s、FCN-16s、FCN-8s

FCN-32s:就是整个网络一条路下来,根据5次pool得到的conv7层的特征图(与原图相比缩小32倍),随后进行32倍的反卷积达到和输入图相同的尺寸,然后根据GT(Groud Truth)进行损失训练

FCN-16s:就是把7次pool得到的conv7层的特征图(与原图相比缩小32倍)进行2倍的反卷积得到比原图缩小16倍的特征图,然后把pool4层得到的特征图(与原图相比缩小16倍),将这两个特征图进行fuse操作,作者是使用sum也就是对应位置特征值相加进行fuse操作,随后将得到的融合特征图进行16倍的反卷积得到和输入图相同尺寸

FCN-8s:就是把7次pool得到的conv7层的特征图(与原图相比缩小32倍)进行4倍的反卷积得到比原图缩小8倍的特征图,然后把pool4层得到的特征图(与原图相比缩小16倍)进行2倍的反卷积得到比原图缩小8倍的特征图,再拿pool3层得到的特征图(与原图相比缩小8倍),把这三个特征图也进行sum fuse操作,然后再将这个融合特征图进行8倍反卷积得到与输入图相同尺寸

同样的还可以得到FCN-4s、FCN-2s。但是作者经过测试,再继续做下去完全没有必要,所以对于目前来说,FCN-8s是计算量和准确率相平衡的一种

下边来看看FCN-8s实现的网络caffe代码

fcn8s代码:

layer {
  name: "input"
  type: "Input"
  top: "data"
  input_param {
    # These dimensions are purely for sake of example;
    # see infer.py for how to reshape the net to the given input size.
    shape { dim: 1 dim: 3 dim: 500 dim: 500 }
  }
}

 输入为500*500*3

layer {
  name: "conv1_1"
  type: "Convolution"
  bottom: "data"
  top: "conv1_1"
  param {
    lr_mult: 1
    decay_mult: 1
  }
  param {
    lr_mult: 2
    decay_mult: 0
  }
  convolution_param {
    num_output: 64
    pad: 100
    kernel_size: 3
    stride: 1
  }
}
layer {
  name: "relu1_1"
  type: "ReLU"
  bottom: "conv1_1"
  top: "conv1_1"
}

第一个卷积层conv1_1的pad为100 pad后为700*700*3

使用64个3*3*3进行卷积操作后输出为698*698*64

 layer {
  name: "conv1_2"
  type: "Convolution"
  bottom: "conv1_1"
  top: "conv1_2"
  param {
    lr_mult: 1
    decay_mult: 1
  }
  param {
    lr_mult: 2
    decay_mult: 0
  }
  convolution_param {
    num_output: 64
    pad: 1
    kernel_size: 3
    stride: 1
  }
}
layer {
  name: "relu1_2"
  type: "ReLU"
  bottom: "conv1_2"
  top: "conv1_2"
}

第二个卷积层conv1_2的pad为1 pad后为700*700*64

使用64个3*3*64进行卷积操作后输出为698*698*64

layer {
  name: "pool1"
  type: "Pooling"
  bottom: "conv1_2"
  top: "pool1"
  pooling_param {
    pool: MAX
    kernel_size: 2
    stride: 2
  }
}

 使用stride为2的MAXpool进行pooling后输出为349*349*64

conv2_1:num_output: 128 pad: 1  kernel_size: 3 stride: 1

输出为349*349*128

conv2_2:num_output: 128 pad: 1 kernel_size: 3 stride: 1

输出为349*349*128

pool2:MAXpooling stride2 size2 输出为175*175*128(pool使用向上取整)

conv3_1、conv3_2、conv3_3:num_output: 256 pad: 1 kernel_size: 3 stride: 1

输出为175*175*256

pool3:MAXpooling stride2 size2 输出为88*88*256(pool使用向上取整)

conv4_1、conv4_2、conv4_3:num_output: 512 pad: 1 kernel_size: 3 stride: 1

输出为88*88*512

pool4:MAXpooling stride2 size2 输出为44*44*512(pool使用向上取整)

conv5_1、conv5_2、conv5_3:num_output: 512 pad: 1 kernel_size: 3 stride: 1

输出为44*44*512

pool5:MAXpooling stride2 size2 输出为22*22*512(pool使用向上取整)

layer {
  name: "fc6"
  type: "Convolution"
  bottom: "pool5"
  top: "fc6"
  param {
    lr_mult: 1
    decay_mult: 1
  }
  param {
    lr_mult: 2
    decay_mult: 0
  }
  convolution_param {
    num_output: 4096
    pad: 0
    kernel_size: 7
    stride: 1
  }
}
layer {
  name: "relu6"
  type: "ReLU"
  bottom: "fc6"
  top: "fc6"
}

(这个作者真的懒,改的VGG16的框架,连全连接层的名字都没给改成卷积层。。。)

输入为 22*22*512 输出为16*16*4096

layer {
  name: "fc7"
  type: "Convolution"
  bottom: "fc6"
  top: "fc7"
  param {
    lr_mult: 1
    decay_mult: 1
  }
  param {
    lr_mult: 2
    decay_mult: 0
  }
  convolution_param {
    num_output: 4096
    pad: 0
    kernel_size: 1
    stride: 1
  }
}
layer {
  name: "relu7"
  type: "ReLU"
  bottom: "fc7"
  top: "fc7"
}

 输入为16*16*4096 输出为16*16*4096

layer {
  name: "score_fr"
  type: "Convolution"
  bottom: "fc7"
  top: "score_fr"
  param {
    lr_mult: 1
    decay_mult: 1
  }
  param {
    lr_mult: 2
    decay_mult: 0
  }
  convolution_param {
    num_output: 21
    pad: 0
    kernel_size: 1
  }
}

score_fr:输入为16*16*4096 输出为16*16*21

 layer {
  name: "upscore2"
  type: "Deconvolution"
  bottom: "score_fr"
  top: "upscore2"
  param {
    lr_mult: 0
  }
  convolution_param {
    num_output: 21
    bias_term: false
    kernel_size: 4
    stride: 2
  }
}

 upscore2:输入为16*16*21 输入为34*34*21

layer {
  name: "score_pool4"
  type: "Convolution"
  bottom: "pool4"
  top: "score_pool4"
  param {
    lr_mult: 1
    decay_mult: 1
  }
  param {
    lr_mult: 2
    decay_mult: 0
  }
  convolution_param {
    num_output: 21
    pad: 0
    kernel_size: 1
  }
}

 score_pool4:输入为44*44*512 输出为44*44*21

layer {
  name: "score_pool4c"
  type: "Crop"
  bottom: "score_pool4"
  bottom: "upscore2"
  top: "score_pool4c"
  crop_param {
    axis: 2
    offset: 5
  }
}

 score_pool4c:这一层为对socre_pool4进行裁剪 caffe中crop作用详见Caffe中crop_layer层的理解和使用

输入为44*44*21 输出为34*34*21

layer {
  name: "fuse_pool4"
  type: "Eltwise"
  bottom: "upscore2"
  bottom: "score_pool4c"
  top: "fuse_pool4"
  eltwise_param {
    operation: SUM
  }
}

 fuse_pool4:这一层是为了将upscore2与score_pool4c进行合并,进行不同层次特征融合 输入为34*34*21

layer {
  name: "upscore_pool4"
  type: "Deconvolution"
  bottom: "fuse_pool4"
  top: "upscore_pool4"
  param {
    lr_mult: 0
  }
  convolution_param {
    num_output: 21
    bias_term: false
    kernel_size: 4
    stride: 2
  }
}

upscore_pool4:输入为34*34*21 输出为70*70*21

 layer {
  name: "score_pool3"
  type: "Convolution"
  bottom: "pool3"
  top: "score_pool3"
  param {
    lr_mult: 1
    decay_mult: 1
  }
  param {
    lr_mult: 2
    decay_mult: 0
  }
  convolution_param {
    num_output: 21
    pad: 0
    kernel_size: 1
  }
}

 score_pool3:输入为88*88*256 输出为88*88*21

layer {
  name: "score_pool3c"
  type: "Crop"
  bottom: "score_pool3"
  bottom: "upscore_pool4"
  top: "score_pool3c"
  crop_param {
    axis: 2
    offset: 9
  }
}

 score_pool3c:这层将score_pool3进行裁剪为和upscore_pool4相同尺寸

输入为88*88*21 输出为70*70*21

layer {
  name: "fuse_pool3"
  type: "Eltwise"
  bottom: "upscore_pool4"
  bottom: "score_pool3c"
  top: "fuse_pool3"
  eltwise_param {
    operation: SUM
  }
}

 fuse_pool3:将upscore_pool4和score_pool3c特征图融合相加 输出为70*70*21

layer {
  name: "upscore8"
  type: "Deconvolution"
  bottom: "fuse_pool3"
  top: "upscore8"
  param {
    lr_mult: 0
  }
  convolution_param {
    num_output: 21
    bias_term: false
    kernel_size: 16
    stride: 8
  }
}

 upscore8:输入为70*70*21 输出为568*568*21

layer {
  name: "score"
  type: "Crop"
  bottom: "upscore8"
  bottom: "data"
  top: "score"
  crop_param {
    axis: 2
    offset: 31
  }
}

 score:对最终分割图进行裁剪 输出为506*506*21

 

通过源码我们可以看到,先实现过程中,并不是像上边图片上画的输入和输出尺寸相同,存在一定偏差,这也是因为,作者在第一次卷积的时候进行一次100的padding,是为了防止图像过小,缩小32次后,特征无法反向传播回去,然后最后根据多次cropping,将不同尺寸的特征图调整完相同的尺寸,最终得到506*506的输入图

这篇关于[深度学习从入门到女装]FCN的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/306820

相关文章

Java深度学习库DJL实现Python的NumPy方式

《Java深度学习库DJL实现Python的NumPy方式》本文介绍了DJL库的背景和基本功能,包括NDArray的创建、数学运算、数据获取和设置等,同时,还展示了如何使用NDArray进行数据预处理... 目录1 NDArray 的背景介绍1.1 架构2 JavaDJL使用2.1 安装DJL2.2 基本操

最长公共子序列问题的深度分析与Java实现方式

《最长公共子序列问题的深度分析与Java实现方式》本文详细介绍了最长公共子序列(LCS)问题,包括其概念、暴力解法、动态规划解法,并提供了Java代码实现,暴力解法虽然简单,但在大数据处理中效率较低,... 目录最长公共子序列问题概述问题理解与示例分析暴力解法思路与示例代码动态规划解法DP 表的构建与意义动

Go中sync.Once源码的深度讲解

《Go中sync.Once源码的深度讲解》sync.Once是Go语言标准库中的一个同步原语,用于确保某个操作只执行一次,本文将从源码出发为大家详细介绍一下sync.Once的具体使用,x希望对大家有... 目录概念简单示例源码解读总结概念sync.Once是Go语言标准库中的一个同步原语,用于确保某个操

五大特性引领创新! 深度操作系统 deepin 25 Preview预览版发布

《五大特性引领创新!深度操作系统deepin25Preview预览版发布》今日,深度操作系统正式推出deepin25Preview版本,该版本集成了五大核心特性:磐石系统、全新DDE、Tr... 深度操作系统今日发布了 deepin 25 Preview,新版本囊括五大特性:磐石系统、全新 DDE、Tree

Node.js 中 http 模块的深度剖析与实战应用小结

《Node.js中http模块的深度剖析与实战应用小结》本文详细介绍了Node.js中的http模块,从创建HTTP服务器、处理请求与响应,到获取请求参数,每个环节都通过代码示例进行解析,旨在帮... 目录Node.js 中 http 模块的深度剖析与实战应用一、引言二、创建 HTTP 服务器:基石搭建(一

HarmonyOS学习(七)——UI(五)常用布局总结

自适应布局 1.1、线性布局(LinearLayout) 通过线性容器Row和Column实现线性布局。Column容器内的子组件按照垂直方向排列,Row组件中的子组件按照水平方向排列。 属性说明space通过space参数设置主轴上子组件的间距,达到各子组件在排列上的等间距效果alignItems设置子组件在交叉轴上的对齐方式,且在各类尺寸屏幕上表现一致,其中交叉轴为垂直时,取值为Vert

Ilya-AI分享的他在OpenAI学习到的15个提示工程技巧

Ilya(不是本人,claude AI)在社交媒体上分享了他在OpenAI学习到的15个Prompt撰写技巧。 以下是详细的内容: 提示精确化:在编写提示时,力求表达清晰准确。清楚地阐述任务需求和概念定义至关重要。例:不用"分析文本",而用"判断这段话的情感倾向:积极、消极还是中性"。 快速迭代:善于快速连续调整提示。熟练的提示工程师能够灵活地进行多轮优化。例:从"总结文章"到"用

Spring Security 从入门到进阶系列教程

Spring Security 入门系列 《保护 Web 应用的安全》 《Spring-Security-入门(一):登录与退出》 《Spring-Security-入门(二):基于数据库验证》 《Spring-Security-入门(三):密码加密》 《Spring-Security-入门(四):自定义-Filter》 《Spring-Security-入门(五):在 Sprin

【前端学习】AntV G6-08 深入图形与图形分组、自定义节点、节点动画(下)

【课程链接】 AntV G6:深入图形与图形分组、自定义节点、节点动画(下)_哔哩哔哩_bilibili 本章十吾老师讲解了一个复杂的自定义节点中,应该怎样去计算和绘制图形,如何给一个图形制作不间断的动画,以及在鼠标事件之后产生动画。(有点难,需要好好理解) <!DOCTYPE html><html><head><meta charset="UTF-8"><title>06

学习hash总结

2014/1/29/   最近刚开始学hash,名字很陌生,但是hash的思想却很熟悉,以前早就做过此类的题,但是不知道这就是hash思想而已,说白了hash就是一个映射,往往灵活利用数组的下标来实现算法,hash的作用:1、判重;2、统计次数;