报错 :RuntimeError: view size is not compatible with input tensor’s size and stride
f1_score = f1_score(punc.view(-1).detach().cpu().numpy(),
RuntimeError: view size is not compatible with input tensor's size and stride (at least one dimension spans across two contiguous subspaces). Use .reshape(...) instead.
原因是:
view操作要求tensor的内存连续存储,所以在view前面需要先使用contiguous来返回一个contiguous copy;
将 f1_score = f1_score(punc.view(-1).detach().cpu().numpy(),修改为:
f1_score = f1_score(punc.contiguous().view(-1).detach().cpu().numpy()