当前位置:网站首页>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])
边栏推荐
- Redis之压缩列表ziplist
- Want to record your supernatural moments when playing games? Let's take a look at how to use unity screenshots
- C# Newtonsoft. Jason advanced usage
- Last week's hot review (7.18-7.24)
- Learn NLP with Transformer (Chapter 8)
- Some usages of beautifulsoup
- HCIP(11)
- 只知道预制体是用来生成物体的?看我如何使用Unity生成UI预制体
- LVS负载均衡之LVS-NAT搭建Web群集
- What kind of product power does Hongguang miniev, the top seller of new energy, have?
猜你喜欢

100W!

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

游戏背包系统,“Inventory Pro插件”,研究学习-----妈妈再也不用担心我不会做背包了(Unity3D)

Want to record your supernatural moments when playing games? Let's take a look at how to use unity screenshots

Code representation learning: introduction to codebert and other related models

Let sports happen naturally, and fire creates a new lifestyle

Implementation of recommendation system collaborative filtering in spark

Learn NLP with Transformer (Chapter 7)
![TPS calculation in performance test [Hangzhou multi tester] [Hangzhou multi tester _ Wang Sir]](/img/b2/7a6b99f0ec907b83ac58ed44b23062.png)
TPS calculation in performance test [Hangzhou multi tester] [Hangzhou multi tester _ Wang Sir]

SQL语言(三)
随机推荐
From the perspective of open source, analyze the architecture design of SAP classic ERP that will not change in 30 years
The most detailed MySQL index analysis (mind map is attached at the end of the article)
PostgreSQL踩坑 | ERROR: operator does not exist: uuid = character varying
Motivation of enterprises to practice open source
Hcip experiment (02)
feign客户端请求之LoadBalancerLifecycle生命周期
Mlx90640 infrared thermal imager temperature measurement module development notes (V)
玩游戏想记录一下自己超神的瞬间?那么就来看一下如何使用Unity截图吧
BGP federal experiment
常见的几种PCB表面处理技术!
Learn NLP with Transformer (Chapter 1)
C# Newtonsoft.Json 高级用法
mysql事务是什么
Dataframe print 省略号问题
用Unity不会几个插件怎么能行?Unity各类插件及教程推荐
NowCoderTOP12-16——持续更新ing
推荐系统-协同过滤在Spark中的实现
shell-第六章练习
SQL语言(六)
LVS负载均衡之LVS-NAT搭建Web群集