3 Star 4 Fork 0

Gitee 极速下载/Syn2Real

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/rajeevyasarla/Syn2Real
克隆/下载
val_data.py 1.88 KB
一键复制 编辑 原始数据 按行查看 历史
rajeevyasarla 提交于 2020-06-09 19:02 . syn2real files
# --- Imports --- #
import torch.utils.data as data
from PIL import Image
from torchvision.transforms import Compose, ToTensor, Normalize
import numpy as np
# --- Validation/test dataset --- #
class ValData(data.Dataset):
def __init__(self, val_data_dir,val_filename):
super().__init__()
val_list = val_data_dir + val_filename
with open(val_list) as f:
contents = f.readlines()
input_names = [i.strip() for i in contents]
gt_names = [i.strip().replace('rain','norain') for i in input_names]
self.input_names = input_names
self.gt_names = gt_names
self.val_data_dir = val_data_dir
def get_images(self, index):
input_name = self.input_names[index]
gt_name = self.gt_names[index]
input_img = Image.open(self.val_data_dir + input_name)
gt_img = Image.open(self.val_data_dir + gt_name)
# Resizing image in the multiple of 16"
wd_new,ht_new = input_img.size
if ht_new>wd_new and ht_new>1024:
wd_new = int(np.ceil(wd_new*1024/ht_new))
ht_new = 1024
elif ht_new<=wd_new and wd_new>1024:
ht_new = int(np.ceil(ht_new*1024/wd_new))
wd_new = 1024
wd_new = int(16*np.ceil(wd_new/16.0))
ht_new = int(16*np.ceil(ht_new/16.0))
input_img = input_img.resize((wd_new,ht_new), Image.ANTIALIAS)
gt_img = gt_img.resize((wd_new, ht_new), Image.ANTIALIAS)
# --- Transform to tensor --- #
transform_input = Compose([ToTensor(), Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])
transform_gt = Compose([ToTensor()])
input_im = transform_input(input_img)
gt = transform_gt(gt_img)
return input_im, gt, input_name
def __getitem__(self, index):
res = self.get_images(index)
return res
def __len__(self):
return len(self.input_names)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/mirrors/Syn2Real.git
[email protected]:mirrors/Syn2Real.git
mirrors
Syn2Real
Syn2Real
master

搜索帮助