valid_eval_loader = DataLoader(valid_dataset,batch_size=8,shuffle=False,pin_memory=True,drop_last=True)
pre_valid = inference(model,valid_eval_loader)
predictions = torch.nn.functional.softmax(torch.tensor(pre_valid,dtype=torch.float32), dim=-1)
result = [1 if x > 0.5 else 0 for x in predictions]
predictions输出的形状是2列,报错如下---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
Cell In[59], line 4
2 pre_valid = inference(model,valid_eval_loader)
3 predictions = torch.nn.functional.softmax(torch.tensor(pre_valid,dtype=torch.float32), dim=-1)
----> 4 result = [1 if x > 0.5 else 0 for x in predictions]
Cell In[59], line 4, in <listcomp>(.0)
2 pre_valid = inference(model,valid_eval_loader)
3 predictions = torch.nn.functional.softmax(torch.tensor(pre_valid,dtype=torch.float32), dim=-1)
----> 4 result = [1 if x > 0.5 else 0 for x in predictions]
RuntimeError: Boolean value of Tensor with more than one value is ambiguous
|