深度学习:view size is not compatible with input tensor‘s size and stride (at least one dimension spans a

错误提示:

view size is not compatible with input tensor's size and stride (at least one dimension spans across two contiguous subspaces). Use .reshape(...) instead.

错误代码:

prec1 = accuracy(-1 * dist_xt_ct.data, target_targets, topk=(1,))[0].item()

正确代码:

prec1 = accuracy(-1 * dist_xt_ct.data, target_targets, topk=(1,)).item()

将[0]去掉即可!

Guess you like

Origin blog.csdn.net/weixin_44575717/article/details/124119167