utils.py 519 B

12345678910111213141516171819202122232425262728293031
  1. import csv
  2. import os
  3. def get_abs_path(rel_path):
  4. """
  5. Get absolute path
  6. Args:
  7. rel_path: relative path to this file
  8. Returns absolute path
  9. """
  10. return os.path.dirname(os.path.abspath(__file__)) + '/' + rel_path
  11. def load_labels(abs_path):
  12. """
  13. loads relative path file as dictionary
  14. Args:
  15. abs_path: absolute path
  16. Returns dictionary of mappings
  17. """
  18. label_tsv = open(abs_path)
  19. labels = list(csv.reader(label_tsv, delimiter="\t"))
  20. return labels