paired_dataset.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from .builder import DATASETS
  15. from .base_dataset import BaseDataset
  16. @DATASETS.register()
  17. class PairedDataset(BaseDataset):
  18. """A dataset class for paired image dataset.
  19. """
  20. def __init__(self, dataroot, preprocess):
  21. """Initialize this dataset class.
  22. Args:
  23. dataroot (str): Directory of dataset.
  24. preprocess (list[dict]): A sequence of data preprocess config.
  25. """
  26. super(PairedDataset, self).__init__(preprocess)
  27. self.dataroot = dataroot
  28. self.data_infos = self.prepare_data_infos()
  29. def prepare_data_infos(self):
  30. """Load paired image paths.
  31. Returns:
  32. list[dict]: List that contains paired image paths.
  33. """
  34. data_infos = []
  35. pair_paths = sorted(self.scan_folder(self.dataroot))
  36. for pair_path in pair_paths:
  37. data_infos.append(dict(pair_path=pair_path))
  38. return data_infos