当前位置:网站首页>Getting started with tensorflow
Getting started with tensorflow
2022-07-25 11:25:00 【fatfatmomo】
The numerical calculation is shown as a calculation diagram ,
TensorFlow The program trunk of is a diagram ,
Graph nodes are operations ( Code operation ), There are multiple inputs and one output
The edges between nodes represent the tensor of flow between (tensors), such as n Dimension group
Use the figure , Allow small and simple operations to build complex models , It will make gradient calculation simpler ----> Automatic derivation
h=ReLU(Wx+b)
Variables:W,b
Placeholders( Place holder ): The execution time will be accepted , x namely input. Assign only one data type , A tensor of size
Mathematical operations: Mathematical operation node Matrix multiplication 、 Wig 、 Activation functions, etc
import tensorflow as tf
import numpy as np
################################ Set up a map ###################################
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)
################################# Deploy the graph to the session ###############################
# Establish session object , Call parameters Fetches,Feeds
# Fetches:list of graph nodes which return the output of the nodes
# Feeds:dictionary mapping from graph nodes to actual values, Place holder
# Establish session object , Take default environment ,CPU, You can add device parameters . The session deploys the graph to hardware ?
sess = tf.Session()
sess.run(tf.initialize_all_variables())
sess.run(h, {x:np.random.random(100,784)})
################################ Training models ######################################
prediction = tf.nn.softmax()# The predicted value of the output
label = tf.placeholder(tf.float32,[100,10])
cross_entropy = -tf.reduce_sum(label * tf.log(prediction),axis=1)
# Create an optimizer for gradient descent , Learning rate setting 0.5, Minimize cross entropy 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])
边栏推荐
- 玩游戏想记录一下自己超神的瞬间?那么就来看一下如何使用Unity截图吧
- txt转csv文件,隔行出现空行
- Mlx90640 infrared thermal imager temperature measurement module development notes (V)
- STM32CubeMX学习记录--安装配置与使用
- shell-第四天作业
- 【IJCAI 2022】参数高效的大模型稀疏训练方法,大幅减少稀疏训练所需资源
- mysql高级语句(一)(总有一个人的出现,让你的生活不再继续糟糕)
- Redis sentry, high availability executor
- Learn NLP with Transformer (Chapter 6)
- Nb-iot control LCD (date setting and reading)
猜你喜欢

HCIP(11)

SQL语言(二)

Learn NLP with Transformer (Chapter 6)

Motivation of enterprises to practice open source

A troubleshooting record of DirectShow playback problems

HCIA experiment (06)

The University of Gottingen proposed clipseg: a model that can perform three segmentation tasks simultaneously using text and image prompts

SQL语言(三)

SQL注入 Less18(头部注入+报错注入)

Hcip experiment (04)
随机推荐
Compressed list ziplist of redis
shell-第六章练习
推荐系统-协同过滤在Spark中的实现
[recursion] 938. Range and of binary search tree
feign客户端请求之LoadBalancerLifecycle生命周期
Learn NLP with Transformer (Chapter 3)
The most detailed MySQL index analysis (mind map is attached at the end of the article)
【高并发】通过源码深度分析线程池中Worker线程的执行流程
数据库设计-简化字典表[通俗易懂]
LVS load balancing lvs-dr builds Web Clusters and LVS combines with kept to build highly available Web Clusters
syncronized锁升级的过程
ArcMap无法启动解决方法
HCIA experiment (08)
The integration of two in one has a long way to go
SQL语言(二)
My colleague looked at my code and exclaimed: how can I use a singleton in unity
Nowcodertop12-16 - continuous updating
Hcip experiment (03)
Mlx90640 infrared thermal imager temperature measurement module development notes (V)
[flask advanced] deeply understand the application context and request context of flask from the source code