match_hashes.py 814 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 match_hash(base_folder):
  7. cfhd = os.path.join(base_folder, "intermediate", "class_file_hashes")
  8. wfhd = os.path.join(base_folder, "intermediate", "write_file_hashes")
  9. class_file_hashes = util.load_obj(cfhd)
  10. write_file_hashes = util.load_obj(wfhd)
  11. class_hash_dict = {}
  12. for i in range(len(class_file_hashes)):
  13. (c, f, h) = class_file_hashes[len(class_file_hashes) - i - 1]
  14. class_hash_dict[h] = (c, f)
  15. write_classes = []
  16. for tup in write_file_hashes:
  17. (w, f, h) = tup
  18. write_classes.append((w, f, class_hash_dict[h][0]))
  19. wwcd = os.path.join(base_folder, "intermediate", "write_with_class")
  20. util.save_obj(write_classes, wwcd)