Can’t use learn.get_preds() OR learn.TTA() with contrastive loss

Using the following pipeline,, I am unable to run learn.get_preds() or learn.TTA(). I get the following error:

TypeError: expected Tensor as element 0 in argument 0, but got list

1 Like

Try to use debugger to see what validate(model, dl, cb_handler=cb_handler, pbar=pbar, average=False, n_batch=n_batch) contains, you should get a better idea of what’s happening. To do that, run the cell so that the error happens, then run %debug in another cell. You can then use python debugger. If you are not familiar with pdb, here is a nice tutorial.
I am not sure it is a problem with your loss, as it returns a tensor, but probably with your model, which returns 2 elements. get_preds then calls on a list of list instead of a list of tensors, which doesn’t work. If it is indeed the problem, you can either merge your outputs into one tensor (which would require you to change a bunch of things in the process), or change the way get_preds work (or just code your own function and forget about it totally).