【问题标题】:TensorFlow - softmax on a placeholderTensorFlow - 占位符上的 softmax
【发布时间】:2016-12-12 02:58:29
【问题描述】:

我刚刚开始使用 TensorFlow。我无法让tf.nn.softmaxtf.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


【解决方案1】:

代码对我来说很好用(Ubuntu、Python 2、TensorFlow 0.11 GPU、CUDA 8)。 Windows 对 TensorFlow 的支持确实是新的(大约一个月内) - 看起来您可能想在他们的问题中提及这一点:https://github.com/tensorflow/tensorflow/issues

【讨论】:

    猜你喜欢
    • 2016-02-28
    • 1970-01-01
    • 1970-01-01
    • 2017-10-12
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多