tenorflow-ValueError: вызывать только `sparse_softmax_cross_entropy_with_logits` - PullRequest
0 голосов
/ 27 февраля 2020

Этот код написан на основе старой версии 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

1 Ответ

0 голосов
/ 28 февраля 2020

заменить 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')

Это потому, что метод ожидает, что переданные параметры будут названы.

...