tensorflow-ValueError:仅调用`sparse_softmax_cross_entropy_with_logits`

问题描述 投票:0回答:1

This code是基于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.gz
Extracting MNIST_data/train-labels-idx1-ubyte.gz
Extracting MNIST_data/t10k-images-idx3-ubyte.gz
Extracting MNIST_data/t10k-labels-idx1-ubyte.gz
Traceback (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
python tensorflow machine-learning logistic-regression mnist
1个回答
0
投票

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')

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

© www.soinside.com 2019 - 2024. All rights reserved.