使用 TF-Slim 设计复杂网络

原文地址:https://mp.weixin.qq.com/s/gUDJuS1HKkxUZaCHHUj7aw

TF-Slim 是一个新的轻量的 TensorFlow 高级 API(tensorflow.contrib.slim),用于定义、训练、评估复杂模型。参考材料【1】包含几个广泛使用的 CNN 图像分类模型代码,可以利用提供的脚本从头训练一个模型,或者使用预训练的网络权值微调。TF-Slim 附带下载标准图像数据集、转换为 TensorFlow 原生 TFRecord 格式、使用 TF-Slim 数据读取队列等功能,可以很方便地在公开数据集上训练任意模型,包括 GoogLeNet【2】、Inception-v2【3】、Inception-v3【4】、Inception-v4【5】以及前两篇介绍的 MobileNet(用于移动和嵌入式视觉应用的 MobileNets)和 ShuffleNet(ShuffleNet——面向移动设备的极为高效的卷积神经网络)。

GoogLeNet 曾获得 ILSVRC 2014 比赛图像分类和目标检测项目冠军,其独特的 Inception 结构为多种尺寸卷积核同时作用于前一层的 feature maps,实现多尺度特征提取。GoogLeNet 随后有多次更新【2】【3】【4】【5】,分类准确率不断提升,甚至超过人类识别极限。TF-Slim 中已有的模型和分类准确率情况如下图所示:
这里写图片描述

一般我们直接使用预训练好的模型在自己数据集上进行 finetune 即可。
今天我们以 Inception-V4【5】 作为研究对象,学习如何利用 TF-Slim 设计复杂模型。
使用 TF-Slim 时,在代码开头写入:

import tensorflow as tf
slim = tf.contrib.slim

这样后面直接使用 slim 就能调用其 API。
Inception-V4 的完整网络结构如下图所示(来自参考文献【5】)。
这里写图片描述

这个图里面涉及到若干 building blocks,我们一个个来研究。

首先看 Inception-A 模块:
这里写图片描述

对应的 TF-Slim 实现代码片段如下(摘自【6】):
这里写图片描述

接着看 Inception-B 模块:
这里写图片描述

对应的 TF-Slim 实现代码片段如下(摘自【6】)
这里写图片描述

继续看 Inception-C 模块:
这里写图片描述

对应的 TF-Slim 实现代码片段如下(摘自【6】):
这里写图片描述

可见 Inception-A/B/C 模块的网络超参数设置与论文中一致,共重复了 4 个 Inception-A 、7个 Inception-B、3 个 Inception-C。
其他模块(Stem、Reduction-A/B)读者可以自行对比下。

通过学习 TF-Slim 可以轻松地构建结构极其复杂的网络,能打消对新网络结构的“恐惧”感。

参考文献
【1】https://github.com/tensorflow/models/tree/master/slim
【2】 C. Szegedy, W. Liu, Y. Jia, P. Sermanet, S. Reed, D. Anguelov, D. Erhan, V. Vanhoucke, and A. Rabinovich. Going deeper with convolutions. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, pages 1–9, 2015.
【3】S. Ioffe and C. Szegedy. Batch normalization: Accelerating deep network training by reducing internal covariate shift. In Proceedings of The 32nd International Conference on Ma- chine Learning, pages 448–456, 2015.
【4】C.Szegedy,V.Vanhoucke,S.Ioffe,J.Shlens,andZ.Wojna. Rethinking the inception architecture for computer vision. arXiv preprint arXiv:1512.00567, 2015.
【5】Inception-v4, Inception-ResNet and the Impact of Residual Connections on Learning
【6】 https://github.com/tensorflow/models/blob/master/slim/nets/inception_v4.py

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值