Python 计算损失时出现值错误

Python 计算损失时出现值错误,python,tensorflow,conv-neural-network,Python,Tensorflow,Conv Neural Network,我在运行模型时遇到此值错误: ValueError: Can not squeeze dim[1], expected a dimension of 1, got 18000 for 'sparse_softmax_cross_entropy_loss/remove_squeezable_dimensions/Squeeze' (op: 'Squeeze') with input shapes: [?,18000]. 触发错误的位置是: logits = model(image, traini

我在运行模型时遇到此值错误:

ValueError: Can not squeeze dim[1], expected a dimension of 1, got 18000 for 'sparse_softmax_cross_entropy_loss/remove_squeezable_dimensions/Squeeze' (op: 'Squeeze') with input shapes: [?,18000].
触发错误的位置是:

logits = model(image, training=True)
loss = tf.losses.sparse_softmax_cross_entropy(labels=labels, logits=logits)
accuracy = tf.metrics.accuracy(
    labels=labels, predictions=tf.argmax(logits, axis=1))

调用sparse_softmax_交叉熵函数时会出现错误。我使用的图片的尺寸是(50、120、3)。关于如何解决这个问题,有什么线索吗?

你读过类似的文章吗?我读过,但我读不出最终的解决方案:/@MohanRadhakrishnantry:cross\u entropy=tf.nn.sparse\u softmax\u cross\u entropy\u with\u logits(labels=labels,logits=logits);损失=tf。减少平均值(交叉熵)。告诉我这是否有帮助。登录和标签的尺寸是多少?图像的尺寸在这里是不相关的。好的,我现在收到的错误是:ValueError:Rank dismatch:Rank of label(接收到的2)的秩应该等于logits的秩减1(接收到的2)@Vlad