【发布时间】:2016-12-12 02:58:29
【问题描述】:
我刚刚开始使用 TensorFlow。我无法让tf.nn.softmax 与tf.placeholder 一起工作。这段代码:
import tensorflow as tf
import numpy as np
shape = [1, 3]
value = 0.
probs = tf.constant(value, shape=shape)
sampling_prob = tf.nn.softmax(probs)
with tf.Session() as sess:
print(sess.run(sampling_prob))
如预期的那样,返回[[ 0.33333334 0.33333334 0.33333334]]。但是当我将其更改为:
probs2 = tf.placeholder(tf.float32, shape=shape)
sampling_prob2 = tf.nn.softmax(probs2)
with tf.Session() as sess:
print(sess.run(sampling_prob2, feed_dict={probs2: np.full(shape, value)}))
我突然收到[[ 0. 0. 0.]]。怎么可能?
在 Windows 10、Python 3.5.2、TensorFlow 0.12、CUDA 8 上运行。
【问题讨论】:
-
它对我来说可以正常工作,Ubuntu 14.04, Python 2.7, TensorFlow 0.11 CPU only
标签: python tensorflow softmax