Tensorflow ValueError:仅使用命名参数调用`sparse_softmax_cross_entropy_with_logits` [英] Tensorflow ValueError: Only call `sparse_softmax_cross_entropy_with_logits` with named arguments

查看:74
本文介绍了Tensorflow ValueError:仅使用命名参数调用`sparse_softmax_cross_entropy_with_logits`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

调用以下方法时:

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

我收到以下ValueError:

I receive the following 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 的文档,我需要确保将登录名和标签初始化为例如:

According to the documentation for nn_ops.py I need to ensure that the logins and labels are initialised to something e.g.:

def _ensure_xent_args(名称,标记,标签,日志):#确保 所有参数都作为命名参数传递.如果哨兵是 不无: 引发ValueError(仅使用< 如果labels为None或logits为None,则为命名参数(labels = ...,logits = ...,...)"%name): 引发ValueError(必须同时提供标签和登录信息.")

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,标签= Y

Logits=X, labels =Y

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

What is the cause here? And am I initialising them to some value such as the loss? Or?

推荐答案

原因是 tf.nn.sparse_softmax_cross_entropy_with_logits _sentinel :

The cause is that the first argument of tf.nn.sparse_softmax_cross_entropy_with_logits is _sentinel:

_sentinel:用于防止位置参数.内部,请勿使用.

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

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

This API encourages you to name your arguments, like this:

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

...以便您不会意外地将logits传递给labels,反之亦然.

... so that you don't accidentally pass logits to labels or vice versa.

这篇关于Tensorflow ValueError:仅使用命名参数调用`sparse_softmax_cross_entropy_with_logits`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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