Some “torchvision.transforms.functional” transformations such as “TF.rotate” and “TF.resize” break the image when the image is in RGBA format, as you can see:
The blue channel before the rotation is left, and after it in the right, everything in where the alpha channel is black was also made black in the blue channel.
Reproduction code:
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
import torchvision.transforms.functional as TF
img = Image.open(r'C:\your\folder\test.png')
plt.imshow(np.asarray(img)[:,:,2:3].squeeze(), cmap='gray'); plt.show()
img = TF.rotate(img, 30) # or img = TF.resize(img, (512, 512))
plt.imshow(np.asarray(img)[:,:,2:3].squeeze(), cmap='gray'); plt.show()
Test image: