Are you working on a segmentation use case?
If so, then t_image.nelement would return the number of pixels in the input batch including the color channels, which might be wrong.
Also, are you using an older PyTorch version, as you are still using Variables?
If that’s the case, check if (predicted==t_image).sum() might be overflowing, as this was an issue in old PyTorch versions (pre 1.0, if I’m not mistaken).