load_label_png.py 905 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/env python
  2. from __future__ import print_function
  3. import os.path as osp
  4. import numpy as np
  5. import PIL.Image
  6. here = osp.dirname(osp.abspath(__file__))
  7. def main():
  8. label_png = osp.join(here, 'apc2016_obj3_json/label.png')
  9. print('Loading:', label_png)
  10. print()
  11. lbl = np.asarray(PIL.Image.open(label_png))
  12. labels = np.unique(lbl)
  13. label_names_txt = osp.join(here, 'apc2016_obj3_json/label_names.txt')
  14. label_names = [name.strip() for name in open(label_names_txt)]
  15. print('# of labels:', len(labels))
  16. print('# of label_names:', len(label_names))
  17. if len(labels) != len(label_names):
  18. print('Number of unique labels and label_names must be same.')
  19. quit(1)
  20. print()
  21. print('label: label_name')
  22. for label, label_name in zip(labels, label_names):
  23. print('%d: %s' % (label, label_name))
  24. if __name__ == '__main__':
  25. main()