import tensorflow as tf

w = tf.constant(1.)
x = tf.constant(2.)
y = x * w
with tf.GradientTape() as tape:
tape.watch([w])
y2 = x * w grad1 = tape.gradient(y, [w])
grad1
with tf.GradientTape() as tape:
tape.watch([w])
y2 = x * w grad2 = tape.gradient(y2, [w])
grad2
try:
grad2 = tape.gradient(y2, [w])
except Exception as e:
print(e) with tf.GradientTape(persistent=True) as tape:
tape.watch([w])
y2 = x * w
grad2 = tape.gradient(y2, [w])
grad2
with tf.GradientTape() as t1:
with tf.GradientTape() as t2:
y = x * w + b
dy_dw, dy_db = t2.gradient(y, [w, b]) d2y_dw2 = t1.gradient(dy_dw, w)

吴裕雄--天生自然TensorFlow2教程:梯度下降简介的更多相关文章

  1. 吴裕雄--天生自然TensorFlow2教程:多输出感知机及其梯度

    import tensorflow as tf x = tf.random.normal([2, 4]) w = tf.random.normal([4, 3]) b = tf.zeros([3]) ...

  2. 吴裕雄--天生自然TensorFlow2教程:单输出感知机及其梯度

    import tensorflow as tf x = tf.random.normal([1, 3]) w = tf.ones([3, 1]) b = tf.ones([1]) y = tf.con ...

  3. 吴裕雄--天生自然TensorFlow2教程:损失函数及其梯度

    import tensorflow as tf x = tf.random.normal([2, 4]) w = tf.random.normal([4, 3]) b = tf.zeros([3]) ...

  4. 吴裕雄--天生自然TensorFlow2教程:激活函数及其梯度

    import tensorflow as tf a = tf.linspace(-10., 10., 10) a with tf.GradientTape() as tape: tape.watch( ...

  5. 吴裕雄--天生自然TensorFlow2教程:Tensor数据类型

    list: [1,1.2,'hello'] ,存储图片占用内存非常大 np.array,存成一个静态数组,但是numpy在深度学习之前就出现了,所以不适合深度学习 tf.Tensor,为了弥补nump ...

  6. 吴裕雄--天生自然TensorFlow2教程:手写数字问题实战

    import tensorflow as tf from tensorflow import keras from keras import Sequential,datasets, layers, ...

  7. 吴裕雄--天生自然TensorFlow2教程:函数优化实战

    import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D def himme ...

  8. 吴裕雄--天生自然TensorFlow2教程:反向传播算法

  9. 吴裕雄--天生自然TensorFlow2教程:链式法则

    import tensorflow as tf x = tf.constant(1.) w1 = tf.constant(2.) b1 = tf.constant(1.) w2 = tf.consta ...

随机推荐

  1. layout components pages及基本操作

    components组件 layouts模板 pages nuxt.config.js nuxt的配置文件

  2. nginx的学习

    什么是反向代理? 参考这个帖子的‘刘志军’的回答 https://www.zhihu.com/question/24723688 nginx的配置 http://baijiahao.baidu.com ...

  3. centos 7 安装 nginx maxmind GEO IP IP库相关部署

    centos 7 上为nginx 增加Geo IP的功能 yum install gcc gcc-c++ make automake autoconf libtool wget unzip -y if ...

  4. win10 解决.net framework 3.5 安装报错 0x80240438

    打开注册表:cmd+r 输入regedit,确定:找到路径HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU ...

  5. Qt那点事儿(一)

    原文http://www.cnblogs.com/andreitang/archive/2011/08/03/2125815.html 第一回 Signal和Slot是同步的还是异步的? 我们知道Qt ...

  6. 更改mysql数据库默认的字符集(编码方式)

    mysql数据库的默认编码方式是latin1, 在mysql中存储和显示中文时会产生乱码,必须要更改默认的编码方式为utf8 或 gbk.(以下以gbk为例.) 更改服务器的编码方式,在终端输入以下命 ...

  7. mybatis--第一个mybatis程序

    首先,创建一个数据库my,并在数据库中插入一张表user,然后在user表中插入一行数据,代码如下: create database my; use my; create table user( id ...

  8. cnblogs在手机端显示的一些坑

    目前在网上搜了个博皮,很高大上,感兴趣的朋友可以看一下,但是在手机端显示这些html5代码有很多缺陷: 1. h1.h2只能显示一行,如果字数太多,则会被隐藏 就像你现在看到的,h1原本内容为: 目前 ...

  9. nginx autoindex 配置目录浏览功能

    Nginx打开目录浏览功能 yum install httpd-tools -y cd /usr/local/openrestry/nginx/conf/ htpasswd -c passwd adm ...

  10. yii2 gii开启

    gii模块可以通过配置yii\base\Application::modules属性开启它.在config/web.php文件中会有以下配置代码: $config = [ ... ]; if (YII ...