gpt4 book ai didi

python - ValueError : Only call `softmax_cross_entropy_with_logits` with named arguments (labels=. .., logits=..., ...)

转载 作者:太空狗 更新时间:2023-10-30 02:38:21 28 4
gpt4 key购买 nike

你能指导如何解决这个问题吗?

with tf.name_scope('loss'):
#cross_entropy = None
val = tf.nn.softmax_cross_entropy_with_logits(y_conv, y_)
cross_entropy = tf.reduce_mean(val)

with tf.name_scope('adam_optimizer'):
#train_step = None
train_step = tf.train.AdamOptimizer(1e-4).minimize(cross_entropy)

我收到这个错误:

---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-40-f67d0aecc114> in <module>()
1 with tf.name_scope('loss'):
2 #cross_entropy = None
----> 3 val = tf.nn.softmax_cross_entropy_with_logits(y_conv, y_)
4 cross_entropy = tf.reduce_mean(val)
5

~/anaconda/lib/python3.6/site-packages/tensorflow/python/ops/nn_ops.py in softmax_cross_entropy_with_logits(_sentinel, labels, logits, dim, name)
1576 """
1577 _ensure_xent_args("softmax_cross_entropy_with_logits", _sentinel,
-> 1578 labels, logits)
1579
1580 # TODO(pcmurray) Raise an error when the labels do not sum to 1. Note: This

~/anaconda/lib/python3.6/site-packages/tensorflow/python/ops/nn_ops.py in _ensure_xent_args(name, sentinel, labels, logits)
1531 if sentinel is not None:
1532 raise ValueError("Only call `%s` with "
-> 1533 "named arguments (labels=..., logits=..., ...)" % name)
1534 if labels is None or logits is None:
1535 raise ValueError("Both labels and logits must be provided.")

ValueError: Only call `softmax_cross_entropy_with_logits` with named arguments (labels=..., logits=..., ...)

此外,tf.__version__ 返回 '1.0.0'我在 OSX Sierra 上安装了 Anaconda Python 3.6.2

最佳答案

这是一个简单的修复:softmax_cross_entropy_with_logits() 具有三个关键参数:_sentinellabelslogits。哨兵必须为空,需要使用命名参数。

已修复(尽管我不确定在这种情况下 y_convy_ 是标签还是 logit,因此您可能需要交换它们):

with tf.name_scope('loss'):
#cross_entropy = None
val = tf.nn.softmax_cross_entropy_with_logits(labels = y_conv, logits=y_)
cross_entropy = tf.reduce_mean(val)

with tf.name_scope('adam_optimizer'):
#train_step = None
train_step = tf.train.AdamOptimizer(1e-4).minimize(cross_entropy)

关于python - ValueError : Only call `softmax_cross_entropy_with_logits` with named arguments (labels=. .., logits=..., ...),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47257002/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com