本文整理汇总了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)
示例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)
示例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)
示例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)
示例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)
示例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))
示例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)
示例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)
示例14: get_transform
# 需要导入模块: from data import base_dataset [as 别名]
# 或者: from data.base_dataset import get_transform [as 别名]
def get_transform(self):
return self.transform
示例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)