如何使用python生成label_map.pbtxt?我需要通过发送对象名称来自动生成label_map.pbtxt文件。'''项目{编号:1名称:“对象名称”}'''我尝试使用python功能创建该函数,但是当我开始训练模型时,出现此错误:TypeError:需要一个类似字节的对象,而不是'str'!
def label_map_v1(objname):
with open('/TEST-DS-TO-RECORD/annotations/label_map.pbtxt', 'a') as the_file:
the_file.write('item\n')
the_file.write('{\n')
the_file.write('id :{}'.format(int(1)))
the_file.write('\n')
the_file.write("name :'{0}'".format(str(objname)))
the_file.write('\n')
the_file.write('}\n')
这可以生成我需要的文件。