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


Python base_dataset.get_transform方法代码示例

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


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

示例1: __init__

# 需要导入模块: from data import base_dataset [as 别名]
# 或者: from data.base_dataset import get_transform [as 别名]
def __init__(self, opt):
        """Initialize this dataset class.

        Parameters:
            opt (Option class) -- stores all the experiment flags; needs to be a subclass of BaseOptions
        """
        BaseDataset.__init__(self, opt)
        self.dir_A = os.path.join(opt.dataroot, opt.phase + 'A')  # create a path '/path/to/data/trainA'
        self.dir_B = os.path.join(opt.dataroot, opt.phase + 'B')  # create a path '/path/to/data/trainB'

        self.A_paths = sorted(make_dataset(self.dir_A, opt.max_dataset_size))   # load images from '/path/to/data/trainA'
        self.B_paths = sorted(make_dataset(self.dir_B, opt.max_dataset_size))    # load images from '/path/to/data/trainB'
        self.A_size = len(self.A_paths)  # get the size of dataset A
        self.B_size = len(self.B_paths)  # get the size of dataset B
        btoA = self.opt.direction == 'BtoA'
        input_nc = self.opt.output_nc if btoA else self.opt.input_nc       # get the number of channels of input image
        output_nc = self.opt.input_nc if btoA else self.opt.output_nc      # get the number of channels of output image
        self.transform_A = get_transform(self.opt, grayscale=(input_nc == 1))
        self.transform_B = get_transform(self.opt, grayscale=(output_nc == 1)) 
开发者ID:Mingtzge,项目名称:2019-CCF-BDCI-OCR-MCZJ-OCR-IdentificationIDElement,代码行数:21,代码来源:unaligned_dataset.py

示例2: __init__

# 需要导入模块: from data import base_dataset [as 别名]
# 或者: from data.base_dataset import get_transform [as 别名]
def __init__(self, opt):
        """Initialize this dataset class.

        Parameters:
            opt (Option class) -- stores all the experiment flags; needs to be a subclass of BaseOptions

        A few things can be done here.
        - save the options (have been done in BaseDataset)
        - get image paths and meta information of the dataset.
        - define the image transformation.
        """
        # save the option and dataset root
        BaseDataset.__init__(self, opt)
        # get the image paths of your dataset;
        self.image_paths = []  # You can call sorted(make_dataset(self.root, opt.max_dataset_size)) to get all the image paths under the directory self.root
        # define the default transform function. You can use <base_dataset.get_transform>; You can also define your custom transform function
        self.transform = get_transform(opt) 
开发者ID:Mingtzge,项目名称:2019-CCF-BDCI-OCR-MCZJ-OCR-IdentificationIDElement,代码行数:19,代码来源:template_dataset.py

示例3: initialize

# 需要导入模块: from data import base_dataset [as 别名]
# 或者: from data.base_dataset import get_transform [as 别名]
def initialize(self, opt):
        self.opt = opt
        self.root = opt.dataroot
        self.dir_A = os.path.join(opt.dataroot, opt.phase + 'A')
        self.dir_B = os.path.join(opt.dataroot, opt.phase + 'B')

        self.A_paths = make_dataset(self.dir_A)
        self.B_paths = make_dataset(self.dir_B)

        self.A_paths = sorted(self.A_paths)
        self.B_paths = sorted(self.B_paths)
        self.A_size = len(self.A_paths)
        self.B_size = len(self.B_paths)
        # self.transform = get_transform(opt)
        transform_list = [transforms.ToTensor(),
                          transforms.Normalize((0.5, 0.5, 0.5),
                                               (0.5, 0.5, 0.5))]
        self.transform = transforms.Compose(transform_list) 
开发者ID:aayushbansal,项目名称:Recycle-GAN,代码行数:20,代码来源:unaligned_triplet_dataset.py

示例4: initialize

# 需要导入模块: from data import base_dataset [as 别名]
# 或者: from data.base_dataset import get_transform [as 别名]
def initialize(self, opt):
		self.opt = opt
		self.root = opt.dataroot
		self.dir_A = os.path.join(opt.dataroot, 'synthia', 'RGB')
		self.dir_B = os.path.join(opt.dataroot, 'cityscapes', 'leftImg8bit')
		self.dir_A_label = os.path.join(opt.dataroot, 'synthia', 'GT', 'parsed_LABELS')
		self.dir_B_label = os.path.join(opt.dataroot, 'cityscapes', 'gtFine')
		
		self.A_paths = make_dataset(self.dir_A)
		self.B_paths = make_dataset(self.dir_B)
		
		self.A_paths = sorted(self.A_paths)
		self.B_paths = sorted(self.B_paths)
		self.A_size = len(self.A_paths)
		self.B_size = len(self.B_paths)
		
		self.A_labels = make_dataset(self.dir_A_label)
		self.B_labels = make_cs_labels(self.dir_B_label)
		
		self.A_labels = sorted(self.A_labels)
		self.B_labels = sorted(self.B_labels)
		
		self.transform = get_transform(opt)
		self.label_transform = get_label_transform(opt) 
