python:labelmap変換

labelmap変換

クラスリストをlabelmapファイルに変換するためのpythonスクリプト

classList2Labelmap.py
path_class = 'class.list'
 
print('Reading '+path_class )
with open(path_class) as f_class:
    l = [s.strip() for s in f_class.readlines()]
    print(l)
print('Done')
 
print('Converting class file to labelmap file:')
with open('labelmap.txt', mode='w') as f:
    count = 0
    for name in l:
        f.write('item {\n')
 
        if count == 0:
            f.write('  name: "none_of_the_above"\n')
            f.write('  label: 0\n')
            f.write('  display_name: "background"\n')
            f.write('}\n')
        else:
            f.write('  name: "'+l[count-1]+'"\n')
            f.write('  label: '+ str(count)+'\n')
            f.write('  display_name: "'+l[count-1]+'"\n')
            f.write('}\n')
        count = count + 1
 
print('Saved labelmap file: labelmap.ptorotxt')
  • /home/users/2/lolipop.jp-4404d470cd64c603/web/ws/data/pages/python/labelmap変換.txt
  • 最終更新: 2018/10/02 23:07
  • by baba