tensorflow-ValueError: 只能使用命名参数调用`sparse_softmax_cross_entropy_with_logits`

这段代码 是基于旧版本的TensorFlow编写的。我试图运行它。然而,由于TensorFlow版本的原因,它出现了错误。我收到了以下错误信息。

据我所知,我无法安装旧版本的OpenCV。

我该如何解决这个问题?

/home/user/PycharmProjects/untitled/venv/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:458: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.  _np_qint8 = np.dtype([("qint8", np.int8, 1)])/home/user/PycharmProjects/untitled/venv/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:459: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])/home/user/PycharmProjects/untitled/venv/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:460: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.  _np_qint16 = np.dtype([("qint16", np.int16, 1)])/home/user/PycharmProjects/untitled/venv/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:461: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])/home/user/PycharmProjects/untitled/venv/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:462: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.  _np_qint32 = np.dtype([("qint32", np.int32, 1)])/home/user/PycharmProjects/untitled/venv/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:465: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.  np_resource = np.dtype([("resource", np.ubyte, 1)])Extracting MNIST_data/train-images-idx3-ubyte.gzExtracting MNIST_data/train-labels-idx1-ubyte.gzExtracting MNIST_data/t10k-images-idx3-ubyte.gzExtracting MNIST_data/t10k-labels-idx1-ubyte.gzTraceback (most recent call last):  File "/home/user/Videos/Chapter-three/2 - MNIST Logistic Regression L2 Regularization.py", line 63, in <module>    labels, loss_op = loss(logits)  File "/home/user/Videos/Chapter-three/2 - MNIST Logistic Regression L2 Regularization.py", line 38, in loss    logits, tf.argmax(batch_labels, dimension=1), name='xentropy')  File "/home/user/PycharmProjects/untitled/venv/lib/python3.6/site-packages/tensorflow/python/ops/nn_ops.py", line 1661, in sparse_softmax_cross_entropy_with_logits    labels, logits)  File "/home/user/PycharmProjects/untitled/venv/lib/python3.6/site-packages/tensorflow/python/ops/nn_ops.py", line 1510, in _ensure_xent_args    "named arguments (labels=..., logits=..., ...)" % name)ValueError: Only call `sparse_softmax_cross_entropy_with_logits` with named arguments (labels=..., logits=..., ...)Process finished with exit code 1

回答:

cross_entropy = tf.nn.sparse_softmax_cross_entropy_with_logits( logits, tf.argmax(batch_labels, dimension=1), name='xentropy') 替换为 cross_entropy = tf.nn.sparse_softmax_cross_entropy_with_logits( logits=logits, labels=tf.argmax(batch_labels, dimension=1), name='xentropy')

这是因为该方法期望传递的参数是命名的。

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注