记住 placeholder就是开辟一个空间,在运行session的时候赋值。有文档的哦
1. Writing and running programs in TensorFlow has the following steps:
To summarize, remember to initialize your variables, create a session and run the operations inside the session.
Writing and running programs in TensorFlow has the following steps:
To summarize, you how know how to:
Create placeholdersSpecify the computation graph corresponding to operations you want to computeCreate the sessionRun the session, using a feed dictionary if necessary to specify placeholder variables' values.
目前学到的有:
1.tf.constant(value,name=“*”) 创造一个叫*的常量值为value。
要运行一个程序,先建session,例
Note that there are two typical ways to create and use sessions in tensorflow:
Method 1:
sess = tf.Session()
# Run the variables initialization (if needed), run the operations
result = sess.run(..., feed_dict = {...})
sess.close() # Close the session
Method 2:
with tf.Session() as sess:
# run the variables initialization (if needed), run the operations
result = sess.run(..., feed_dict = {...})
# This takes care of closing the session for you :)
tf.placeholder(tf.float32,name="z")创造叫z的量,类型是float32,看名字就是预留空间,可以先不给该值赋量。
cost = sess.run(cost,feed_dict=({z:logits,y:labels})) 这是对之前没有幅值的两个量z,y进行幅值用的feed_dict
2.有用的函数
tf.matmul计算矩阵乘法,tf.add计算加法。
tf.global_variables_initializer()
. 参数的初始化。
tf.nn.sigmoid_cross_entropy_with_logits(logits = z, labels = y)计算cost所用。
tf.one_hot(labels,C,1)labels是指输入的值,C表示可表示的类数,该类为1其余为0。就是自动将y从原始数据转成只有一个1的表示,例如
TensorFlow架构深度学习步骤:
1.Your first task is to create placeholders for X
and Y
. This will allow you to later pass your training data in when you run your session.
2.Your second task is to initialize the parameters in tensorflow.
3.You will now implement the forward propagation module in tensorflow. The function will take in a dictionary of parameters and it will complete the forward pass.
4.compute the cost,It is important to know that the "logits
" and "labels
" inputs of tf.nn.softmax_cross_entropy_with_logits
are expected to be of shape (number of examples, num_classes). We have thus transposed Z3 and Y for you.Besides, tf.reduce_mean
basically does the summation over the examples.
5.Backward propagation & parameter updates
Tensorflow is a programming framework used in deep learningThe two main object classes in tensorflow are Tensors and Operators. When you code in tensorflow you have to take the following steps:
You can execute the graph multiple times as you've seen in model()The backpropagation and optimization is automatically done when running the session on the "optimizer" object.
如果对你有所帮助,谢谢您的鼓励^_^
红包还不收?