关于文档中参数的tf.nn.sigmoid_cross_entropy_with_logits公司 [英] tf.nn.sigmoid_cross_entropy_with_logits companies about arguments from documentation

查看:112
本文介绍了关于文档中参数的tf.nn.sigmoid_cross_entropy_with_logits公司的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我想使用以下模型来测试一个想法.我对 tf.nn.sigmoid_cross_entropy_with_logits()特别感兴趣标签不是互斥的.

So I have the following model that I am wanting to test out an idea with. I am particularly interested in tf.nn.sigmoid_cross_entropy_with_logits() because my labels are not mutually exclusive.

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]})

但是,我反复遇到以下错误,这似乎与张量流文档矛盾.

However, I am getting the following error repeatedly, which seems to be contradicting the tensor flow documentation.

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

The keyword argument labels only exists in TensorFlow 1.0.0 and above. I guess you're using 0.12 or below. Use pip freeze or print('TensorFlow version: {0}'.format(tf.__version__)) to check.

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

The documentation for prior versions can be found at https://www.tensorflow.org/versions/

要在先前版本的文档中搜索某些信息,可以使用:

To search for some information in the documentation of a previous version you can use: https://www.google.com/search?q=site:https://www.tensorflow.org/versions/r0.12+sigmoid_cross_entropy_with_logits()

这篇关于关于文档中参数的tf.nn.sigmoid_cross_entropy_with_logits公司的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