MCPcopy Create free account
hub / github.com/JunlinHan/DCLGAN / SingleDataset

Class SingleDataset

data/single_dataset.py:6–40  ·  view source on GitHub ↗

This dataset class can load a set of images specified by the path --dataroot /path/to/data. It can be used for generating CycleGAN results only for one side with the model option '-model test'.

Source from the content-addressed store, hash-verified

4
5
6class SingleDataset(BaseDataset):
7 """This dataset class can load a set of images specified by the path --dataroot /path/to/data.
8
9 It can be used for generating CycleGAN results only for one side with the model option '-model test'.
10 """
11
12 def __init__(self, opt):
13 """Initialize this dataset class.
14
15 Parameters:
16 opt (Option class) -- stores all the experiment flags; needs to be a subclass of BaseOptions
17 """
18 BaseDataset.__init__(self, opt)
19 self.A_paths = sorted(make_dataset(opt.dataroot, opt.max_dataset_size))
20 input_nc = self.opt.output_nc if self.opt.direction == 'BtoA' else self.opt.input_nc
21 self.transform = get_transform(opt, grayscale=(input_nc == 1))
22
23 def __getitem__(self, index):
24 """Return a data point and its metadata information.
25
26 Parameters:
27 index - - a random integer for data indexing
28
29 Returns a dictionary that contains A and A_paths
30 A(tensor) - - an image in one domain
31 A_paths(str) - - the path of the image
32 """
33 A_path = self.A_paths[index]
34 A_img = Image.open(A_path).convert('RGB')
35 A = self.transform(A_img)
36 return {'A': A, 'A_paths': A_path}
37
38 def __len__(self):
39 """Return the total number of images in the dataset."""
40 return len(self.A_paths)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected