クラスリストをlabelmapファイルに変換するためのpythonスクリプト
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')