PolarisFTL commited on
Commit
9b2a343
·
verified ·
1 Parent(s): 4c1b58e

Update data/single_dataset.py

Browse files
Files changed (1) hide show
  1. data/single_dataset.py +14 -8
data/single_dataset.py CHANGED
@@ -16,19 +16,25 @@ class SingleDataset(BaseDataset):
16
  opt (Option class) -- stores all the experiment flags; needs to be a subclass of BaseOptions
17
  """
18
  BaseDataset.__init__(self, opt)
19
-
20
- self.A_path = opt.image_path # Assume 'image_path' is a new option for single image input
21
-
22
  input_nc = self.opt.output_nc if self.opt.direction == 'BtoA' else self.opt.input_nc
23
  self.transform = get_transform(opt, grayscale=(input_nc == 1))
24
 
25
  def __getitem__(self, index):
26
- """Return a data point and its metadata information."""
27
- A_img = Image.open(self.A_path).convert('RGB')
 
 
 
 
 
 
 
 
 
28
  A = self.transform(A_img)
29
- return {'A': A, 'A_paths': self.A_path}
30
 
31
  def __len__(self):
32
  """Return the total number of images in the dataset."""
33
- return 1 # Always 1 for single image input
34
-
 
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)