When I am running below lines for my image classification problem getting error as mentioned :
RuntimeError Traceback (most recent call last)
----> 1 interp.plot_confusion_matrix()
/usr/local/lib/python3.6/dist-packages/fastai/train.py in confusion_matrix(self, slice_size)
155 for i in range(0, self.y_true.shape, slice_size):
156 cm_slice = ((self.pred_class[i:i+slice_size]==x[:,None])
–> 157 & (self.y_true[i:i+slice_size]==x[:,None,None])).sum(2)
158 torch.add(cm, cm_slice, out=cm)
159 return to_np(cm)
RuntimeError: Expected object of scalar type Float but got scalar type Long for argument #2 ‘other’
Good morning, I’m experiencing the same problem, did you find the solution?
Thank you very much
Hi , Even I am seeing the same error , did you find any resolution for this? If yes please share, thanks in advance
nop, I changed the project I was making and now theres no error.
However, dont nkow nothing about what that error is…
Hi, I stumbled sometimes with this error, I don’t know what kind of data set you are trying to plot the CM, but what happened to me was that when I tried to plot CM with a multi-label data set I got this error. I’m not sure that you can have a confusion matrix for multi-label data sets.
I am not using a multi label data set , below is the code I tried, if you dont mind can you please provide any code snippets you tried.
I am using Kaggle competition data for blindness detection [https://www.kaggle.com/c/aptos2019-blindness-detection]
src = (ImageList.from_csv(path, ‘train.csv’, folder=‘train_images’, suffix=’.png’)
data = (src.transform(tfms, size=128)
def accuracy_01(input:Tensor, targs:Tensor)->Rank0Tensor:
“Computes accuracy with
input is bs * n_classes.”
targs = targs.view(-1).long()
n = targs.shape
input = input.argmax(dim=-1).view(n,-1)
targs = targs.view(n,-1)
acc_02 = partial(accuracy_thresh, thresh=0.2)
f_score = partial(fbeta, thresh=0.2)
#learn = cnn_learner(data, arch, metrics=[acc_02, f_score],callback_fns=ShowGraph) . #failing with Conf Mat
#learn = cnn_learner(data, arch, metrics=[error_rate],callback_fns=ShowGraph) . #failing with Conf Mat
#learn = cnn_learner(data, arch, metrics=[accuracy_01]) #,callback_fns=ShowGraph) #failing with training
learn = cnn_learner(data, arch, metrics=[accuracy_thresh]) #failing with training [ ]