AI challenger 场景分类 tensorflow inception-resnet-v2 LB: 0.94361

模型采用tf-slim在imagenet上训练的inception-resnet-v2,可以选择训练哪些层,如只重新训练最后一层,或重新训练后面的多层等等。没有采取特殊的数据增强,用的tf-slim默认的inception输入方式。采用如下参数配置线上得分0.94361。
用的tfrecord图片都是先resize成299*299再转换的,具体方法可参考之前的博文。
learning_rate=0.0001
batch_size=32
num_epochs=80
具体情况:
training accuracy: 0.836019
FInal Testing accuracy: 0.945787(val)
FInal Testing accuracy: 0.94361 (testA)
看起来还是有很大改进(调参)空间的,包括数据增强/分辨率和epoch数等等,但是:

这个代码目前有个问题: 没有实现训练的同时监测验证准确率。这是tensorflow使用tfrecord时的一个坑,需要自己写一些很丑的解决方案,待解决(非常重要,因为已经在一些参数配置上观测到过拟合)。新版本的tf会逐步解决这个问题,详见开头注释的两个issues。采用官方代码提供的图片读取方案则可以简单解决这个问题,但是读取效率可能慢一倍,而且无法在一些云计算平台使用。

# -*- coding: utf-8 -*-
"""
Created on Wed Sep 20 16:05:02 2017

@author: wayne

FEELINGS
目前原生tf和tfrecord的坑还是挺多的,需要自己写的“通用代码”较多,尤其是input pipeline和训练/验证的【流程控制和监控准确率】等
已经在最新的1.3版本中引入了datasets,未来的1.4版本特性参见
https://github.com/tensorflow/tensorflow/issues/7902
和
https://github.com/tensorflow/tensorflow/issues/7951
目前来看,其实还是PyTorch好用,代码更直观易懂

使用原生tf的各种模块结合slim模型。可以考虑学习使用slim官方的样板代码,不过抽象程度较高。

CHANGES
- 可以restore我们自己上次的存档模型,而不是每次都从官方模型开始训练: tf.flags.DEFINE_bool('use_official', True)
- 

REFERENCES

https://web.stanford.edu/class/cs20si/syllabus.html

输入数据
https://stackoverflow.com/questions/44054656/creating-tfrecords-from-a-list-of-strings-and-feeding-a-graph-in-tensorflow-afte
https://indico.io/blog/tensorflow-data-inputs-part1-placeholders-protobufs-queues/
https://indico.io/blog/tensorflow-data-input-part2-extensions/

整个架构
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/how_tos/reading_data/fully_connected_reader.py
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/udacity/2_fullyconnected.ipynb

模型的存储和调用
http://blog.csdn.net/u014595019/article/details/53912710
http://blog.csdn.net/u012436149/article/details/52883747 (restore变量的子集)
https://github.com/SymphonyPy/Valified_Code_Classify/tree/master/Classified
http://blog.csdn.net/lwplwf/article/details/76177296 (定义了一个loop,去监听,一旦有新的checkpoint生成,就去执行一次验证。)

迁移学习(使用tf原生模块结合slim cnn模型的教程真少!)
https://github.com/AIChallenger/AI_Challenger/tree/master/Baselines/caption_baseline (用的slim cnn)
https://github.com/kwotsin/transfer_learning_tutorial (较为完整的程序,但是使用的都是slim提供的模块,还使用了tf.train.Supervisor和tensorboard)
http://blog.csdn.net/ArtistA/article/details/52860050 (用tf直接实现的cnn): https://github.com/joelthchao/tensorflow-finetune-flickr-style
http://blog.csdn.net/nnnnnnnnnnnny/article/details/70244232 (tensorflow_inception_graph.pb。因为一个训练数据会被使用多次,所以可以将原始图像通过Inception-v3模型计算得到的特征向量保存在文件中,免去重复的计算。)
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/image_retraining/retrain.py 

https://github.com/tensorflow/models/issues/391         [slim] weird result with parameter is_training
https://github.com/YanWang2014/models/tree/master/slim  (slim的各种模型)
http://pytorch.org/docs/master/torchvision/models.html
http://data.mxnet.io/models/

数据增强
https://github.com/wzhang1/iNaturalist   MXNet finetune baseline (res152) for challenger.ai/competition/scene
https://github.com/AIChallenger/AI_Challenger/tree/master/Baselines/caption_baseline/im2txt/im2txt/ops

调参
https://zhuanlan.zhihu.com/p/22252270    深度学习最全优化方法总结比较(SGD,Adagrad,Adadelta,Adam,Adamax,Nadam) 
http://www.360doc.com/content/16/1010/08/36492363_597225745.shtml

https://www.zhihu.com/question/41631631  你有哪些deep learning(rnn、cnn)调参的经验?
https://www.zhihu.com/question/25097993  深度学习调参有哪些技巧?
https://www.zhihu.com/question/24529483  在神经网络中weight decay起到的做用是什么?momentum呢?normalization呢?
https://zhuanlan.zhihu.com/p/27555858?utm_medium=social&utm_source=wechat_session  [科普]如何使用高大上的方法调参数

tfrecord验证集问题:在是否额外建立graph方面有很多幺蛾子方法
https://github.com/tensorflow/tensorflow/issues/7902    每次验证要恰好读完整个验证集,且要读多次,在用tfrecord时怎么(优雅地)实现?
https://github.com/tensorflow/tensorflow/issues/7951    新版本会在input pipeline上做改进
https://stackoverflow.com/questions/39187764/tensorflow-efficient-feeding-of-eval-train-data-using-queue-runners
https://stackoverflow.com/questions/44270198/when-using-tfrecord-how-can-i-run-intermediate-validation-check-a-better-way

https://stackoverflow.com/questions/40146428/show-training-and-validation-accuracy-in-tensorflow-using-same-graph

可视化adamoptimizer的lr
https://stackoverflow.com/questions/36990476/getting-the-current-learning-rate-from-a-tf-train-adamoptimizer/44688307#44688307

"""

from __future__ import division, print_function, absolute_import

import tensorflow as tf
import time
slim = tf.contrib.slim
from inception_resnet_v2 import *
import inception_preprocessing

tf.reset_default_graph()

import os
FLAGS = tf.flags.FLAGS

tf.flags.DEFINE_bool('train_flag', False, 'train_flag')
tf.flags.DEFINE_string('trainable_scopes', 'InceptionResnetV2/Logits,InceptionResnetV2/AuxLogits', '训练的层') #None 为全部训练。测试时不用管
tf.flags.DEFINE_bool('use_official', True, '使用官方模型开始训练还是使用自己存的模型,使用自己模型之前先给模型备份,否则可能会被覆盖掉')

tf.flags.DEFINE_float('learning_rate', 0.001, 'learning_rat
  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 7
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值