I think it is because the data is in form of Tensor. Meanwhile you doing processing with python math library. My solution is you must convert it to numpy first or you just using Tensor operation in pytorch Tensor Operation 11 . If you want to just calculate using python function you can cast it as numpy array. It is so simple, you can just doing preds.data.numpy() . I also found that your tensor is in GPU so don’t forget to copy it to GPU, so you can use preds.data.cpu().numpy(). Here is the example in figure for clearer.