4

所以我有以下模型,我想测试一个想法。我对tf.nn.sigmoid_cross_entropy_with_logits()特别感兴趣,因为我的标签不是互斥的。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]}) 

但是,我重复出现以下错误,这似乎与张量流文档相矛盾。

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' 

请帮忙!!

回答

3

TensorFlow 1.0.0及更高版本中的关键字参数labelsonly exists。我猜你正在使用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()

+0

有人能提供一个链接到老的张量流程文件?我无法在他们的网站上找到它。 –

+0

@JoshuaHoward添加到答案 –