【问题标题】:TensorFlow Neural Network's output don't changeTensorFlow 神经网络的输出不会改变
【发布时间】:2016-11-09 18:18:01
【问题描述】:

我想做一个神经网络的基本应用。我有一个值列表。我选择了 30 个值的序列,我想猜测 31 个。( 希望有关系)

我的问题是我的神经网络的输出总是1。

import tensorflow as tf

INPUT_NUMBER = 30

filename_queue = tf.train.string_input_producer(["googl.csv"])
reader = tf.TextLineReader()
key, value = reader.read(filename_queue)
closeValue_ = tf.decode_csv(value, record_defaults=[[1.]])

# Neural Network

tf_in = tf.placeholder(tf.float32, [None, INPUT_NUMBER])
tf_weight = tf.Variable(tf.random_normal([INPUT_NUMBER, 1], stddev=0.35), name="tf_weight")
tf_bias = tf.Variable(tf.zeros([1]))

y = tf.nn.softmax(tf.matmul(tf_in, tf_weight) + tf_bias)
y_ = tf.placeholder(tf.float32, [None, 1])

cost = tf.abs(tf.sub(y, y_))
train_step = tf.train.AdamOptimizer().minimize(cost)

init = tf.initialize_all_variables()


with tf.Session() as sess:
    coord = tf.train.Coordinator()
    threads = tf.train.start_queue_runners(coord=coord)
    data = []
    for i in range(3000):
        closeValue = sess.run([closeValue_])[0][0]
        data.append(closeValue/10000)

    sess.run(init)

    for i in range(2000):
        batch_xs = []
        batch_ys = []
        for j in range(i, i+30):
            batch_xs.append(data[j])
        batch_ys.append(data[j+1])
        _, predictionValue, realValue = sess.run([train_step, y, y_], feed_dict={tf_in: [batch_xs], y_: [batch_ys]})
        print("predictionValue: ")
        print(predictionValue)
        print("realValue: ")
        print(realValue)
    coord.request_stop()
    coord.join(threads)

输出:

   predictionValue: 
  [[ 1.]]
  realValue: 
  [[ 0.01313463]]
  predictionValue: 
  [[ 1.]]
  realValue: 
  [[ 0.01299099]]
  predictionValue: 
  [[ 1.]]
  realValue: 
  [[ 0.01402302]]
  predictionValue: 
  [[ 1.]]
  realValue: 
  [[ 0.01488589]]
  predictionValue: 
  [[ 1.]]
  realValue: 
  [[ 0.01502102]]
  predictionValue: 
  [[ 1.]]
  realValue: 
  [[ 0.01551652]]
  predictionValue: 
  [[ 1.]]
  realValue: 
  [[ 0.01561962]]
  predictionValue: 
  [[ 1.]]
  realValue: 
  [[ 0.01456456]]
  predictionValue: 
  [[ 1.]]
  realValue: 
  [[ 0.01558859]]
  predictionValue: 
  [[ 1.]]
  realValue: 
  [[ 0.01595495]]
  predictionValue: 
  [[ 1.]]
  realValue: 
  [[ 0.01657357]]
  predictionValue: 
  [[ 1.]]
  realValue: 
  [[ 0.01657758]]
  predictionValue: 
  [[ 1.]]
  realValue: 
  [[ 0.01712913]]
  predictionValue: 
  [[ 1.]]
  realValue: 
  [[ 0.01836537]]
  predictionValue: 
  [[ 1.]]
  realValue: 
  [[ 0.01734184]]
  predictionValue: 
  [[ 1.]]
  realValue: 
  [[ 0.01798599]]
  predictionValue: 
  [[ 1.]]
  realValue: 
  [[ 0.0180025]]
  predictionValue: 
  [[ 1.]]
  realValue: 
  [[ 0.01791792]]
  predictionValue: 
  [[ 1.]]
  realValue: 
  [[ 0.01845596]]
  predictionValue: 
  [[ 1.]]
  realValue: 
  [[ 0.01649099]]
  predictionValue: 
  [[ 1.]]
  realValue: 
  [[ 0.01698148]]
  predictionValue: 
  [[ 1.]]
  realValue: 
  [[ 0.01763363]]
  predictionValue: 
  [[ 1.]]
  realValue: 
  [[ 0.0178013]]
  predictionValue: 
  [[ 1.]]
  realValue: 
  [[ 0.01815565]]
  predictionValue: 
  [[ 1.]]
  realValue: 
  [[ 0.01898498]]
  predictionValue: 
  [[ 1.]]
  realValue: 
  [[ 0.01864565]]

【问题讨论】:

  • 你能给我们提供培训的痕迹吗?这通常有线索。

标签: python machine-learning neural-network tensorflow


【解决方案1】:

你正在做回归,因此你的模型不应该最后有softmax。 Softmax 是一种用于产生概率估计的归一化元素,因此如果您只有一个输出,那么这个估计将是……总是 1。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-23
    • 2020-05-03
    • 2020-03-15
    相关资源
    最近更新 更多