tensorflow,torch tips
- apply weightDecay,L2 REGULARIZATION_LOSSES
weights = tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES)
for w in weights:
print(w)
l2r = tf.contrib.layers.l2_regularizer(0.001)
tf.contrib.layers.apply_regularization(l2r,weights)
tf.get_collection(tf.GraphKeys.REGULARIZATION_LOSSES) ##cross_entropy loss
tf.add_to_collection('losses', cross_entropy_mean)
loss = tf.add_n(tf.get_collection('losses'), name='cross_entropy_loss')
# config optimizer
target_loss = target_loss + tf.add_n(tf.get_collection(tf.GraphKeys.REGULARIZATION_LOSSES),name='l2_loss')
train_step = tf.train.AdamOptimizer(
learning_rate).minimize(target_loss,global_step)
- .learningRateDecay
global_step = tf.Variable(0, trainable=False,name = 'global_step')
learning_rate = tf.train.exponential_decay(opts.learning_rate, global_step, 10000, 0.96, staircase=True)
train_step = tf.train.AdamOptimizer(learning_rate).minimize(target_loss,global_step)
- tensorflow 与torch 中 learningRateDecay的差异
torch:
-- (3) learning rate decay (annealing)
local clr = lr / (1 + state.t*lrd) state.t = state.t + 1 https://github.com/torch/optim/blob/master/adam.lua tensorflow:
decayed_learning_rate = learning_rate *
decay_rate ^ (global_step / decay_steps) https://www.tensorflow.org/versions/r0.11/api_docs/python/train/decaying_the_learning_rate
torch中是每个batch执行一次,如果lrd = 0.001
tensorflow 对应的应该是:decay_steps设为1,decay_steps = 1-lrd=0.999,这样就与torch的方法近似了?
不对,tesorflow中有等价的tf.train.inverse_time_decay
- tensorflow 中的softmax与torch 中LogSoftmax
tf.nn.softmax
exp(logits) / reduce_sum(exp(logits), dim)
tf.log(tf.nn.softmax(logits))并不与torch的LogSoftmax,torch中的LogSoftmax实现方式不一样:
https://github.com/torch/nn/blob/master/lib/THNN/generic/LogSoftMax.c
http://blog.csdn.net/lanchunhui/article/details/51248184
- saver
http://www.jianshu.com/p/8487db911d9a
- tensorflow 与torch 中 DropOut的差异
torch:
Furthermore, the outputs are scaled by a factor of 1/(1-p) during training. tensorflow:
With probability keep_prob, outputs the input element scaled up by 1 / keep_prob, otherwise outputs 0. The scaling is so that the expected sum is unchanged. 所以torch中的dropout_rate = p,相当于tesnsorflow中的keep_prob = 1-p
参数顺序
conv:torch outputs*inputs*kh*kw , tf kh*kw*inputs*outputs
deconv:torch inputs*outputs*kh*kw , tf kh*kw*outputs*inputs
移动端&MPS: outputs*kh*kw*inputs ,注意deconv kh*kw rotate 180度
tensorflow,torch tips的更多相关文章
- 『TensorFlow』专题汇总
TensorFlow:官方文档 TensorFlow:项目地址 本篇列出文章对于全零新手不太合适,可以尝试TensorFlow入门系列博客,搭配其他资料进行学习. Keras使用tf.Session训 ...
- 【深度学习Deep Learning】资料大全
最近在学深度学习相关的东西,在网上搜集到了一些不错的资料,现在汇总一下: Free Online Books by Yoshua Bengio, Ian Goodfellow and Aaron C ...
- 机器学习(Machine Learning)&深度学习(Deep Learning)资料(Chapter 2)
##机器学习(Machine Learning)&深度学习(Deep Learning)资料(Chapter 2)---#####注:机器学习资料[篇目一](https://github.co ...
- (转)Awesome Human Pose Estimation
Awesome Human Pose Estimation 2018-10-08 11:02:35 Copied from: https://github.com/cbsudux/awesome-hu ...
- 8.8 Deep Learning Software
深度学习软件 -CPU vs GPU -Deep Learning Framework - Caffe / Caffe2 - Theano / TensorFlow - Torch / PyTorch ...
- opencv::DNN介绍
DNN模块介绍: Tiny-dnn模块 支持深度学习框架 - Caffe - TensorFlow - Torch/PyTorch DNN运用 图像分类 对象检测 实时对象检测 图像分割 预测 视频对 ...
- YOLO---近段时间的练习目标
YOLO---近段时间的练习目标 yolo(darknet)官方主页:https://pjreddie.com/darknet/yolo/ 和在学校时用的不太一样了,有更新了- 还有一个常用版本: ...
- 【opencv系列01】OpenCV4.X介绍与安装
一.介绍 OpenCV(开源计算机视觉库:http://opencv.org)是英特尔开源的一个跨平台计算机视觉的BSD许可库,包含数百种计算机视觉算法.OpenCV由Gary Bradsky于199 ...
- CS231n 斯坦福李飞飞视觉识别课程
本文是个人在学习<CS231n 斯坦福李飞飞视觉识别课程>的学习笔记. 第一讲:课程简介 课时1 计算机视觉概述 课时2 计算机视觉历史背景 课时3 课程后勤 选读书籍<DeepLe ...
随机推荐
- 基于Docker Compose搭建mysql主从复制(1主2从)
系统环境 * 3 Ubuntu 16.04 mysql 8.0.12 docker 18.06.1-ce docker-compose 1.23.0-rc3 *3 ==> PS ###我用的是 ...
- web应用无法访问的原因之一以及如何设置数据库编码
这篇随笔,本是应该是在前天晚上发的,但是因为事情太多,硬生生拖到了现在,当时,在我将web应用部署到服务器上时,在调用接口时,客户端没有任何反应,应该是又出异常了,查看了控制台的异常输出,提示requ ...
- 86-Money Flow Index 资金流量指数指标.(2015.7.3)
Money Flow Index 资金流量指数指标 计算: 1.典型价格(TP)=当日最高价.最低价与收盘价的算术平均值 2.货币流量(MF)=典型价格(TP)×N日内成交金额 3.如果当日MF> ...
- build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing
maven test项目时遇到一下错误 Some problems were encountered while building the effective model for cn.temptat ...
- 集训第四周(高效算法设计)K题 (滑窗问题)
UVA 11572 唯一的雪花 题意:给你从1到n的数组,要求求得其中的最长连续不重复子序列,经典的滑窗问题,方法是维护一个窗口,设置左框和右框,然后不断的进行维护和更新 方法一: #include& ...
- DFS求连通块(漫水填充法)
G - DFS(floodfill),推荐 Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I6 ...
- python用模块zlib压缩与解压字符串和文件的方法
摘自:http://www.jb51.net/article/100218.htm Python标准模块中,有多个模块用于数据的压缩与解压缩,如zipfile,gzip, bz2等等. python中 ...
- 开车旅行(codevs 1199)
题目描述 Description 小A 和小B决定利用假期外出旅行,他们将想去的城市从1到N 编号,且编号较小的城市在编号较大的城市的西边,已知各个城市的海拔高度互不相同,记城市 i的海拔高度为Hi, ...
- VIM使用技巧14
经常使用vim的童鞋可能会注意到,实际操作过程中,处于插入模式中是非常少的,更多的是查看和浏览,偶尔修改即可.因此,快速从插入模式退出进入普通模式,就显得非常重要.主要有以下四种方式: 一.在插入模式 ...
- Linux下汇编语言学习笔记24 ---
这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...