|
|
|
|
|
吴裕雄--天生自然TensorFlow2教程:手写数字问题实战
摘要:import tensorflow as tf from tensorflow import keras from keras import Sequential,datasets, layers, optimizers, metrics def preprocess(x, y): """数据处理函
阅读全文
吴裕雄--天生自然TensorFlow2教程:函数优化实战
摘要:import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D def himmeblau(x): return (x[0]**2 + x[1] - 11)**2 + (x[0] +
阅读全文
吴裕雄--天生自然TensorFlow2教程:链式法则
摘要: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(p
阅读全文
吴裕雄--天生自然TensorFlow2教程:多输出感知机及其梯度
摘要:import tensorflow as tf x = tf.random.normal([2, 4]) w = tf.random.normal([4, 3]) b = tf.zeros([3]) y = tf.constant([2, 0]) with tf.GradientTape() as
阅读全文
吴裕雄--天生自然TensorFlow2教程:单输出感知机及其梯度
摘要: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.wa
阅读全文
吴裕雄--天生自然TensorFlow2教程:损失函数及其梯度
摘要:import tensorflow as tf x = tf.random.normal([2, 4]) w = tf.random.normal([4, 3]) b = tf.zeros([3]) y = tf.constant([2, 0]) with tf.GradientTape() as
阅读全文
吴裕雄--天生自然TensorFlow2教程:激活函数及其梯度
摘要:import tensorflow as tf a = tf.linspace(-10., 10., 10) a with tf.GradientTape() as tape: tape.watch(a) y = tf.sigmoid(a) grads = tape.gradient(y, [a])
阅读全文
吴裕雄--天生自然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.grad
阅读全文
吴裕雄--天生自然TensorFlow2教程:误差计算
摘要:import tensorflow as tf y = tf.constant([1, 2, 3, 0, 2]) y = tf.one_hot(y, depth=4) # max_label=3种 y = tf.cast(y, dtype=tf.float32) out = tf.random.no
阅读全文
吴裕雄--天生自然TensorFlow2教程:输出方式
摘要:sigmoid out' = sigmoid(out) # 把输出值压缩在0-1 import tensorflow as tf a = tf.linspace(-6., 6, 10) a tf.sigmoid(a) x = tf.random.normal([1, 28, 28]) * 5 tf.
阅读全文
吴裕雄--天生自然TensorFlow2教程:全连接层
摘要: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 n
阅读全文
吴裕雄--天生自然TensorFlow2教程:测试(张量)- 实战
摘要:import tensorflow as tf from tensorflow import keras from tensorflow.keras import datasets import os # do not print irrelevant information # os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' # x: [60k,28,28],
阅读全文
吴裕雄--天生自然TensorFlow2教程:数据加载
摘要:import tensorflow as tf from tensorflow import keras # train: 60k | test: 10k (x, y), (x_test, y_test) = keras.datasets.mnist.load_data() x.shape y.shape # 0纯黑、255纯白 x.min(), x.max(), x.mean() x_test.
阅读全文
吴裕雄--天生自然TensorFlow2教程:高阶操作
摘要:import tensorflow as tf a = tf.random.normal([3, 3]) a mask = a > 0 mask # 为True元素,即>0的元素的索引 indices = tf.where(mask) indices # 取回>0的值 tf.gather_nd(a, indices) A = tf.ones([3, 3]) B = tf.zeros([3, 3])
阅读全文
吴裕雄--天生自然TensorFlow2教程:张量限幅
摘要:import tensorflow as tf a = tf.range(10) a # a中小于2的元素值为2 tf.maximum(a, 2) # a中大于8的元素值为8 tf.minimum(a, 8) # a中的元素值限制在[2,8]区间内 tf.clip_by_value(a, 2, 8) a = a - 5 a tf.nn.relu(a) tf.maximum(a, 0) 缩放时不改变
阅读全文
吴裕雄--天生自然TensorFlow2教程:填充与复制
摘要:import tensorflow as tf a = tf.reshape(tf.range(9), [3, 3]) a tf.pad(a, [[0, 0], [0, 0]]) tf.pad(a, [[ 1, 0, ], [0, 0]]) tf.pad(a, [[1, 1], [0, 0]]) tf.pad(a, [[1, 1], [1, 0]]) tf....
阅读全文
吴裕雄--天生自然TensorFlow2教程:张量排序
摘要:import tensorflow as tf a = tf.random.shuffle(tf.range(5)) a tf.sort(a, direction='DESCENDING') # 返回索引 tf.argsort(a, direction='DESCENDING') idx = tf.argsort(a, direction='DESCENDING') tf.gath...
阅读全文
吴裕雄--天生自然TensorFlow2教程:数据统计
摘要:import tensorflow as tf a = tf.ones([2, 2]) a tf.norm(a) tf.sqrt(tf.reduce_sum(tf.square(a))) a = tf.ones([4, 28, 28, 3]) a.shape tf.norm(a) tf.sqrt(tf.reduce_sum(tf.square(a))) b = tf.ones([2, 2]) tf
阅读全文
|
|