我是tensorflow中的新手,并尝试创建一个模型,该模型将根据INPUT预测X和Y坐标,INPUT由86个变量组成,这些变量决定从位于建筑物中的86个扫描接收的信号强度。我有340个测试数据。我解析它们并将它们放在两个.csv文件中。
第一组包含有序信号强度。我把它保存为data.csv。 data.csv
第二个文件包含当时仪表所在的坐标。我把它保存为labes.csv。 labels.csv
我已经创建了一个模型,但不幸的是它的准确性只改变了两个训练步骤。如果我想制作tf.summary.merge_all(),则会出现此错误:Error message。如果我删除此行,则培训会成功结束,但除前两个步骤外,准确性不会改变: training steps
此处出现错误消息:
Nan的摘要直方图:偏差
[[Node: Biases = HistogramSummary[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"](Biases/tag, Bias/read)]]
由op' Biases'引起,定义于:
文件" E:\ Programy \ Microsoft Visual Studio 14.0 \ Common7 \ IDE \ Extensions \ Microsoft \ Python工具,用于Visual Studio \ 2.2 \ visualstudio_py_launcher.py",第78行,
vspd.debug(filename, port_num, debug_id, debug_options, run_as)
文件" E:\ Programy \ Microsoft Visual Studio 14.0 \ Common7 \ IDE \ Extensions \ Microsoft \ Python工具,用于Visual Studio \ 2.2 \ visualstudio_py_debugger.py",第2483行,在调试中
exec_file(file, globals_obj)
文件" E:\ Programy \ Microsoft Visual Studio 14.0 \ Common7 \ IDE \ Extensions \ Microsoft \ Python工具,用于Visual Studio \ 2.2 \ visualstudio_py_util.py",第111行,在exec_file中
exec_code(code, file, global_variables)
文件" E:\ Programy \ Microsoft Visual Studio 14.0 \ Common7 \ IDE \ Extensions \ Microsoft \ Python工具,用于Visual Studio \ 2.2 \ visualstudio_py_util.py",第87行,在exec_code中
exec(code_obj, global_variables)
文件" C:\ Users \ Tesi \ documents \ visual studio 2015 \ Projects \ LocationDetectionTensorflow \ LocationDetectionTensorflow \ LocationDetectionTensorflow.py",第41行,
tf.summary.histogram("Biases", b)
文件&#34; C:\ Users \ Tesi \ AppData \ Local \ Programs \ Python \ Python35 \ lib \ site-packages \ tensorflow \ python \ summary \ summary.py&#34;,第193行,直方图< / p>
tag=tag, values=values, name=scope)
文件&#34; C:\ Users \ Tesi \ AppData \ Local \ Programs \ Python \ Python35 \ lib \ site-packages \ tensorflow \ python \ ops \ gen_logging_ops.py&#34;,第215行,在_histogram_summary < / p>
"HistogramSummary", tag=tag, values=values, name=name)
文件&#34; C:\ Users \ Tesi \ AppData \ Local \ Programs \ Python \ Python35 \ lib \ site-packages \ tensorflow \ python \ framework \ op_def_library.py&#34;,第787行,在_apply_op_helper < / p>
op_def=op_def)
文件&#34; C:\ Users \ Tesi \ AppData \ Local \ Programs \ Python \ Python35 \ lib \ site-packages \ tensorflow \ python \ framework \ ops.py&#34;,第3160行,在create_op < / p>
op_def=op_def)
文件&#34; C:\ Users \ Tesi \ AppData \ Local \ Programs \ Python \ Python35 \ lib \ site-packages \ tensorflow \ python \ framework \ ops.py&#34;,第1625行,初始化
self._traceback = self._graph._extract_stack() # pylint: disable=protected-access
InvalidArgumentError(参见上面的回溯):Nan的摘要直方图:偏差
[[Node: Biases = HistogramSummary[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"](Biases/tag, Bias/read)]]
Data.csv:
100,94,99,100,100,100,100,100,100,100,100,100,100,100,100,90,79,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,85,100,78,77,79,78,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,89
... 100,100,100,100,100,87,100,87,100,97,100,90,90,100,100,100,100,100,100,92,100,100,100,100,95,100,100,100,100,88,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,64,64,74,74,100,100,100,100,100,100,100,73,100,100,100,100,100,100,88,100,100,100,100,100,100,100,100,100,100,100,100
Labels.csv:
450,2300
1750,900 ...
代码在这里:
import tensorflow as tf
import numpy as np
data = np.genfromtxt("dataExcel.csv", delimiter=';')
labels = np.genfromtxt("labelsExcel.csv", delimiter=';')
inputs = 86
outputs = 2
x = tf.placeholder(tf.float32, shape=[None, inputs], name='input_X')
y = tf.placeholder(tf.float32, shape=[None, outputs], name='output_Y')
tf.summary.histogram("input_X",x)
tf.summary.histogram("output_Y",y)
W = tf.Variable(tf.zeros([86, 2]), name="Weight")
b = tf.Variable(tf.zeros([2]), name="Bias")
tf.summary.histogram("Weights", W)
tf.summary.histogram("Biases", b)
with tf.name_scope("softmax") as scope:
softmax = tf.nn.softmax(tf.matmul(x, W) + b)
with tf.name_scope("cross_entropy_also_cost_function") as scope:
cross_entropy = -tf.reduce_sum(y*tf.log(softmax))
tf.summary.scalar("cross_entropy", cross_entropy)
with tf.name_scope("train") as scope:
optimizer = tf.train.GradientDescentOptimizer(0.01).minimize(cross_entropy)
with tf.name_scope("accuracy"):
prediction = tf.equal(tf.argmax(softmax,1),tf.argmax(y,1))
accuracy = tf.reduce_mean(tf.cast(prediction,tf.float32))
tf.summary.scalar("accuracy", accuracy)
merged_summary = tf.summary.merge_all()
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
avg_cost = 0.
writer = tf.summary.FileWriter("/tmp/Location")
writer.add_graph(sess.graph)
for i in range(1001):
sess.run(optimizer, feed_dict={x: train_batch_x, y: train_batch_y})
avg_cost += sess.run(cross_entropy, feed_dict={x: train_batch_x, y: train_batch_y})
tf.summary.scalar("avrage cost", avg_cost)
merged_summary_string = sess.run(merged_summary, feed_dict={x: train_batch_x, y: train_batch_y})
writer.add_summary(merged_summary_string, i)
train_accuracy = sess.run(accuracy, feed_dict={x: train_batch_x, y: train_batch_y})
print("STEP:", i,"=>", train_accuracy,"% accuracy.")
writer.close()
所以我的问题是:如何修复我的模型来预测X和Y坐标?
感谢您的每一条建议或至少努力!祝你有愉快的一天!
更新: 所以我应该更换我的sotfmax功能:
with tf.name_scope("softmax") as scope:
softmax = tf.nn.softmax(tf.matmul(x, W) + b)
用这个?:
with tf.name_scope("softmax") as scope:
softmax = tf.nn.softmax_cross_entropy_with_logits()'
但是这个函数的输入是什么?