吴裕雄--天生自然TensorFlow2教程:梯度下降简介
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教程:梯度下降简介的更多相关文章
- 吴裕雄--天生自然TensorFlow2教程:多输出感知机及其梯度
import tensorflow as tf x = tf.random.normal([2, 4]) w = tf.random.normal([4, 3]) b = tf.zeros([3]) ...
- 吴裕雄--天生自然TensorFlow2教程:单输出感知机及其梯度
import tensorflow as tf x = tf.random.normal([1, 3]) w = tf.ones([3, 1]) b = tf.ones([1]) y = tf.con ...
- 吴裕雄--天生自然TensorFlow2教程:损失函数及其梯度
import tensorflow as tf x = tf.random.normal([2, 4]) w = tf.random.normal([4, 3]) b = tf.zeros([3]) ...
- 吴裕雄--天生自然TensorFlow2教程:激活函数及其梯度
import tensorflow as tf a = tf.linspace(-10., 10., 10) a with tf.GradientTape() as tape: tape.watch( ...
- 吴裕雄--天生自然TensorFlow2教程:Tensor数据类型
list: [1,1.2,'hello'] ,存储图片占用内存非常大 np.array,存成一个静态数组,但是numpy在深度学习之前就出现了,所以不适合深度学习 tf.Tensor,为了弥补nump ...
- 吴裕雄--天生自然TensorFlow2教程:手写数字问题实战
import tensorflow as tf from tensorflow import keras from keras import Sequential,datasets, layers, ...
- 吴裕雄--天生自然TensorFlow2教程:函数优化实战
import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D def himme ...
- 吴裕雄--天生自然TensorFlow2教程:反向传播算法
- 吴裕雄--天生自然TensorFlow2教程:链式法则
import tensorflow as tf x = tf.constant(1.) w1 = tf.constant(2.) b1 = tf.constant(1.) w2 = tf.consta ...
随机推荐
- NOIP做题练习(day2)
A - Reign 题面 题解 最大子段和+\(DP\). 预处理两个数组: \(p[i]\)表示 \(i\) 之前的最大子段和. \(l[i]\)表示 \(i\) 之后的最大子段和. 最后直接输出即 ...
- 题解 【洛谷P1035】[NOIP2002普及组]级数求和
[NOIP2002普及组]级数求和 这个题……用循环也是可以的,不过我写了两种循环的题解,供各位dalao参考!O(∩_∩)O谢谢! for循环版本: #include<bits/stdc++. ...
- 【C语言】请输入一个n(n<=10)并输出一个n行n列的杨辉三角
应用二维数组的知识 杨辉三角特点: 1.第一列和对角线的元素全部为1 2.其他元素等于上一行的当前列的值和上一行中当前列前边一列的值之和 #include<stdio.h> #define ...
- RestTemplate-记录
org.springframework.web.client.RestTemplate 1.从使用功能上看,是一种简化请求响应的工具类,从发送请求,到对返回的结果进行json解析.格式不对会有异常.
- python中GraphViz's executables not found的解决方法以及决策树可视化
出现GraphViz's executables not found报错很有可能是环境变量没添加上或添加错地方. 安装pydotplus.graphviz库后,开始用pydotplus.graph_f ...
- Bugku-CTF之web8(txt????)
Day29
- 二次封装 Reponse,视图家族
复习 """ 1.整体修改与局部修改 # 序列化 ser_obj = ModelSerializer(model_obj) # 反序列化,save() => cre ...
- swiper移动端全屏播放动态获取数据
html: <link rel="stylesheet" href="css/swiper.min.css"> <div class=& ...
- centos 6.10 安装mysql 5.7.27
操作系统Centos 6.10 64位 Mysql 版本 5.7.27 , 从官网下载 该教程是Mysql shell安装脚本,脚本运行结束后需要重置密码,以及必要的授权操作等 该教程对外端口设置为5 ...
- sklearn 线性回归
# import numpy as np import pandas as pd from pandas import Series,DataFrame import matplotlib.pyplo ...