当前位置: 首页>>代码示例>>Python>>正文


Python base_dataset.get_params方法代码示例

本文整理汇总了Python中data.base_dataset.get_params方法的典型用法代码示例。如果您正苦于以下问题:Python base_dataset.get_params方法的具体用法?Python base_dataset.get_params怎么用?Python base_dataset.get_params使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在data.base_dataset的用法示例。


在下文中一共展示了base_dataset.get_params方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __getitem__

# 需要导入模块: from data import base_dataset [as 别名]
# 或者: from data.base_dataset import get_params [as 别名]
def __getitem__(self, index):
        """Return a data point and its metadata information.

        Parameters:
            index - - a random integer for data indexing

        Returns a dictionary that contains A, B, A_paths and B_paths
            A (tensor) - - an image in the input domain
            B (tensor) - - its corresponding image in the target domain
            A_paths (str) - - image paths
            B_paths (str) - - image paths (same as A_paths)
        """
        # read a image given a random integer index
        AB_path = self.AB_paths[index]
        AB = Image.open(AB_path).convert('RGB')
        # split AB image into A and B
        w, h = AB.size
        w2 = int(w / 2)
        if self.opt.add_contrast:
            ## 增加亮度和对比度
            AB = transforms.ColorJitter(contrast=0.1, brightness=0.1)(AB)

        A = AB.crop((0, 0, w2, h))
        B = AB.crop((w2, 0, w, h))

        # apply the same transform to both A and B
        transform_params = get_params(self.opt, A.size)
        A_transform = get_transform(self.opt, transform_params, grayscale=(self.input_nc == 1))
        B_transform = get_transform(self.opt, transform_params, grayscale=(self.output_nc == 1))

        A = A_transform(A)
        B = B_transform(B)

        return {'A': A, 'B': B, 'A_paths': AB_path, 'B_paths': AB_path} 
开发者ID:Mingtzge,项目名称:2019-CCF-BDCI-OCR-MCZJ-OCR-IdentificationIDElement,代码行数:36,代码来源:aligned_dataset.py

示例2: __getitem__

# 需要导入模块: from data import base_dataset [as 别名]
# 或者: from data.base_dataset import get_params [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 
开发者ID:Lotayou,项目名称:everybody_dance_now_pytorch,代码行数:38,代码来源:aligned_dataset.py

示例3: __getitem__

# 需要导入模块: from data import base_dataset [as 别名]
# 或者: from data.base_dataset import get_params [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 
开发者ID:thomasjhuang,项目名称:deep-learning-for-document-dewarping,代码行数:38,代码来源:aligned_dataset.py

示例4: __getitem__

# 需要导入模块: from data import base_dataset [as 别名]
# 或者: from data.base_dataset import get_params [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 
开发者ID:Lotayou,项目名称:everybody_dance_now_pytorch,代码行数:50,代码来源:aligned_pair_dataset.py

示例5: __getitem__

# 需要导入模块: from data import base_dataset [as 别名]
# 或者: from data.base_dataset import get_params [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 
开发者ID:Kuzphi,项目名称:EverybodyDanceNow-Temporal-FaceGAN,代码行数:46,代码来源:aligned_dataset.py

示例6: work

# 需要导入模块: from data import base_dataset [as 别名]
# 或者: from data.base_dataset import get_params [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 
开发者ID:Kuzphi,项目名称:EverybodyDanceNow-Temporal-FaceGAN,代码行数:46,代码来源:aligned_dataset_temporal.py


注:本文中的data.base_dataset.get_params方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。