本文整理汇总了Python中data.base_dataset.normalize方法的典型用法代码示例。如果您正苦于以下问题:Python base_dataset.normalize方法的具体用法?Python base_dataset.normalize怎么用?Python base_dataset.normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类data.base_dataset
的用法示例。
在下文中一共展示了base_dataset.normalize方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: preprocess_inputs
# 需要导入模块: from data import base_dataset [as 别名]
# 或者: from data.base_dataset import normalize [as 别名]
def preprocess_inputs(self, raw_inputs, params):
outputs = dict()
# label & inst.
transform_label = get_transform_fn(self.opt, params, method=Image.NEAREST, normalize=False)
outputs['label'] = transform_label(raw_inputs['label']) * 255.0
outputs['inst'] = transform_label(raw_inputs['inst'])
if self.opt.dataloader == 'sun_rgbd' or self.opt.dataloader == 'ade20k': # NOTE(sh): dirty exception!
outputs['inst'] *= 255.0
outputs['label_path'] = raw_inputs['label_path']
outputs['inst_path'] = raw_inputs['inst_path']
# image
if self.load_image:
transform_image = get_transform_fn(self.opt, params)
outputs['image'] = transform_image(raw_inputs['image'])
outputs['image_path'] = raw_inputs['image_path']
# raw inputs
if self.load_raw:
transform_raw = get_raw_transform_fn(normalize=False)
outputs['label_raw'] = transform_raw(raw_inputs['label']) * 255.0
outputs['inst_raw'] = transform_raw(raw_inputs['inst'])
transform_image_raw = get_raw_transform_fn()
outputs['image_raw'] = transform_image_raw(raw_inputs['image'])
return outputs
示例2: __getitem__
# 需要导入模块: from data import base_dataset [as 别名]
# 或者: from data.base_dataset import normalize [as 别名]
def __getitem__(self, index):
### input A (label maps)
A_path = self.A_paths[index]
A = Image.open(A_path)
params = get_params(self.opt, A.size)
if self.opt.label_nc == 0:
transform_A = get_transform(self.opt, params)
A_tensor = transform_A(A.convert('RGB'))
else:
transform_A = get_transform(self.opt, params, method=Image.NEAREST, normalize=False)
A_tensor = transform_A(A) * 255.0
B_tensor = inst_tensor = feat_tensor = 0
### input B (real images)
if self.opt.isTrain:
B_path = self.B_paths[index]
B = Image.open(B_path).convert('RGB')
transform_B = get_transform(self.opt, params)
B_tensor = transform_B(B)
### if using instance maps
if not self.opt.no_instance:
inst_path = self.inst_paths[index]
inst = Image.open(inst_path)
inst_tensor = transform_A(inst)
if self.opt.load_features:
feat_path = self.feat_paths[index]
feat = Image.open(feat_path).convert('RGB')
norm = normalize()
feat_tensor = norm(transform_A(feat))
input_dict = {'label': A_tensor, 'inst': inst_tensor, 'image': B_tensor,
'feat': feat_tensor, 'path': A_path}
return input_dict
示例3: __getitem__
# 需要导入模块: from data import base_dataset [as 别名]
# 或者: from data.base_dataset import normalize [as 别名]
def __getitem__(self, index):
### input A (label maps)
A_path = self.A_paths[index]
A = Image.open(A_path)
params = get_params(self.opt, A.size)
if self.opt.label_nc == 0:
transform_A = get_transform(self.opt, params)
A_tensor = transform_A(A.convert('RGB'))
else:
transform_A = get_transform(self.opt, params, method=Image.NEAREST, normalize=False)
A_tensor = transform_A(A) * 255.0
B_tensor = inst_tensor = feat_tensor = 0
### input B (real images)
if self.opt.isTrain or self.opt.use_encoded_image:
B_path = self.B_paths[index]
B = Image.open(B_path).convert('RGB')
transform_B = get_transform(self.opt, params)
B_tensor = transform_B(B)
### if using instance maps
if not self.opt.no_instance:
inst_path = self.inst_paths[index]
inst = Image.open(inst_path)
inst_tensor = transform_A(inst)
if self.opt.load_features:
feat_path = self.feat_paths[index]
feat = Image.open(feat_path).convert('RGB')
norm = normalize()
feat_tensor = norm(transform_A(feat))
input_dict = {'label': A_tensor, 'inst': inst_tensor, 'image': B_tensor,
'feat': feat_tensor, 'path': A_path}
return input_dict
示例4: preprocess_cropping
# 需要导入模块: from data import base_dataset [as 别名]
# 或者: from data.base_dataset import normalize [as 别名]
def preprocess_cropping(self, raw_inputs, outputs, params):
transform_obj = get_transform_fn(
self.opt, params, method=Image.NEAREST, normalize=False, is_context=False)
label_obj = transform_obj(raw_inputs['label']) * 255.0
input_bbox = np.array(params['bbox_in_context'])
bbox_cls = params['bbox_cls']
bbox_cls = bbox_cls if bbox_cls is not None else self.opt.label_nc-1
mask_object_inst = (outputs['inst']==params['bbox_inst_id']).float() \
if not (params['bbox_inst_id'] == None) else torch.zeros(outputs['inst'].size())
### generate output bbox
img_size = outputs['label'].size(1) #shape[1]
context_ratio = np.random.uniform(
low=self.config['min_ctx_ratio'], high=self.config['max_ctx_ratio'])
output_bbox = np.array(get_soft_bbox(input_bbox, img_size, img_size, context_ratio))
mask_in, mask_object_in, mask_context_in = get_masked_image(
outputs['label'], input_bbox, bbox_cls)
mask_out, mask_object_out, _ = get_masked_image(
outputs['label'], output_bbox)
# Build dictionary
outputs['input_bbox'] = torch.from_numpy(input_bbox)
outputs['output_bbox'] = torch.from_numpy(output_bbox)
outputs['mask_in'] = mask_in # (1x1xHxW)
outputs['mask_object_in'] = mask_object_in # (1xCxHxW)
outputs['mask_context_in'] = mask_context_in # (1xCxHxW)
outputs['mask_out'] = mask_out # (1x1xHxW)
outputs['mask_object_out'] = mask_object_out # (1xCxHxW)
outputs['label_obj'] = label_obj
outputs['mask_object_inst'] = mask_object_inst
outputs['cls'] = torch.LongTensor([bbox_cls])
return outputs
示例5: __getitem__
# 需要导入模块: from data import base_dataset [as 别名]
# 或者: from data.base_dataset import normalize [as 别名]
def __getitem__(self, index):
### input A (label maps)
if index > self.dataset_size - self.clip_length:
index = 0 # it's a rare chance and won't be effecting training dynamics
A_path = self.A_paths[index: index + self.clip_length]
A = [Image.open(path) for path in A_path]
params = get_params(self.opt, A[0].size)
if self.opt.label_nc == 0:
transform_A = get_transform(self.opt, params)
A_tensor = [transform_A(item.convert('RGB')) for item in A]
A_tensor = torch.stack(A_tensor, dim=0)
else:
transform_A = get_transform(self.opt, params, method=Image.NEAREST, normalize=False)
A_tensor = transform_A(A) * 255.0
B_tensor = inst_tensor = feat_tensor = 0
### input B (real images)
if self.opt.isTrain:
B_path = self.B_paths[index: index + self.clip_length]
B = [Image.open(path).convert('RGB') for path in B_path]
transform_B = get_transform(self.opt, params)
B_tensor = [transform_B(item) for item in B]
B_tensor = torch.stack(B_tensor, dim=0)
else: # only retain first frame for testing
B_path = self.B_paths[index]
B = Image.open(B_path).convert('RGB')
transform_B = get_transform(self.opt, params)
B_tensor = transform_B(B)
### if using instance maps (which is never supposed to)
if not self.opt.no_instance:
inst_path = self.inst_paths[index: index + self.clip_length]
inst = [Image.open(path) for path in inst_path]
inst_tensor = [transform_A(item) for item in inst]
inst_tensor = torch.stack(inst_tensor, dim=0)
if self.opt.load_features:
feat_path = self.feat_paths[index: index + self.clip_length]
feat = [Image.open(path).convert('RGB') for path in feat_path]
norm = normalize()
feat_tensor = [norm(transform_A(item)) for item in feat]
feat_tensor = torch.stack(feat_tensor, dim=0)
input_dict = {'label': A_tensor, 'inst': inst_tensor, 'image': B_tensor,
'feat': feat_tensor, 'path': A_path}
return input_dict
示例6: __getitem__
# 需要导入模块: from data import base_dataset [as 别名]
# 或者: from data.base_dataset import normalize [as 别名]
def __getitem__(self, index):
### input A (label maps)
A_path = self.A_paths[index]
A_tensor = torch.load(A_path).permute((2,0,1))
# A = Image.open(A_path)
# params = get_params(self.opt, A.size)
# if self.opt.label_nc == 0:
# transform_A = get_transform(self.opt, params)
# A_tensor = transform_A(A.convert('RGB'))
# else:
# transform_A = get_transform(self.opt, params, method=Image.NEAREST, normalize=False)
# A_tensor = transform_A(A) * 255.0
B_tensor = inst_tensor = feat_tensor = 0
### input B (real images)
if self.opt.isTrain:
B_path = self.B_paths[index]
B = Image.open(B_path).convert('RGB')
# transform_B = get_transform(self.opt, params)
# B_tensor = transform_B(B)
B = np.array(B, dtype = float) / 255.
B_tensor = torch.tensor(B)[:,:,:3].permute((2,0,1)).float()
# fig = plt.figure(1)
# ax = fig.add_subplot(111)
# ax.imshow(B_tensor[:,:1024,:].permute((1,2,0)))
# plt.show()
### if using instance maps
if not self.opt.no_instance:
inst_path = self.inst_paths[index]
inst = Image.open(inst_path)
inst_tensor = transform_A(inst)
if self.opt.load_features:
feat_path = self.feat_paths[index]
feat = Image.open(feat_path).convert('RGB')
norm = normalize()
feat_tensor = norm(transform_A(feat))
input_dict = {'label': A_tensor, 'inst': inst_tensor, 'image': B_tensor,
'feat': feat_tensor, 'path': A_path}
return input_dict
示例7: __getitem__
# 需要导入模块: from data import base_dataset [as 别名]
# 或者: from data.base_dataset import normalize [as 别名]
def __getitem__(self, index):
### input A (label maps)
lpath = self.label_paths[index]
A_tensor_0 = torch.load(lpath).permute((2,0,1)).float()
idx_ = lpath.split('/')[-1][:12]
spath = self.opt.input_image_root + '%s_synthesized_image.jpg'%idx_
A = Image.open(spath).convert('RGB')
A = np.array(A, dtype = float) / 255.
A = A[:,:,:3]
idx = lpath.split('/')[-1].split('.')[0]
minx, maxx, miny, maxy = list(self.crop_coor[int(idx), :])
A = A[minx: maxx + 1, miny: maxy + 1, :]
A = cv2.resize(A, (128, 128))
A_tensor_1 = torch.tensor(A).permute((2,0,1)).float()
A_tensor = torch.cat((A_tensor_0, A_tensor_1), dim = 0)
B_tensor = inst_tensor = feat_tensor = 0
lidx = lpath.split('/')[-1][:12]
sidx = spath.split('/')[-1][:12]
### input B (real images)
if self.opt.isTrain:
B_path = self.rimage_paths[index]
B = Image.open(B_path).convert('RGB')
B = np.array(B, dtype = float) / 255.
B_tensor = torch.tensor(B)[:,:,:3].permute((2,0,1)).float()
# fig = plt.figure(1)
# ax = fig.add_subplot(111)
# ax.imshow(B_tensor[:,:1024,:].permute((1,2,0)))
# plt.show()
ridx = B_path.split('/')[-1][:12]
assert lidx == ridx , "Wrong match"
### if using instance maps
if not self.opt.no_instance:
inst_path = self.inst_paths[index]
inst = Image.open(inst_path)
inst_tensor = transform_A(inst)
if self.opt.load_features:
feat_path = self.feat_paths[index]
feat = Image.open(feat_path).convert('RGB')
norm = normalize()
feat_tensor = norm(transform_A(feat))
# print(lpath, spath, B_path)
# print(lidx, sidx )
assert lidx == sidx , "Wrong match"
# fig = plt.figure(1)
# ax = fig.add_subplot(111)
# ax.imshow(A)
# plt.show()
input_dict = {'label': A_tensor, 'inst': inst_tensor, 'image': B_tensor,
'feat': feat_tensor, 'path': lpath}
return input_dict
示例8: work
# 需要导入模块: from data import base_dataset [as 别名]
# 或者: from data.base_dataset import normalize [as 别名]
def work(self, index):
### input A (label maps)
A_path = self.A_paths[index]
A_tensor = torch.load(A_path).permute((2,0,1))
# A = Image.open(A_path)
# params = get_params(self.opt, A.size)
# if self.opt.label_nc == 0:
# transform_A = get_transform(self.opt, params)
# A_tensor = transform_A(A.convert('RGB'))
# else:
# transform_A = get_transform(self.opt, params, method=Image.NEAREST, normalize=False)
# A_tensor = transform_A(A) * 255.0
B_tensor = inst_tensor = feat_tensor = 0
### input B (real images)
if self.opt.isTrain:
B_path = self.B_paths[index]
B = Image.open(B_path).convert('RGB')
# transform_B = get_transform(self.opt, params)
# B_tensor = transform_B(B)
B = np.array(B, dtype = float) / 255.
B_tensor = torch.tensor(B)[:,:,:3].permute((2,0,1)).float()
# fig = plt.figure(1)
# ax = fig.add_subplot(111)
# ax.imshow(B_tensor[:,:1024,:].permute((1,2,0)))
# plt.show()
### if using instance maps
if not self.opt.no_instance:
inst_path = self.inst_paths[index]
inst = Image.open(inst_path)
inst_tensor = transform_A(inst)
if self.opt.load_features:
feat_path = self.feat_paths[index]
feat = Image.open(feat_path).convert('RGB')
norm = normalize()
feat_tensor = norm(transform_A(feat))
input_dict = {'label': A_tensor, 'inst': inst_tensor, 'image': B_tensor,
'feat': feat_tensor, 'path': A_path}
return input_dict