这段代码 是基于旧版本的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')
这是因为该方法期望传递的参数是命名的。