张量流错误:"logits and labels must be same size",暖春风"tutorial"



我目前正在学习本教程,在由于张量流更新而进行了一些更改后,我收到了此错误:

tensorflow.python.framework.errors_impl。无效参数错误:日志和标签的大小必须相同:logits_size=[399360,2] labels_size=[409920,2] [[Node: SoftmaxCrossEntropyWithLogits = SoftmaxCrossEntropyWithLogits[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"](Reshape_2, Reshape_3(]]。

谁能帮我解决这个问题?

代码中的更改:

#Replaced concat_dim=2 with axis=2
combined_mask = tf.concat(axis=2, values=[bit_mask_class, bit_mask_background])
#Update the import of urllib2 to urllib3
#Replace tf.pack with tf.stack
upsampled_logits_shape = tf.stack([
downsampled_logits_shape[0],
downsampled_logits_shape[1] * upsample_factor,
downsampled_logits_shape[2] * upsample_factor,
downsampled_logits_shape[3]])

引发此错误的原因是,当您向函数提供带有409920标签时,399360了logit的数量。该函数tf.nn.softmax_cross_entropy_with_logits期望每个 logit 有一个标签,并且它会崩溃,因为您提供的标签多于 logit。

至于为什么会发生这种情况,您应该发布您对代码所做的更改。

相关内容

最新更新