Yeah, it’s unrelated to PyTorch, but still interesting as I haven’t seen the issue before.
It doesn’t look like a perfectly inverted image though.
Using your code snippet I get the same image back and inverting it naively via:
plt.imshow(np.array(img)*(-1)+255)

gives