prepare_levircd.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/env python
  2. # Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. import os.path as osp
  16. from common import (get_default_parser, add_crop_options, crop_patches,
  17. get_path_tuples, create_file_list, link_dataset)
  18. SUBSETS = ('train', 'val', 'test')
  19. SUBDIRS = ('A', 'B', 'label')
  20. FILE_LIST_PATTERN = "{subset}.txt"
  21. URL = ""
  22. if __name__ == '__main__':
  23. parser = get_default_parser()
  24. parser = add_crop_options(parser)
  25. args = parser.parse_args()
  26. out_dir = osp.join(args.out_dataset_dir,
  27. osp.basename(osp.normpath(args.in_dataset_dir)))
  28. if args.crop_size is not None:
  29. crop_patches(
  30. args.crop_size,
  31. args.crop_stride,
  32. data_dir=args.in_dataset_dir,
  33. out_dir=out_dir,
  34. subsets=SUBSETS,
  35. subdirs=SUBDIRS,
  36. glob_pattern='*.png',
  37. max_workers=0)
  38. else:
  39. link_dataset(args.in_dataset_dir, args.out_dataset_dir)
  40. for subset in SUBSETS:
  41. path_tuples = get_path_tuples(
  42. *(osp.join(out_dir, subset, subdir) for subdir in SUBDIRS),
  43. glob_pattern='**/*.png',
  44. data_dir=args.out_dataset_dir)
  45. file_list = osp.join(
  46. args.out_dataset_dir, FILE_LIST_PATTERN.format(subset=subset))
  47. create_file_list(file_list, path_tuples)
  48. print(f"Write file list to {file_list}.")