tensorflow學習之(四)使用placeholder 傳入值


#placeholder 傳入值
import tensorflow as tf

"""
tf.Variable:主要在於一些可訓練變量(trainable variables),比如模型的權重(weights,W)或者偏執值(bias):
    聲明時,必須提供初始值;
    名稱的真實含義,在於變量,也即在真實訓練時,其值是會改變的,自然事先需要指定初始值; 
tf.placeholder:用於得到傳遞進來的真實的訓練樣本:
    不必指定初始值,可在運行時,通過 Session.run 的函數的 feed_dict 參數指定;
    這也是其命名的原因所在,僅僅作為一種占位符;
"""
input1 = tf.placeholder(tf.float32)#默認是float32的形式
input2 = tf.placeholder(tf.float32)

output = tf.multiply(input1,input2)

with tf.Session() as sess:
    print(sess.run(output,feed_dict={input1:[7.0],input2:[2.0]}))#以字典的形式傳值給output

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM