0
Tensorflow集計機能を試すための簡単なコードを書きました。コードは以下の通りです。Tensorflow v1.2.1で要約を使用したときのInvalidArgumentError
import tensorflow as tf
import numpy as np
graph = tf.Graph()
with graph.as_default():
x = tf.placeholder(tf.float32, [1, 2], name='x')
W = tf.ones([2, 1], tf.float32, name='W')
b = tf.constant([1.5], dtype=tf.float32, shape=(1, 1), name='bias')
y_ = tf.add(tf.matmul(x, W, name='mul'), b, name='add')
tf.summary.scalar('y', y_)
with tf.Session(graph=graph) as session:
merged = tf.summary.merge_all()
fw = tf.summary.FileWriter("/tmp/tensorflow/logs", graph=graph)
tf.global_variables_initializer().run()
x_var = np.array([1., 1.], np.float32).reshape([1, 2])
print(x_var)
summary, y = session.run([merged, y_], feed_dict={x: x_var})
fw.add_summary(summary, 0)
print(y)
fw.close()
基本的には、y=Wx + b
を実装しようとします。
要約関連コードをすべて削除すると、コードが機能します。しかし、私は要約関連するコードを追加した場合、私はエラーの下になった:
InvalidArgumentError (see above for traceback): tags and values not the same shape: [] != [1,1] (tag 'y')
[[Node: y = ScalarSummary[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"](y/tags, add)]]
私は通常のPython、およびIPythonの両方で試してみました。
あなたの答えと[this](http://www.cloudypoint.com/Tutorials/discussion/python-solved-tensorflow-how-to-tensorboard/)ポストの助けを借りて、私は最終的にコード作業を手に入れました。あなたの答えも更新しました。 – davidshen84
**キー**は、入力** x **は固定サイズではありません。出力** y **で* reduce _ **を使用してください。 – davidshen84