tf.placeholde function interpretation and usage

Function prototype : tf.placeholder (dtype, shape = None , name = None)

Description : This function is used to get the real training samples passed in. But it can also be understood as a parameter,
to define the process, and then given a specific value at the time of execution. (Corresponding to first define a container, comprising a capacity, size and other information, real time call things go down inside the container injection)

Note : do not have to specify the initial value, at run time, by the function of the parameter Session.run "feed_dict = {x: value} " assignment

Parameters :
DTYPE: data type. Commonly used tf.float32, tf.float64 other numeric type
shape: shape data. The default is None, that is, one-dimensional value, it can be multi-dimensional, such as [, 2, 3]
name: Name

Examples :

import tensorflow as tf
import numpy as np

x = tf.placeholder(tf.float32, shape=[24, 24])  
y = tf.matmul(x, x)  

with tf.Session() as sess:  
  print(sess.run(y))  # ERROR: 此处x还没有赋值.  

  rand_array = np.random.rand(24,24)  
  print(sess.run(y, feed_dict={x: rand_array}))  # 这一步 x 将被赋值
   
   

    Add that :
    the tf.Variable different, tf.Variable mainly used for some variables may be trained (trainable variables), such as a model weights (weight) or offset value (bias).
    tf.Variable When you declare a variable, you must provide the initial value. It is considered that the statement is an argument. Really meaning that the variable name, in other words the value of the variable will change.

    [Reserved] https://blog.csdn.net/qq_18254385/article/details/78073531

    Guess you like

    Origin www.cnblogs.com/yuehouse/p/12033572.html