out = f(X@W + b)
out = relut(X@W + b)

import tensorflow as tf

x = tf.random.normal([4, 784])
net = tf.keras.layers.Dense(512)
out = net(x)
out.shape
net.kernel.shape, net.bias.shape
net = tf.keras.layers.Dense(10)
try:
net.bias
except Exception as e:
print(e)
net.build(input_shape=(None, 4))
net.kernel.shape, net.bias.shape
net.build(input_shape=(None, 20))
net.kernel.shape, net.bias.shape
net.build(input_shape=(2, 4))
net.kernel
from tensorflow import keras

x = tf.random.normal([2, 3])
model = keras.Sequential([
keras.layers.Dense(2, activation='relu'),
keras.layers.Dense(2, activation='relu'),
keras.layers.Dense(2)
])
model.build(input_shape=[None, 3])
model.summary()
# [w1,b1,w2,b2,w3,b3]
for p in model.trainable_variables:
print(p.name, p.shape)

吴裕雄--天生自然TensorFlow2教程:全连接层的更多相关文章

  1. 吴裕雄--天生自然TensorFlow2教程:合并与分割

    import tensorflow as tf # 6个班级的学生分数情况 a = tf.ones([4, 35, 8]) b = tf.ones([2, 35, 8]) c = tf.concat( ...

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

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

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

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

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

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

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

  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 x = tf.random.normal([1, 3]) w = tf.ones([3, 1]) b = tf.ones([1]) y = tf.con ...

  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. 【资源分享】RPG Maker 2000/2003 简体中文版

    *----------------------------------------------[下载区]----------------------------------------------* ...

  2. markdown整理

    html标签# h1 ## h2 ### h3 #### h4 ##### h5 ###### h6 一级标题:内容=== 二级标题:内容--- 强调文字:>内容 链接:[文字](链接地址) 图 ...

  3. UITextField的内存泄漏问题

    背景: 项目中使用了Facebook的FBRetainCycleDetector框架检测内存泄漏问题. 登录VC的view中放置了一个UITextField对象. 产品的要求是当进入登录界面的时候,让 ...

  4. win10下Ubuntu18.04安装的简单教程

    win10下Ubuntu18.04安装的简单教程      操作系统:windows    软件:Vmware15.      一.下载 Ubuntu18.04镜像   Ubuntu18.04镜像下载 ...

  5. PTA的Python练习题(十八)

    第4章-20 求矩阵各行元素之和 遇到一个麻烦的事情: 上面a,b输入,如果一起输入转int会报错,因为int只能一对一 但是明明我分开来int了,下面第十行还是报错说我的b是string字符,难不成 ...

  6. 树莓派3B 安装gcc和g++

    转:https://blog.csdn.net/zhuming3834/article/details/81946707 安装 如果不是root 用户,请自行加上sudo apt-get instal ...

  7. 吴裕雄 python 人工智能——基于神经网络算法在智能医疗诊断中的应用探索代码简要展示

    #K-NN分类 import os import sys import time import operator import cx_Oracle import numpy as np import ...

  8. Linux内核5.6亮点

    导读 当我们还在体验 Linux 5.5 稳定发行版带来更好的硬件支持时,Linux 5.6 已经来了.我将在本文中重点介绍 Linux 5.6 发布版中值得期待的关键更改和功能. 说实话,Linux ...

  9. 洛谷 P1063 能量项链(区间DP)

    嗯... 题目链接:https://www.luogu.com.cn/problem/P1063 这道题首先要读懂题目,然后往上套区间dp,要转换成链式. AC代码: #include<cstd ...

  10. 刷题15. 3Sum

    一.题目说明 题目非常简洁15. 3Sum,读懂题目后,理解不难. 但 实话说,我们提交代码后,Time Limit Exceeded,最主要的是给了非常长的测试用例,我本地运行后87秒,确实时间非常 ...