import tensorflow as tf

x = tf.constant(1.)
w1 = tf.constant(2.)
b1 = tf.constant(1.)
w2 = tf.constant(2.)
b2 = tf.constant(1.) with tf.GradientTape(persistent=True) as tape:
tape.watch([w1, b1, w2, b2])
y1 = x * w1 + b1
y2 = y1 * w2 + b2 dy2_dy1 = tape.gradient(y2, [y1])[0]
dy1_dw1 = tape.gradient(y1, [w1])[0]
dy2_dw1 = tape.gradient(y2, [w1])[0]
dy2_dy1 * dy1_dw1
dy2_dw1

吴裕雄--天生自然TensorFlow2教程:链式法则的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

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

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

  8. 吴裕雄--天生自然TensorFlow2教程:梯度下降简介

    import tensorflow as tf w = tf.constant(1.) x = tf.constant(2.) y = x * w with tf.GradientTape() as ...

  9. 吴裕雄--天生自然TensorFlow2教程:误差计算

    import tensorflow as tf y = tf.constant([1, 2, 3, 0, 2]) y = tf.one_hot(y, depth=4) # max_label=3种 y ...

随机推荐

  1. 用户 'sa' 登录失败。该用户与可信 SQL Server 连接无关联'。错误代码:18452 解决办法

    原文:https://blog.csdn.net/wuxianwei/article/details/6330270 SQLSERVER 2005采用'SQLSERVER身份验证'去登录, 出错的原因 ...

  2. 题解【洛谷P5483】[JLOI2011]小A的烦恼

    我们可以灵活运用\(C++\)的语法来解决此题. 解释一下代码中会出现的语法: \(string::iterator\ it\)表示定义了一个\(string\)类型的迭代器\(it\),\(^*it ...

  3. 2.17NOIP模拟赛(by hzwer) T1 小奇挖矿

    [题目背景] 小奇要开采一些矿物,它驾驶着一台带有钻头(初始能力值 w)的飞船,按既定 路线依次飞过喵星系的 n 个星球. [问题描述] 星球分为 2 类:资源型和维修型. 1. 资源型:含矿物质量 ...

  4. linux系统下如何打开端口

    1)vi /etc/sysconfig/iptables 2)-A INPUT -m state --state NEW -m tcp -p tcp --dport xxxxxxxxxx -j ACC ...

  5. 【转载】C/C++预处理器

    转自:http://www.cnblogs.com/lidabo/archive/2012/08/27/2658909.html C/C++编译系统编译程序的过程为预处理.编译.链接.预处理器是在程序 ...

  6. java把带小数点的字符串转换成int类型

    String number ="1.0000"; int num =Double.valueOf(number).intValue();//转换为Int类型

  7. 错误记录(一):VSCode

    VS Code莫名其妙突然变卡. 后来重新安装,下载以前版本,设置防止循环,都不太管用. 最后想添加VS Code目录到windows扫描白名单,但因为系统之前是英文不太好看懂,所以又调回了中文. 这 ...

  8. 3.CRUD(增删改查)

    Select 选择,查询语句 id:就是对应的namespace中的方法名: resultType:Sql语句执行的返回值: parameterType:参数类型 我们想使用查询语句首先要在UserM ...

  9. C#中字符串常用方法

    string str = "123@163.com"; int index = str.IndexOf('@'); // 返回3  从左向右第一个@ int index = str ...

  10. JVM(三、双亲委派机制)

    javadoc的解释: ClassLoader的每一个实例都会有一个与之关联的父ClassLoader,当被要求去寻找一个类或者资源的时候,ClassLoader的实例就会对于类或者是资源的寻找委托给 ...