tensorflow检查op是否可导(反向传播)
来源:互联网 发布:人工智能的主要技术 编辑:程序博客网 时间:2024/05/18 09:09
1.安装最新版tf--tensorflow1.5,gpu版本需要CUDA8和cudnn6,命令如下
GPU版:sudo pip3 install tf-nightly-gpu
CPU版:sudo pip3 install tf-nightly
对应pip网站:https://pypi.python.org/pypi/tf-nightly-gpu
2.编写代码进行测试,主要包括可导函数square和不可导函数floor
代码参考网站https://research.googleblog.com/2017/10/eager-execution-imperative-define-by.html
代码示例:
import numpy as np
import tensorflow as tf
import tensorflow.contrib.eager as tfe
tfe.enable_eager_execution()
def floor(x):
return tf.floor(x)
def square(x):
return tf.multiply(x, x)
grad_f = tfe.gradients_function(floor)
print(floor(3.))
print('gradient of floor:',grad_f(3.))
grad_s = tfe.gradients_function(square)
print(square(3.))
print('gradient of square:',grad_s([3.]))
代码输出:
tf.Tensor(3.0, shape=(), dtype=float32)
gradient of floor: [None]
tf.Tensor(9.0, shape=(), dtype=float32)
gradient of square: [<tf.Tensor: id=21, shape=(1,), dtype=float32, numpy=array([ 6.], dtype=float32)>]
3.小结
可以看出,floor函数对应的梯度为None,而square函数对应的梯度为 derivative(x^2)=2*x|x=3=6
阅读全文
0 0
- tensorflow检查op是否可导(反向传播)
- 对正向传播、反向传播和精度检查的理解
- 反向传播算法(BP)
- (Caffe,LeNet)反向传播
- Tensorflow使用流程小例子 ——反向传播
- 获取URL图片(可检查是否存在)
- 反向传播
- 反向传播
- 反向传播
- 反向传播
- tensorflow自定义op:work_shard
- tensorflow自定义op:梯度
- Tensorflow add op
- CNN卷积神经网络--反向传播(2,前向传播)
- 前向传播和反向传播(举例说明)
- 检查字符串是否可运算的数字
- android检查sd卡是否可写
- (Caffe,LeNet)反向传播(六)
- 51nod 1246 罐子和硬币(贪心)
- js和webview的交互
- 作业2:4-16进制译码器Verilog 语句实现
- 文件IO方式操作GPIO
- 两个字符串是否存在相同部分的比较
- tensorflow检查op是否可导(反向传播)
- 庆科信息AZ3166亮相北京2017微软技术暨生态大会
- opengl入门
- 【UVA1331】关于最优三角剖分
- 单据开发时,怎样让字段是添加时间的值是当前的时间?
- 基于Spring、SpringMVC、MyBatis、Druid、Shrio构建web系统
- python 最大公约数与最小公倍数
- Android 手机号,密码正则验证
- apache对目录和地址的安全权限控制