![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Tensorflow基础入门
文章平均质量分 51
持续更新中
小蜗笔记
热爱建模和计算机
展开
-
(25)梯度下降法求解曲面极小值
import tensorflow as tfimport numpy as npimport matplotlib.pyplot as pltdef himmelblau(x): return (x[0]**2 + x[1]-11)**2 + (x[0]+x[1]**2-7)**2 x = np.arange(-6,6,0.1)y= np.arange(-6,6,0.1)print(x.shape,y.shape)X,Y = tf.meshgrid(x,y)#组合Z =原创 2021-01-16 12:29:26 · 576 阅读 · 1 评论 -
(23)tensorflow进阶之激活函数的导数
激活函数导数Sigmoid 函数导数导数为:Sigmoid(1−Sigmoid) Sigmoid(1 − Sigmoid) Sigmoid(1−Sigmoid)ReLU 函数导数LeakyReLU函数导数Tanh 函数梯度导数为:1−tanh2(x) 1 − tanh^2(x) 1−tanh2(x)原创 2020-09-30 14:54:07 · 161 阅读 · 0 评论 -
(24)tensorflow进阶--损失函数梯度
损失函数梯度均方误差函数梯度均方误差表达式:梯度导数:交叉熵函数梯度Softmax 梯度回顾 Softmax 函数的表达式:Softmax 梯度为:交叉熵梯度考虑交叉熵损失函数的表达式:将log分解:最终简化求出:...原创 2020-09-30 15:09:18 · 186 阅读 · 0 评论 -
(22)tensorflow自动求导
自动求导打开自动求导功能tf.GradientTape()import tensorflow as tfx = tf.constant([2.3]) #初始化数据z = tf.constant([1.])with tf.GradientTape() as tape: tape.watch([x,z]) #加入梯度追踪列表 x = z**2 #计算过程 y = x**2+x*3 grads = tape.gradient(原创 2020-09-07 08:47:31 · 121 阅读 · 0 评论 -
(21)tensorflow误差计算
误差计算均方差误差MSEMSE(y,o)=1n∑i=1n(yi−oi)2MSE(y,o)=\cfrac{1}{n}\displaystyle\sum_{i=1}^n(y_i-o_i)^2\\ MSE(y,o)=n1i=1∑n(yi−oi)2import tensorflow as tfo = tf.random.normal([2,10])y = tf.constant([1,3])print(y)y = tf.one_hot(y,depth=10)print(y)loss = t原创 2020-09-05 11:05:41 · 197 阅读 · 0 评论 -
(20)tensorflow输出层设计
输出层设计原创 2020-09-05 10:12:33 · 190 阅读 · 0 评论 -
(19)tensorflow激活函数
激活函数原创 2020-09-04 16:30:59 · 258 阅读 · 0 评论 -
(18)tensorflow误差loss简介
误差loss原创 2020-09-04 15:29:04 · 236 阅读 · 0 评论 -
(17)tensorflow多层神经网络实现
多层神经网络实现多层神经网络张量方式实现初始化各层调用梯度记录器(自动求导)搭建各层import tensorflow as tffrom tensorflow.keras import layersx = tf.random.normal([3,784])#模拟2个样本,50个特征w1 = tf.Variable(tf.random.truncated_normal([784,256],stddev=0.5))#第1层初始化b1 = tf.zeros([256])w2 = tf原创 2020-09-04 14:10:55 · 679 阅读 · 0 评论 -
(16)tensorflow全连接的层实现
全连接的层实现功能函数代码层实现方式layers.Dense(units, activation)获取 Dense 类的权值矩阵fc.kernel获取 Dense 类的偏置向量fc.bias返回待优化参数列表fc.trainable_variables层实现layers.Dense(units, activation)units指定层输出节点数activation指定激活函数ayers.Dense在调用时会根据输入数据自动生成输入节点数im原创 2020-09-04 13:14:46 · 404 阅读 · 0 评论 -
(15)tensorflow全连接层的张量实现
全连接层的张量实现----单层神经网络的实现定义好权值张量????和偏置张量????批量矩阵相乘函数 tf.matmul()即可完成网络层的计算偏置向量????与计算完????@????的相加将结果传入激活函数import tensorflow as tfx = tf.random.normal([2,567])#模拟2个样本,567个特征w1 = tf.Variable(tf.random.truncated_normal([567,250],stddev=0.5))#初始化W,bb1原创 2020-09-04 11:25:53 · 526 阅读 · 0 评论 -
(14)tensorflow神经网络基础
神经网络基础原创 2020-09-04 11:06:49 · 130 阅读 · 0 评论 -
(13)tensorflow数据集操作
经典数据集操作功能函数代码加载数据集datasets.Dataset_name.load_data()构建 Dataset 对象tf.data.Dataset_name.from_tensor_slices((x, y))随机打散Dataset_name.shuffle(buffer_size)批训练train_db.batch(size)数据预处理Dataset_name.map(func_name)数据集类型Boston原创 2020-09-04 09:16:08 · 262 阅读 · 0 评论 -
(12)tensorflow高级操作函数
高级操作函数根据索引号收集数据tf.gather采样tf.gather_nd掩码方式采样tf.boolean_mask索引坐标tf.wheretf.scatter_nd(indices, updates, shape)函数可以高效地刷新张量的部分数据生成二维网格的采样点坐标tf.meshgrid...原创 2020-09-03 20:14:30 · 131 阅读 · 0 评论 -
(11)tensorflow填充与复制
填充与复制填充复制数据限幅原创 2020-09-03 13:54:10 · 401 阅读 · 0 评论 -
(10)tensorflow张量比较
张量比较原创 2020-09-03 12:36:44 · 449 阅读 · 0 评论 -
(9)tensorflow数据统计
数据统计功能函数代码范数计算tf.norm(x,ord)最值tf.reduce_max、 tf.reduce_min均值tf.reduce_mean和tf.reduce_sumaxis 轴上最值tf.argmax(x, axis)、tf.argmin(x, axis)原创 2020-09-02 20:44:45 · 218 阅读 · 0 评论 -
(8)tensorflow合并与分割
合并与分割功能代码函数合并之拼接tf.concat(tensors,axis)合并之堆叠tf.stack(tensors, axis)分割tf.split(x,num_or_size_split,axis)合并拼接tf.concat(tensors,axis)堆叠分割原创 2020-08-25 08:58:37 · 243 阅读 · 0 评论 -
(7)tensorflow神经网络前向传播
前向传播采用的数据集是 MNIST 手写数字图片集,输入节点数为 784,第一层的输出节点数是256,第二层的输出节点数是 128,第三层的输出节点是 10,也就是当前样本属于 10 类别的概率.import tensorflow as tfimport tensorflow.keras.datasets as datasetsdef load_data(): # 加载 MNIST 数据集 (x, y), (x_val, y_val) = datasets.mnist.load原创 2020-09-05 15:30:20 · 152 阅读 · 0 评论 -
tensorflow中文笔记
tensorflow中文笔记原创 2020-07-20 19:58:37 · 67 阅读 · 0 评论 -
(6)tensorflow数学运算
数学运算功能代码函数加tf.add减tf.subtract乘tf.multiply除tf.divide整除//余除%乘方**或者 tf.pow(x, a)矩阵乘法@平方和tf.square(x)平方根tf.sqrt(x)自然指数etf.exp(x)自然对数tfmath.log()简单运算import tensorflow as tfa = tf.range(1,9)b = tf.con原创 2020-08-23 10:49:42 · 142 阅读 · 0 评论 -
(5)tensorflow张量的变换
张量的变换功能代码改变视图tf.reshape(x,shape)增加维度tf.expand_dims(x, axis)删除维度tf.squeeze(x, axis)交换维度tf.transpose(x, perm)复制数据tf.tile(x, multiples)改变视图tf.reshape(x,shape)形成新形状视图变换只需要满足新视图的元素总量与存储区域大小相等即可x.ndim可以查询维度,x.shape查询形状import原创 2020-08-22 18:47:28 · 384 阅读 · 0 评论 -
(4)tensorflow数据索引与切片
数据索引与切片索引通过随机数模拟输入x为 5张6 × 6大小的彩色图片, 张量表达为x[5,6,6,3]x[k][m][n][h] 与 x[k,m,n,h]表达方式等价import tensorflow as tfx = tf.random.normal([5,6,6,3])print(x[1]) #索引第1张图片print(x[1,2]) #索引第2张图片第3行print(x[1,2,3])#索引第2张图片第3行第4列print(x[1,2,3,2])#索引第2张图片第3行第4列原创 2020-08-22 15:05:59 · 308 阅读 · 0 评论 -
(3)tensorflow张量的应用
张量的应用标量向量矩阵三维张量四维张量原创 2020-08-22 14:38:41 · 106 阅读 · 0 评论 -
(2)tensorflow创建张量
创建张量综述:功能代码利用数组、列表对象创建张量tf.constant与tf.convert_to_tensor创建纯0 或纯 1 张量tf.zeros()和tf.ones()按照现有张量创建纯0 或纯 1 张量tf.zeros_like, tf.ones_like创建自定义纯数字张量tf.fill(shape,number)创建已知分布张量tf.random.normal(shape, mean=0.0, stddev=1.0) 和tf.rando原创 2020-08-21 15:13:24 · 666 阅读 · 0 评论 -
(1) Tensorflow数据类型
安装Tensorflow pip install tensorflow -i https://pypi.douban.com/simple备用镜像 https://pypi.tuna.tsinghua.edu.cn/simple镜像站点汇总(镜像有个 simple,不知道不加会怎么样)https://blog.csdn.net/qq_42830971/article/details/108119481数据类型数值类型、 字符串类型和布尔类型数值类型标量 0,1,2,3,4,5向原创 2020-08-21 13:54:29 · 236 阅读 · 0 评论 -
前期准备--安装Tensorflow
安装Tensorflow自动安装: pip install tensorflow -i https://pypi.douban.com/simple 速度最快的镜像 https://pypi.tuna.tsinghua.edu.cn/simple 镜像站点汇总 https://blog.csdn.net/qq_42830971/article/details/108119481手动安装:下载站点(下载符合当前电脑环境版本的,python版本和CPU与GPU之分): https://mi原创 2020-08-20 18:19:43 · 215 阅读 · 3 评论 -
前期准备-- tensorflow手动安装镜像
https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple/tensorflow/清华站点原创 2020-08-20 17:40:12 · 210 阅读 · 0 评论 -
镜像汇总
(一)、企业站网易:http://mirrors.163.com/搜狐:http://mirrors.sohu.com/(Ubuntu旧发行版同步被冻结,不同步Ubuntu新发行版,Ubuntu源同步正常)阿里云:http://mirrors.aliyun.com/(部分镜像同步延迟超过1天)腾讯Bugly:http://android-mirror.bugly.qq.com:8080/(仅针对APP开发的软件,手动同步,限流)首都在线科技股份有限公司(英文名Capital Online Data原创 2020-08-20 11:08:22 · 1915 阅读 · 0 评论