I had a similar problem in the pascal notebook with pytorch 0.4.1 and I was able to fix it with two changes:
1.) In the function “detn_loss” and “detn_l1” change “F.sigmoid” to “torch.sigmoid” to avoid the errors during learn.lr_find() and learn.fit(). (This is not a problem but the output looks much better.)
2.) The learn.fit() was always throwing an error when calculating the metrics:
Expected object of type torch.LongTensor but found type torch.cuda.LongTensor for argument #2 'other'
This I could fix with copying the accuracy_np function into the notebook and adapting it to this (after the # you see the original version):
def accuracy_np(preds, targs):
preds = np.argmax(preds, 1)
return np.mean(to_np((preds==targs.cpu()))) # (preds==targs).mean()
Here you also see the nice info from the debugger (started with “%debug” in a cell):
> <ipython-input-199-b9616952fd70>(3)accuracy_np()
1 def accuracy_np(preds, targs):
2 preds = np.argmax(preds, 1)
----> 3 return np.mean(to_np((preds==targs))) # (preds==targs).mean()
ipdb> p preds
tensor([14, 17, 2, 14, 14, 6, 13, 8, 2, 9, 15, 6, 17, 7, 12, 0, 14, 14,
7, 19, 1, 14, 14, 13, 14, 14, 14, 6, 9, 18, 13, 0, 2, 6, 18, 11,
14, 6, 0, 10, 6, 13, 12, 14, 3, 13, 14, 7, 14, 13, 9, 14, 13, 2,
14, 11, 6, 0, 2, 2, 2, 14, 14, 9])
ipdb> p targs
tensor([14, 17, 2, 14, 14, 5, 13, 10, 2, 9, 15, 6, 8, 7, 12, 0, 14, 14,
7, 19, 1, 14, 14, 13, 14, 14, 14, 5, 9, 18, 13, 0, 2, 6, 18, 11,
14, 3, 0, 10, 6, 13, 12, 14, 3, 13, 14, 7, 12, 13, 9, 14, 1, 2,
14, 11, 6, 0, 2, 2, 2, 17, 14, 9], device='cuda:0')
ipdb> p preds==targs
*** RuntimeError: Expected object of type torch.LongTensor but found type torch.cuda.LongTensor for argument #2 'other'
ipdb> p preds==targs.cpu()
tensor([1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1], dtype=torch.uint8)
ipdb> p to_np(preds==targs.cpu())
array([1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,
1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1], dtype=uint8)
ipdb> p np.mean(to_np((preds==targs.cpu())))
0.875
ipdb> q
Maybe the debugging overview helps somebody not familiar with it.
Best regards
Michael