Add grayscale downsampling option

This commit is contained in:
James Betker 2020-05-29 20:34:00 -06:00
parent b123ed8a45
commit 74b313aaa9

View File

@ -5,7 +5,7 @@ import lmdb
import torch import torch
import torch.utils.data as data import torch.utils.data as data
import data.util as util import data.util as util
from PIL import Image from PIL import Image, ImageOps
from io import BytesIO from io import BytesIO
import torchvision.transforms.functional as F import torchvision.transforms.functional as F
@ -180,6 +180,9 @@ class LQGTDataset(data.Dataset):
corruption_buffer.seek(0) corruption_buffer.seek(0)
img_LQ = Image.open(corruption_buffer) img_LQ = Image.open(corruption_buffer)
if self.opt['grayscale']:
img_LQ = ImageOps.grayscale(img_LQ)
img_GT = torch.from_numpy(np.ascontiguousarray(np.transpose(img_GT, (2, 0, 1)))).float() img_GT = torch.from_numpy(np.ascontiguousarray(np.transpose(img_GT, (2, 0, 1)))).float()
img_PIX = torch.from_numpy(np.ascontiguousarray(np.transpose(img_PIX, (2, 0, 1)))).float() img_PIX = torch.from_numpy(np.ascontiguousarray(np.transpose(img_PIX, (2, 0, 1)))).float()
img_LQ = F.to_tensor(img_LQ) img_LQ = F.to_tensor(img_LQ)