The error is most likely raised by matplotlib in plt.imshow, which expects an image array in the shape [height, width, channels] or [height, width], while you seem to pass a single channel image array containing the batch dimension to this call.
Remove the batch dimension e.g. via tensor.squeeze(0).