有关异常图像生成的问题
houruixiang-1024 opened this issue · 2 comments
houruixiang-1024 commented
cnulab commented
你好!
train_loader中的image经过了normalize,要想还原为可保存的图像需要以下步骤:
from PIL import Image
for data in train_loader:
image = data['image'][0]
image = image.permute(1,2,0) * torch.from_numpy(np.array([[0.229, 0.224, 0.225]])) + torch.from_numpy(np.array([[[0.485, 0.456, 0.406]]]))
image = image * 255
Image.fromarray( image.cpu().numpy().astype(np.uint8)).save('image_name.jpg')
houruixiang-1024 commented
感谢您的回复!😀