移动手机号码网站90设计网图片
移动手机号码网站,90设计网图片,品牌网站首页设计,做网站必备软件前向传播神经网络搭建
1.tensorflow库搭建神经网络
参数#xff1a;线上的权重W#xff0c;用变量表示#xff0c;随机给初值。相关介绍 tf.truncated_normal():去掉过大偏离点的正太分布tf.random_normal()正太分布tf.random_uniform():平均分布tf.zeros:全零数组#x…前向传播神经网络搭建
1.tensorflow库搭建神经网络
参数线上的权重W用变量表示随机给初值。相关介绍 tf.truncated_normal():去掉过大偏离点的正太分布tf.random_normal()正太分布tf.random_uniform():平均分布tf.zeros:全零数组tf.zeros([3,2],int32)tf.ones:全一数组,tf.ones([3,2],int32)tf.fill:全定值数组,tf.ones([3,2],6)tf.constant:直接给值,tf.constant([3,2,1]) Variable(tf.random_normal([2,3],stddev2,mean0,seed1))参数介绍 random_normal生成正态分布随机数2*3矩阵标准差为2均值为0随机种子1随机种子如果去掉每次生成的随机数将不一致变量初始化计算图结点运算需要用会话(with结构)实现
2.神经网络的实现过程 准备数据集提取特征最为输入喂给神经网络(Neural Network,NN)搭建NN结构从输入到输出(先搭建计算图在用会话执行),NN 前向传播算法-----计算输出。大量特征数据喂给NN迭代优化NN参数NN反向传播算法-----优化参数训练模型使用训练好的模型预测和分类。
3.前向传播-----搭建模型实现推理以全连接网络为例
eg.生产一批零件将体积x1重量x2为特征输入NN通过NN后输出一个值.运算结果中间结点值a:XW1第二层权重W2第一层权重W1输入体积X实现 #实例两层简单全连接神经网络
import tensorflow as tf#定义输入和参数
xtf.constant([[0.7,0.8]])#一行两列的张量存储体积和重量
w1tf.Variable(tf.random.normal([2,3],stddev1,seed1))
w2tf.Variable(tf.random.normal([3,1],stddev1,seed1))
print(w1)
print(w2)
#定义前向传播
atf.matmul(x,w1)
ytf.matmul(a,w2)#用会话计算结果
with tf.compat.v1.Session() as sess:#tf.Session#因版本不同tf.Session使用tf.compat.v1.Session()代替init_optf.compat.v1.global_variables_initializer()#tf.global_variables_initializer()用tf.compat.v1.global_variables_initializer()sess.run(init_op)print(result is \n,sess.run(y))#实例两层简单全连接神经网络
import tensorflow as tf#定义输入和参数
#xtf.placeholder(tf.float32,shape(1,2))
xtf.compat.v1.placeholder(tf.float32,shape(1,2))#通过placeholder实行定义输入(sess.run喂入一组数据)
w1tf.Variable(tf.random.normal([2,3],stddev1,seed1))
w2tf.Variable(tf.random.normal([3,1],stddev1,seed1))
print(w1)
print(w2)
#定义前向传播
atf.matmul(x,w1)
ytf.matmul(a,w2)#用会话计算结果
with tf.compat.v1.Session() as sess:#tf.Session#init_optf.global_variables_initializer()init_optf.compat.v1.global_variables_initializer()#tf.global_Variables_initializer()sess.run(init_op)print(result is \n,sess.run(y,feed_dict{x:[[0.7,0.5]]}))#x的一组特征喂入神经网络。#实例两层简单全连接神经网络
import tensorflow as tf#定义输入和参数
#xtf.placeholder(tf.float32,shape(1,2))
xtf.compat.v1.placeholder(tf.float32,shape(None,2))#通过placeholder实行定义输入(sess.run喂入多组数据),不知道维度可以None
w1tf.Variable(tf.random.normal([2,3],stddev1,seed1))
w2tf.Variable(tf.random.normal([3,1],stddev1,seed1))
print(w1)
print(w2)
#定义前向传播
atf.matmul(x,w1)
ytf.matmul(a,w2)#用会话计算结果
with tf.compat.v1.Session() as sess:#tf.Session#init_optf.global_variables_initializer()init_optf.compat.v1.global_variables_initializer()#tf.global_Variables_initializer()sess.run(init_op)print(result is \n,sess.run(y,feed_dict{x:[[0.7,0.5],[0.2,0.3],[0.3,0.4],[0.4,0.5]]}))#x的一组特征喂入神经网络。print(w1\n,sess.run(w1))print(w2\n,sess.run(w2)) 运算结果
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/86587.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!