import tensorflow as tf

x = tf.random.normal([1, 3])
w = tf.ones([3, 1])
b = tf.ones([1])
y = tf.constant([1]) with tf.GradientTape() as tape:
tape.watch([w, b])
prob = tf.sigmoid(x @ w + b)
loss = tf.reduce_mean(tf.losses.MSE(y, prob)) grads = tape.gradient(loss, [w, b])
grads[0]
grads[1]

吴裕雄--天生自然TensorFlow2教程:单输出感知机及其梯度的更多相关文章

  1. 吴裕雄--天生自然TensorFlow2教程:输出方式

    sigmoid out' = sigmoid(out) # 把输出值压缩在0-1 import tensorflow as tf a = tf.linspace(-6., 6, 10) a tf.si ...

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

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

  3. 吴裕雄--天生自然TensorFlow2教程:前向传播(张量)- 实战

    手写数字识别流程 MNIST手写数字集7000*10张图片 60k张图片训练,10k张图片测试 每张图片是28*28,如果是彩色图片是28*28*3-255表示图片的灰度值,0表示纯白,255表示纯黑 ...

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. 题解【Codeforces438D】The Child and Sequence

    题目描述 At the children's day, the child came to Picks's house, and messed his house up. Picks was angr ...

  2. 【Python】【爬虫】爬取酷狗音乐网络红歌榜

    原理:我的上篇博客 import requests import time from bs4 import BeautifulSoup def get_html(url): ''' 获得 HTML ' ...

  3. grep Or And 操作

    grep or 操作符 使用 \| 如果不使用grep命令的任何选项,可以通过使用 '|' 来分割多个pattern,以此实现OR的操作. grep 'pattern1\|pattern2' file ...

  4. Spring Cloud和Spring Boot版本问题导致Nacos 注册失败!

    之前学习consul注册中心的时候就遇到版本问题,这次学习nacos的时候又遇到版本问题,可惜没长记性,排查了一天最后才发现是boot和cloud的版本有问题. 记录一下,防止以后再出现这种浪费时间的 ...

  5. Tex 论文写作 jpg eps图像

    pdflatex只能支持pdf.jpg.jpeg.png共4中格式的图片.所以在插入eps图像是会没法显示,使用latex编译不存在这个问题,但是,我还不会用,编译完后从哪里看不知道. 这个里面说的详 ...

  6. js实现页面下拉后展示导航,以及点击导航自动滑动到相关页面

    //监控,下拉750px后展示导航 $(window).scroll(function(){ var $this = $(this); var targetTop = $(this).scrollTo ...

  7. Java-POJ1000-A+B Problem

  8. AcWing 851. spfa求最短路 边权可能为负数。 链表 队列

    #include <cstring> #include <iostream> #include <algorithm> #include <queue> ...

  9. python 鸢尾花数据集报表展示

    import seaborn as snsimport pandas as pdimport matplotlib.pyplot as pltsns.set_style('white',{'font. ...

  10. 吴裕雄 python 机器学习——支持向量机SVM非线性分类SVC模型

    import numpy as np import matplotlib.pyplot as plt from sklearn import datasets, linear_model,svm fr ...