0
我試圖建立一個基本的網絡,錯誤餵養浮點值tensorflow
# Suppress OS related warnings
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
# Import tensorflow library
import tensorflow as tf
import numpy as np
sess = tf.Session()
# Input Data X : of placeholder Value 1.0 tf.float32
x = tf.placeholder(tf.float32, name="input")
# Variable Weight : Arbitary Value
w = tf.Variable(0.8, name='weight')
# Neuron : y = w * x
with tf.name_scope('operation'):
y = tf.multiply(w, x, name='output')
# Actual Output
actual_output = tf.constant(0.0, name="actual_output")
# Loss function , delta square
with tf.name_scope("loss"):
loss = tf.pow(y - actual_output, 2, name='loss')
# Training Step : Algorithm -> GradientDescentOptimizer
with tf.name_scope("training"):
train_step = tf.train.GradientDescentOptimizer(0.025).minimize(loss)
# Ploting graph : Tensorboard
for value in [x, w, y, actual_output, loss]:
tf.summary.scalar(value.op.name, value)
# Merging all summaries : Tensorboard
summaries = tf.summary.merge_all()
# Printing the graph : Tensorboard
summary_writer = tf.summary.FileWriter('log_simple_stats', sess.graph)
# Initialize all variables
sess.run(tf.global_variables_initializer())
for i in range(300):
summary_writer.add_summary(sess.run(summaries), i)
sample = np.random.uniform(low=0.0, high=400.0)
print(sample)
sess.run(train_step, feed_dict={x: sample})
# Output
print(sess.run([w]))
和錯誤是
你必須養活佔位符張量「輸入」的值與D型浮動 [ [節點:輸入= Placeholderdtype = DT_FLOAT,形狀= [],_device = 「/作業:本地主機/複製:0 /任務:0/CPU:0」]]
仍然是一樣的錯誤 –
只是跑你的代碼。您的其他問題是,當您運行摘要時,您不會提供相同的數據。讓我編輯答案來包含它。 –
很好的解決了,但代碼沒有按預期工作,你有一個工作代碼,你可以發佈它嗎? –