开发者ID:Luodian,项目名称:MADAN,代码行数:26,代码来源:synthia_cityscapes.py

示例5: initialize

# 需要导入模块: from data import base_dataset [as 别名]
# 或者: from data.base_dataset import get_transform [as 别名]
def initialize(self, opt):
		self.opt = opt
		self.root = opt.dataroot
		self.dir_A = os.path.join(opt.dataroot, 'gta5', 'images')
		self.dir_B = os.path.join(opt.dataroot, 'cityscapes', 'leftImg8bit')
		self.dir_A_label = os.path.join(opt.dataroot, 'gta5', 'labels')
		self.dir_B_label = os.path.join(opt.dataroot, 'cityscapes', 'gtFine')
		
		self.A_paths = make_dataset(self.dir_A)
		self.B_paths = make_dataset(self.dir_B)
		
		self.A_paths = sorted(self.A_paths)
		self.B_paths = sorted(self.B_paths)
		self.A_size = len(self.A_paths)
		self.B_size = len(self.B_paths)
		
		self.A_labels = make_dataset(self.dir_A_label)
		self.B_labels = make_cs_labels(self.dir_B_label)
		
		self.A_labels = sorted(self.A_labels)
		self.B_labels = sorted(self.B_labels)
		
		self.transform = get_transform(opt)
		self.label_transform = get_label_transform(opt) 
开发者ID:Luodian,项目名称:MADAN,代码行数:26,代码来源:gta5_cityscapes.py

示例6: __getitem__

# 需要导入模块: from data import base_dataset [as 别名]
# 或者: from data.base_dataset import get_transform [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

示例7: __init__

# 需要导入模块: from data import base_dataset [as 别名]
# 或者: from data.base_dataset import get_transform [as 别名]
def __init__(self, opt):
        """Initialize this dataset class.

        Parameters:
            opt (Option class) -- stores all the experiment flags; needs to be a subclass of BaseOptions
        """
        BaseDataset.__init__(self, opt)
        self.A_paths = sorted(make_dataset(opt.dataroot, opt.max_dataset_size))
        input_nc = self.opt.output_nc if self.opt.direction == 'BtoA' else self.opt.input_nc
        self.transform = get_transform(opt, grayscale=(input_nc == 1)) 
开发者ID:Mingtzge,项目名称:2019-CCF-BDCI-OCR-MCZJ-OCR-IdentificationIDElement,代码行数:12,代码来源:single_dataset.py

示例8: __init__

# 需要导入模块: from data import base_dataset [as 别名]
# 或者: from data.base_dataset import get_transform [as 别名]
def __init__(self, opt):
        """Initialize this dataset class.

        Parameters:
            opt (Option class) -- stores all the experiment flags; needs to be a subclass of BaseOptions
        """
        BaseDataset.__init__(self, opt)
        self.dir = os.path.join(opt.dataroot, opt.phase)
        self.AB_paths = sorted(make_dataset(self.dir, opt.max_dataset_size))
        assert(opt.input_nc == 1 and opt.output_nc == 2 and opt.direction == 'AtoB')
        self.transform = get_transform(self.opt, convert=False) 
开发者ID:Mingtzge,项目名称:2019-CCF-BDCI-OCR-MCZJ-OCR-IdentificationIDElement,代码行数:13,代码来源:colorization_dataset.py

示例9: initialize

# 需要导入模块: from data import base_dataset [as 别名]
# 或者: from data.base_dataset import get_transform [as 别名]
def initialize(self, opt):
        self.opt = opt
        self.root = opt.dataroot
        self.dir_A = os.path.join(opt.dataroot, opt.phase + 'A')
        self.dir_B = os.path.join(opt.dataroot, opt.phase + 'B')

        self.A_paths = make_dataset(self.dir_A)
        self.B_paths = make_dataset(self.dir_B)

        self.A_paths = sorted(self.A_paths)
        self.B_paths = sorted(self.B_paths)
        self.A_size = len(self.A_paths)
        self.B_size = len(self.B_paths)
        self.transform = get_transform(opt) 
开发者ID:aayushbansal,项目名称:Recycle-GAN,代码行数:16,代码来源:unaligned_dataset.py

示例10: __init__

# 需要导入模块: from data import base_dataset [as 别名]
# 或者: from data.base_dataset import get_transform [as 别名]
def __init__(self, opt):
        """Initialize this dataset class.

        Parameters:
            opt (Option class) -- stores all the experiment flags; needs to be a subclass of BaseOptions

        A few things can be done here.
        - save the options (have been done in BaseDataset)
        - get image paths and meta information of the dataset.
        - define the image transformation.
        """
        # save the option and dataset root
        BaseDataset.__init__(self, opt)
        # get the image paths of your dataset;
        self.hdf5_path = os.path.join(opt.dataroot, opt.hdf5_filename) 
        self.load_in_mem = opt.load_in_mem
        self.imkey = None
        self.lkey = None
        
        with h5.File(self.hdf5_path,'r') as f:
            key_list = list(f.keys())
            for key in key_list:
                if key == 'data' or key == 'imgs':
                    self.imkey = key
                    self.num_imgs = len(f[self.imkey])
                elif key == 'label' or key == 'labels':
                    self.lkey = key
                else:    
                    raise ValueError('Unkown key in the HDF5 file.')

            # If loading into memory, do so now
            if self.load_in_mem:
                print('Loading %s into memory...' % self.hdf5_path)
                self.data = f[self.imkey][:]
                self.labels = f[self.lkey][:] if (self.lkey is not None) else None

        # define the default transform function. 
        self.transform = get_transform(opt) 
