0

我试图修改“ mnist_with_summaries.py”以分析我研究中的图像数据。

当我尝试使用 TensorBoard 进行可视化时,出现以下错误(0x2e414f0 Compute status: Out of range: Nan in summary histogram for: HistogramSummary):

W tensorflow/core/common_runtime/executor.cc:1102] 0x2e414f0 Compute status: Out of range: Nan in summary histogram for: HistogramSummary
     [[Node: HistogramSummary = HistogramSummary[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"](HistogramSummary/tag, weights/read)]]
W tensorflow/core/common_runtime/executor.cc:1102] 0x2e414f0 Compute status: Out of range: Nan in summary histogram for: HistogramSummary_1
     [[Node: HistogramSummary_1 = HistogramSummary[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"](HistogramSummary_1/tag, bias/read)]]
W tensorflow/core/common_runtime/executor.cc:1102] 0x2e414f0 Compute status: Out of range: Nan in summary histogram for: HistogramSummary
     [[Node: HistogramSummary = HistogramSummary[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"](HistogramSummary/tag, weights/read)]]
     [[Node: _send_train/ScatterUpdate_0 = _Send[T=DT_FLOAT, client_terminated=true, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/cpu:0", send_device_incarnation=1698099469756475374, tensor_name="train/ScatterUpdate:0", _device="/job:localhost/replica:0/task:0/cpu:0"](train/ScatterUpdate)]]
Traceback (most recent call last):
  File "NeuralNetwork_TensorFlow.py", line 102, in main
    update_op_train, train_step], feed_dict=feed)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 315, in run
    return self._run(None, fetches, feed_dict)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 511, in _run
    feed_dict_string)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 564, in _do_run
    target_list)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 586, in _do_call
    e.code)
OutOfRangeError: Nan in summary histogram for: HistogramSummary
     [[Node: HistogramSummary = HistogramSummary[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"](HistogramSummary/tag, weights/read)]]
Caused by op u'HistogramSummary', defined at:
  File "NeuralNetwork_TensorFlow.py", line 124, in <module>
    main()
  File "NeuralNetwork_TensorFlow.py", line 58, in main
    w_hist = tf.histogram_summary("weights", W)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/summary_ops.py", line 60, in histogram_summary
    tag=tag, values=values, name=scope)
  File "/usr/lrflow/python/ops/gen_summary_ops.py", line 34, in _histogram_summary
    name=name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/op_def_library.py", line 655, in apply_op
    op_def=op_def)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2040, in create_op
    original_op=self._default_original_op, op_def=op_def)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1087, in __init__
    self._traceback = _extract_stack()ocal/lib/python2.7/dist-packages/tensorflow/python/ops/gen_summary_ops.py", line 34, in _histogram_summary
    name=name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/op_def_library.py", line 655, in apply_op
    op_def=op_def)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2040, in create_op
    original_op=self._default_original_op, op_def=op_def)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1087, in __init__
    self._traceback = _extract_stack()

我想知道为什么?这个“超出范围”是什么意思?

这是我修改后的代码的一部分:

...
sess = tf.Session()

#training data
trainDS = trainds.read_data_sets(ins_size, step);
testDS = testds.read_data_sets(img, ins_size, step)

batch_num  = testDS.test.ylength
batch_size = testDS.test.xlength

# Create the model
x = tf.placeholder(tf.float32, shape=[None, ins_size**2*3], name = "x_input")
y_ = tf.placeholder(tf.float32, [None, label_option], name="y_input") 
W = tf.Variable(tf.zeros([ins_size**2*3,label_option]), name = "weights")
b = tf.Variable(tf.zeros([label_option]), name = "bias")

with tf.name_scope("Wx_b") as scope:
  y = tf.nn.softmax(tf.matmul(x, W) + b)

#Add summary ops to collect data
w_hist = tf.histogram_summary("weights", W)
b_hist = tf.histogram_summary("biases", b)
... ...
merged_train = tf.merge_summary([w_hist, b_hist]) 
writer = tf.train.SummaryWriter("/tmp/neuralnetwork_logs", \
                   sess.graph.as_graph_def(add_shapes=True))
init = tf.initialize_all_variables()    
sess.run(init)

#train
for i in range(batch_num):
  batch_xs, batch_ys = trainDS.train.next_batch(batch_size)
  feed = {x: batch_xs, y_: batch_ys, batch_index: i}
  if i % 100 == 0:  # Record summary data
    result = sess.run([merged_train, \
       update_op_train, train_step], feed_dict=feed)
    writer.add_summary(result[0], i)
  else:
    sess.run([update_op_train, train_step], feed_dict=feed)

sess.close()
... ...

请帮我!

4

0 回答 0