当前位置:网站首页>tensorflow入门
tensorflow入门
2022-07-25 10:27:00 【fatfatmomo】
数值计算表示为计算图,
TensorFlow的程序主干是一个图,
图节点是操作(代码中操作),有多个输入和一个输出
节点间的边表示之间流动的张量(tensors),比如n维数组
使用图,允许小而简单的操作建立复杂模型,会使梯度计算变简单---->自动求导
h=ReLU(Wx+b)
Variables:W,b
Placeholders(占位符):执行时间才会接受的点, x 即input。仅分配一个数据类型,一种大小的张量
Mathematical operations:数学操作节点 矩阵乘法、假发、激活函数等
import tensorflow as tf
import numpy as np
################################ 建立图 ###################################
b = tf.Variable(tf.zeros((100,)))
W = tf.Variable(tf.random_uniform((784,100),-1,1))
x = tf.placeholder(tf.float32,(100,784))
h = tf.nn.relu(tf.matmul(x,W)+b)
################################# 将图部署到会话上 ###############################
# 建立会话对象,调用参数Fetches,Feeds
# Fetches:list of graph nodes which return the output of the nodes
# Feeds:dictionary mapping from graph nodes to actual values,占位符
# 建立会话对象,采取默认环境,CPU,可以添加设备参数. 会话将图部署到硬件上?
sess = tf.Session()
sess.run(tf.initialize_all_variables())
sess.run(h, {x:np.random.random(100,784)})
################################ 训练模型 ######################################
prediction = tf.nn.softmax()#输出的预测值
label = tf.placeholder(tf.float32,[100,10])
cross_entropy = -tf.reduce_sum(label * tf.log(prediction),axis=1)
# 创建梯度下降的优化器,学习率设置0.5,最小化交叉熵cross_entropy
train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)
sess = tf.Session()
sess.run(tf.initialize_all_variables())
for i in range(100):
batch_x,batch_label = data.next_batch()
sess.run(train_step,feed_dict={x: batch_x,label: batch_label})
with tf.variable_scope("foo"):
v=tf.get_variable("v",shape=[1])
边栏推荐
- 学习路之PHP--TP5.0使用中文当别名,报“不支持的数据表达式”
- AI system frontier dynamics issue 43: ONEFLOW V0.8.0 officially released; GPU finds human brain connections; AI doctoral online crowdfunding research topic
- Learn NLP with Transformer (Chapter 2)
- HCIP (01)
- 复习背诵整理版
- SQL语言(三)
- JS collection
- Flask framework -- flask caching
- 性能测试中TPS的计算【杭州多测师】【杭州多测师_王sir】
- UE4.26源码版学习广域网独立服务器时遇到的客户端运行黑屏问题
猜你喜欢
![[flask advanced] deeply understand the application context and request context of flask from the source code](/img/67/88c21967da28d09694568ebdaae44c.png)
[flask advanced] deeply understand the application context and request context of flask from the source code

Reinforcement learning (III)

2021 qunar written examination summary

SQL语言(三)

BeautifulSoup的一些用法

Microwave technology homework course design - Discrete capacitance and inductance + microstrip single stub + microstrip double stub

mysql主从复制与读写分离

2021 CEC written examination summary

mysql高级语句(一)(总有一个人的出现,让你的生活不再继续糟糕)

HCIP(13)
随机推荐
接口流量突增,如何做好性能调优?
【云享新鲜】社区周刊·Vol.72- 2022华为开发者大赛中国区首场开幕式启动;华为云KooMessage火热公测中…
C3d model pytorch source code sentence by sentence analysis (III)
Shell 脚本参数传递时有 \r 换行符问题
MySQL | GROUP_CONCAT函数,将某一列的值用逗号拼接
What is MySQL transaction
[flask advanced] combined with the source code, explain the operation mechanism of flask (in and out of the stack)
mysql主从复制与读写分离
HCIP实验(01)
The University of Gottingen proposed clipseg: a model that can perform three segmentation tasks simultaneously using text and image prompts
AI系统前沿动态第43期:OneFlow v0.8.0正式发布;GPU发现人脑连接;AI博士生在线众筹研究主题
100W!
JS 将伪数组转换成数组
企业实践开源的动机
JS hash table 01
Nb-iot control LCD (date setting and reading)
学习路之PHP--TP5.0使用中文当别名,报“不支持的数据表达式”
HCIA experiment (09)
Druid 查询超时配置的探究 → DataSource 和 JdbcTemplate 的 queryTimeout 到底谁生效?
Signal integrity (SI) power integrity (PI) learning notes (XXXIII) 102 general design rules to minimize signal integrity problems