开发者ID:WANG-Chaoyue,项目名称:EvolutionaryGAN-pytorch,代码行数:40,代码来源:hdf5_dataset.py

示例11: __init__

# 需要导入模块: from data import base_dataset [as 别名]
# 或者: from data.base_dataset import get_transform [as 别名]
def __init__(self, opt):
        """Initialize this dataset class.

        Parameters:
            opt (Option class) -- stores all the experiment flags; needs to be a subclass of BaseOptions
        """
        BaseDataset.__init__(self, opt)
        self.A_paths = sorted(make_dataset(opt.dataroot, opt.max_dataset_size))
        self.transform = get_transform(opt, grayscale=(self.opt.input_nc == 1)) 
开发者ID:WANG-Chaoyue,项目名称:EvolutionaryGAN-pytorch,代码行数:11,代码来源:single_dataset.py

示例12: __init__

# 需要导入模块: from data import base_dataset [as 别名]
# 或者: from data.base_dataset import get_transform [as 别名]
def __init__(self, opt):
        """Initialize this dataset class.

        Parameters:
            opt (Option class) -- stores all the experiment flags; needs to be a subclass of BaseOptions

        A few things can be done here.
        - save the options (have been done in BaseDataset)
        - get image paths and meta information of the dataset.
        - define the image transformation.
        """
        # save the option and dataset root
        BaseDataset.__init__(self, opt)
        # define the default transform function. You can use <base_dataset.get_transform>; You can also define your custom transform function
        self.transform = get_transform(opt)
        
        # import torchvision dataset
        if opt.dataset_name == 'CIFAR10':
            from torchvision.datasets import CIFAR10 as torchvisionlib
        elif opt.dataset_name == 'CIFAR100':
            from torchvision.datasets import CIFAR100 as torchvisionlib
        else:
            raise ValueError('torchvision_dataset import fault.')

        self.dataload = torchvisionlib(root = opt.download_root,
                                       transform = self.transform,
                                       download = True) 
开发者ID:WANG-Chaoyue,项目名称:EvolutionaryGAN-pytorch,代码行数:29,代码来源:torchvision_dataset.py

示例13: initialize

# 需要导入模块: from data import base_dataset [as 别名]
# 或者: from data.base_dataset import get_transform [as 别名]
def initialize(self, opt):
        self.opt = opt
        self.root = opt.dataroot
        self.dir_scribbles = os.path.join(opt.dataroot, 'scribbles')  #'pix2pix') #'scribbles' )  #'masks')
        self.dir_images = os.path.join(opt.dataroot, 'images') #os.path.join(opt.dataroot, 'images')

        self.classes = sorted(os.listdir(self.dir_images)) # sorted so that the same order in all cases; check if you've to change this with other models
        self.num_classes = len(self.classes)

        self.scribble_paths = []
        self.images_paths = []
        for cl in self.classes:
            self.scribble_paths.append(sorted( make_dataset( os.path.join( self.dir_scribbles , cl  )  )  ) )
            self.images_paths.append( sorted(  make_dataset( os.path.join( self.dir_images , cl  )  )  ) )

        self.cum_sizes = []
        self.sizes = []
        size =0
        for i in range(self.num_classes):
            size += len(self.scribble_paths[i])
            self.cum_sizes.append(size)
            self.sizes.append(size)

        self.transform = get_transform(opt)
        self.sparse_transform = get_sparse_transform(opt)
        self.mask_transform =  get_mask_transform(opt) 
开发者ID:arnabgho,项目名称:iSketchNFill,代码行数:28,代码来源:labeled_dataset.py

示例14: get_transform

# 需要导入模块: from data import base_dataset [as 别名]
# 或者: from data.base_dataset import get_transform [as 别名]
def get_transform(self):
        return self.transform 
开发者ID:arnabgho,项目名称:iSketchNFill,代码行数:4,代码来源:labeled_dataset.py

示例15: initialize

# 需要导入模块: from data import base_dataset [as 别名]
# 或者: from data.base_dataset import get_transform [as 别名]
def initialize(self, opt):
        self.opt = opt
        self.root = opt.dataroot
        self.dir_A = os.path.join(opt.dataroot)

        self.A_paths = make_dataset(self.dir_A)

        self.A_paths = sorted(self.A_paths)

        self.transform = get_transform(opt) 
开发者ID:arnabgho,项目名称:iSketchNFill,代码行数:12,代码来源:single_dataset.py


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