please help me with this code.Icouldnt find the tuple object in my code
mahsa14775 opened this issue · comments
the code is:
# switch to evaluate mode
model.eval()
for i, (inp, target) in enumerate(test_loader):
target = target.cuda()
gt = torch.cat((gt, target), 0)
bs, n_crops, c, h, w = inp.size()
input_var = torch.autograd.Variable(inp.view(-1, c, h, w).cuda(), volatile=True)
output = model(input_var)
output_mean = output.view(bs, n_crops, -1).mean(1)
pred = torch.cat((pred, output_mean.data), 0)
AUROCs = compute_AUCs(gt, pred)
AUROC_avg = np.array(AUROCs).mean()
print('The average AUROC is {AUROC_avg:.3f}'.format(AUROC_avg=AUROC_avg))
There is a problem with your test loader or test dataset, you need to be more specific about how you designed it
My guess since it indicates that the transform operation is tuple is that you wanted to apply several transforms to your images and gave a tuple of transforms as argument instead of a proper transform. To apply multiple transform, you nood to use the transform composition : https://pytorch.org/docs/stable/torchvision/transforms.html#torchvision.transforms.Compose
Thanks for your answerI have another question:I want use auc in Jupiter The code is:
```python
# switch to evaluate mode
with torch.no_grad():
model.eval()
for i, (inp, target) in enumerate(test_loader):
target = target.cuda()
gt = torch.cat((gt, target), 0)
bs, n_crops, c, h, w = inp.size()
input_var = torch.autograd.Variable(inp.view(-1, c, h, w).cuda(), volatile=True)
output = model(input_var)
output_mean = output.view(bs, n_crops, -1).mean(1)
pred = torch.cat((pred, output_mean.data), 0)
AUROCs = compute_AUCs(gt, pred)
AUROC_avg = np.array(AUROCs).mean()
print('The average AUROC is {AUROC_avg:.3f}'.format(AUROC_avg=AUROC_avg))
for i in range(N_CLASSES):
print('The AUROC of {} is {}'.format(CLASS_NAMES[i], AUROCs[i]))
```
but the error is:
```python
NameError Traceback (most recent call last)<ipython-input-132-7cf96a50adda> in <module> 12 pred = torch.cat((pred, output_mean.data), 0) 13 ---> 14 AUROCs = compute_AUCs(gt, pred) 15 AUROC_avg = np.array(AUROCs).mean() 16 print('The average AUROC is {AUROC_avg:.3f}'.format(AUROC_avg=AUROC_avg)) NameError: name 'compute_AUCs' is not defined
```
What should I do?Could you please help me ASAP ?
the error is pretty straight forward here, the function compute_AUCs
is not defined. If you defined somewhere else, you need to import it