错误提示:
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]去掉即可!