Are you dealing with some gray images (single channel), while others are RGB  (3 channels)?
Based on the error message, it seems mean and std contain three values (for each channel), while the tensor seems to be a single channel tensor.
If that’s the case, you could load the images as color images (PIL will repeat the single channel) using img = img.convert("RGB").