python - tf.nn.sigmoid_cross_entropy_with_logits 公司关于文档中的参数

标签 python python-2.7 machine-learning tensorflow deep-learning

所以我有以下模型,我想用它来测试一个想法。我对tf.nn.sigmoid_cross_entropy_with_logits()特别感兴趣因为我的标签并不相互排斥。

import tensorflow as tf

from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets('MNIST_data', one_hot=True)

x  = tf.placeholder(tf.float32, shape=[None, 784])
y_ = tf.placeholder(tf.float32, shape=[None, 10])

w1 = tf.get_variable("w1", shape=[784, 512], initializer=tf.contrib.layers.xavier_initializer())
b1 = tf.Variable(tf.zeros([512], dtype=tf.float32))
w2 = tf.Variable(tf.zeros([512, 10], dtype=tf.float32))
b2 = tf.Variable(tf.zeros([10], dtype=tf.float32))

h = tf.nn.relu(tf.matmul(x, w1) + b1)
y = tf.matmul(h, w2) + b2

cross_entropy = tf.nn.sigmoid_cross_entropy_with_logits(labels=y_, logits=y)
train_step = tf.train.AdamOptimizer().minimize(cross_entropy)

with tf.Session() as sess:

    sess.run(tf.initialize_all_variables())
    start = time.time()

    for i in range(20000):
        batch = mnist.train.next_batch(50)
        train_step.run(feed_dict={x: batch[0], y_: batch[1]})

但是,我反复收到以下错误,这似乎与 tensorflow 文档相矛盾。

Traceback (most recent call last):
File "mnist_test.py", line 19, in <module>
cross_entropy = tf.nn.sigmoid_cross_entropy_with_logits(labels=y_, logits=y)
TypeError: sigmoid_cross_entropy_with_logits() got an unexpected keyword argument 'labels'

请帮忙!!

最佳答案

关键字参数labels only exists在 TensorFlow 1.0.0 及更高版本中。我猜你使用的是 0.12 或更低版本。使用 pip freezeprint('TensorFlow version: {0}'.format(tf.__version__)) 检查。


以前版本的文档可以在 https://www.tensorflow.org/versions/ 找到

要在以前版本的文档中搜索一些信息,您可以使用:https://www.google.com/search?q=site:https://www.tensorflow.org/versions/r0.12+sigmoid_cross_entropy_with_logits()

关于python - tf.nn.sigmoid_cross_entropy_with_logits 公司关于文档中的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42675391/

相关文章:

带有 sqlalchemy 的 Python Pandas |批量插入错误

machine-learning - Affdex Emotion SDK - 即使跟踪面部,在某些头部角度下指标仍为零

r - 使用连续变量的决策树

Python:除了以数字开头的字符串之外,是否有单行脚本来标题大小写字符串?

python - 我如何有两个字段可供选择?

python - Theano中变量的形状有什么区别

python - 是否可以在给定百分位数而不是原始输入的情况下绘制 matplotlib 箱线图?

python - Pandas :时间序列数据:如何选择一小时或一天或一分钟的行?

python - 字母数字字符串的正则表达式,下划线不应是第一个或最后一个字符

machine-learning - 图像中的 Logo 识别