gpt4 book ai didi

python - tensorflow 值错误: Only call `sparse_softmax_cross_entropy_with_logits` with named arguments

转载 作者:太空宇宙 更新时间:2023-11-03 14:21:36 26 4
gpt4 key购买 nike

调用以下方法时:

losses = [tf.nn.sparse_softmax_cross_entropy_with_logits(logits, labels)
for logits, labels in zip(logits_series,labels_series)]

我收到以下 ValueError:

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

反对这一点:

[tf.nn.sparse_softmax_cross_entropy_with_logits(logits, labels)

根据 nn_ops.py 的文档,我需要确保登录名和标签已初始化为以下内容:

def _ensure_xent_args(name, sentinel, labels, logits): # Make sure that all arguments were passed as named arguments. if sentinel is not None: raise ValueError("Only call %s with " "named arguments (labels=..., logits=..., ...)" % name) if labels is None or logits is None: raise ValueError("Both labels and logits must be provided.")

Logits=X, labels =Y

这是什么原因呢?我是否将它们初始化为某个值,例如损失?或者?

最佳答案

原因是 tf.nn.sparse_softmax_cross_entropy_with_logits 的第一个参数是_sentinel:

_sentinel: Used to prevent positional parameters. Internal, do not use.

此 API 鼓励您命名您的参数,如下所示:

tf.nn.sparse_softmax_cross_entropy_with_logits(logits=logits, labels=labels)

...这样您就不会意外地将 logits 传递给 labels,反之亦然。

关于python - tensorflow 值错误: Only call `sparse_softmax_cross_entropy_with_logits` with named arguments,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47909606/

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