1.报错信息:TYPEERROR: MAX() RECEIVED AN INVALID COMBINATION OF ARGUMENTS - GOT (AXIS=INT, OUT=NONETYPE, ), BUT EXPECTED ONE OF:
报错代码为:
def f1_overall_1sec(O, T, block_size):
if len(O.shape) == 3:
O, T = utils.reshape_3Dto2D(O), utils.reshape_3Dto2D(T) #[4096, 6]
new_size = int(np.ceil(O.shape[0] / block_size))
O_block = np.zeros((new_size, O.shape[1]))
T_block = np.zeros((new_size, O.shape[1]))
for i in range(0, new_size):
O_block[i, :] = np.max(O[int(i * block_size):int(i * block_size + block_size - 1), ], axis=0) #报错行
T_block[i, :] = np.max(T[int(i * block_size):int(i * block_size + block_size - 1), ], axis=0)
return f1_overall_framewise(O_block, T_block)
我出现该错误的原因是传入的参数O和T是tensor,需要转换为numpy
报错代码行修改为:
O_block[i, :] = np.max(O[int(i * block_size):int(i * block_size + block_size - 1), ].cpu().numpy(), axis=0)
2.报错信息:TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
报错代码行为:
plt.plot(range(nb_epoch), val_loss, label='val loss')
按照报错信息添加.cpu()依然会报错list元素不支持.cpu()
报错代码修改为:
val_loss = torch.tensor(val_loss, device='cpu')
plt.plot(range(nb_epoch), val_loss, label='val loss')
标签:解决办法,val,int,常见,报错,np,block,size
From: https://www.cnblogs.com/fly-smart/p/17529677.html