How can generate label_map.pbtxt using python?
I need to generate label_map.pbtxt file automatically by sending object name.
item {
id: 1
name: 'object name'
}
I tried to create that using python functionality but when I start to train a model I get this error:
TypeError: a bytes-like object is required, not 'str'!
from google.protobuf import text_format
with open("obj.pb.txt", "w") as fw:
text_format.PrintMessage(obj, fw)
with open("obj.pb.txt", "r") as fr:
text_format.Parse(fr.read(), obj)
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')
This can generate file that I need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With