本文整理汇总了Python中data.util.augment方法的典型用法代码示例。如果您正苦于以下问题:Python util.augment方法的具体用法?Python util.augment怎么用?Python util.augment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类data.util
的用法示例。
在下文中一共展示了util.augment方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __getitem__
# 需要导入模块: from data import util [as 别名]
# 或者: from data.util import augment [as 别名]
def __getitem__(self, index):
if self.opt['data_type'] == 'lmdb':
if self.LR_env is None:
self._init_lmdb()
LR_size = self.LR_size
# get real kernel map
real_ker_map = self.real_ker_map_list[index].float()
# get LR image
LR_path = self.LR_paths[index]
if self.opt['data_type'] == 'lmdb':
resolution = [int(s) for s in self.LR_sizes[index].split('_')]
else:
resolution = None
img_LR = util.read_img(self.LR_env, LR_path, resolution)
H, W, C = img_LR.shape
if self.opt['phase'] == 'train':
#randomly crop
rnd_h = random.randint(0, max(0, H - LR_size))
rnd_w = random.randint(0, max(0, W - LR_size))
img_LR = img_LR[rnd_h:rnd_h + LR_size, rnd_w:rnd_w + LR_size, :]
# augmentation - flip, rotate
img_LR = util.augment(img_LR, self.opt['use_flip'], self.opt['use_rot'], self.opt['mode'])
# change color space if necessary
if self.opt['color']:
img_LR = util.channel_convert(C, self.opt['color'], [img_LR])[0]
# BGR to RGB, HWC to CHW, numpy to tensor
if img_LR.shape[2] == 3:
img_LR = img_LR[:, :, [2, 1, 0]]
img_LR = torch.from_numpy(np.ascontiguousarray(np.transpose(img_LR, (2, 0, 1)))).float()
return {'LQ': img_LR, 'LQ_path': LR_path, 'real_ker': real_ker_map}
示例2: __getitem__
# 需要导入模块: from data import util [as 别名]
# 或者: from data.util import augment [as 别名]
def __getitem__(self, index):
if self.opt['data_type'] == 'lmdb':
if self.LR_env is None:
self._init_lmdb()
LR_size = self.LR_size
# get LR image, kernel map
LR_path = self.LR_paths[index]
ker_map = self.ker_maps[index]
if self.opt['data_type'] == 'lmdb':
resolution = [int(s) for s in self.LR_sizes[index].split('_')]
else:
resolution = None
img_LR = util.read_img(self.LR_env, LR_path, resolution)
H, W, C = img_LR.shape
if self.opt['phase'] == 'train':
#randomly crop
rnd_h = random.randint(0, max(0, H - LR_size))
rnd_w = random.randint(0, max(0, W - LR_size))
img_LR = img_LR[rnd_h:rnd_h + LR_size, rnd_w:rnd_w + LR_size, :]
# augmentation - flip, rotate
img_LR = util.augment(img_LR, self.opt['use_flip'], self.opt['use_rot'], self.opt['mode'])
# change color space if necessary
if self.opt['color']:
img_LR = util.channel_convert(C, self.opt['color'], [img_LR])[0]
# BGR to RGB, HWC to CHW, numpy to tensor
if img_LR.shape[2] == 3:
img_LR = img_LR[:, :, [2, 1, 0]]
img_LR = torch.from_numpy(np.ascontiguousarray(np.transpose(img_LR, (2, 0, 1)))).float()
return {'LQ': img_LR, 'ker': ker_map, 'LQ_path': LR_path}
示例3: __getitem__
# 需要导入模块: from data import util [as 别名]
# 或者: from data.util import augment [as 别名]
def __getitem__(self, index):
if self.opt['data_type'] == 'lmdb':
if self.LR_env is None:
self._init_lmdb()
LR_size = self.LR_size
SR_size = self.SR_size
scale = self.opt['scale']
# get real kernel map
real_ker_map = self.real_ker_map_list[index]
# get each kernel map
ker_map = self.ker_map_list[index]
# get LR image
LR_path = self.LR_paths[index]
if self.opt['data_type'] == 'lmdb':
resolution = [int(s) for s in self.LR_sizes[index].split('_')]
else:
resolution = None
img_LR = util.read_img(self.LR_env, LR_path, resolution)
H, W, C = img_LR.shape
#get SR image
img_SR = self.SR_img_list[index]
if self.opt['phase'] == 'train':
#randomly crop
rnd_h = random.randint(0, max(0, H - LR_size))
rnd_w = random.randint(0, max(0, W - LR_size))
rnd_h_SR, rnd_w_SR = int(rnd_h * scale), int(rnd_w * scale)
img_SR = img_SR[rnd_h_SR:rnd_h_SR + SR_size, rnd_w_SR:rnd_w_SR + SR_size, :]
# augmentation - flip, rotate
img_SR = util.augment(img_SR, self.opt['use_flip'], self.opt['use_rot'], self.opt['mode'])
# change color space if necessary
if self.opt['color']:
img_SR = util.channel_convert(C, self.opt['color'], [img_SR])[0]
# BGR to RGB, HWC to CHW, numpy to tensor
if img_SR.shape[2] == 3:
img_SR = img_SR[:, :, [2, 1, 0]]
img_SR = torch.from_numpy(np.ascontiguousarray(np.transpose(img_SR, (2, 0, 1)))).float()
return {'SR': img_SR, 'real_ker': real_ker_map, 'ker': ker_map}