group_by_writer.py 708 B

12345678910111213141516171819202122232425
  1. """
  2. These codes are adopted from LEAF with some modifications.
  3. """
  4. import os
  5. from easyfl.datasets.utils import util
  6. def group_by_writer(base_folder):
  7. wwcd = os.path.join(base_folder, "intermediate", "write_with_class")
  8. write_class = util.load_obj(wwcd)
  9. writers = [] # each entry is a (writer, [list of (file, class)]) tuple
  10. cimages = []
  11. (cw, _, _) = write_class[0]
  12. for (w, f, c) in write_class:
  13. if w != cw:
  14. writers.append((cw, cimages))
  15. cw = w
  16. cimages = [(f, c)]
  17. cimages.append((f, c))
  18. writers.append((cw, cimages))
  19. ibwd = os.path.join(base_folder, "intermediate", "images_by_writer")
  20. util.save_obj(writers, ibwd)