我使用自定义代码使用网络摄像头实时识别对象,但在创建标签的过程中出现了此错误,我使用的是 python 3.7 和 TensorFlow 1.15,这是错误的,有一种更简单的方法使用实时物体识别?
标签图:
labels = [
{'name':'1DIG', 'id':1},
{'name':'2DIG', 'id':2},
{'name':'3DIG', 'id':3},
{'name':'4DIG', 'id':4},
]
with open(ANNOTATION_PATH + '\label_map.pbtxt', 'w') as f:
for label in labels:
f.write('item { \n')
f.write('\tname:\'{}\'\n'.format(label['name']))
f.write('\tid:{}\n'.format(label['id']))
f.write('}\n')
tf 记录的代码:
!python {SCRIPTS_PATH + '/generate_tfrecord.py'} -x {IMAGE_PATH + '/train'} -l {ANNOTATION_PATH + '/label_map.pbtxt'} -o {ANNOTATION_PATH + '/train.record'}
!python {SCRIPTS_PATH + '/generate_tfrecord.py'} -x{IMAGE_PATH + '/test'} -l {ANNOTATION_PATH + '/label_map.pbtxt'} -o {ANNOTATION_PATH + '/test.record'}
错误:
Traceback (most recent call last):
File "Tensorflow/scripts/generate_tfrecord.py", line 62, in <module>
label_map_dict = label_map_util.get_label_map_dict(label_map)
File "C:\Users\Gabriel\AppData\Local\Programs\Python\Python37\lib\site-packages\object_detection\utils\label_map_util.py", line 164, in get_label_map_dict
label_map = load_labelmap(label_map_path)
File "C:\Users\Gabriel\AppData\Local\Programs\Python\Python37\lib\site-packages\object_detection\utils\label_map_util.py", line 133, in load_labelmap
label_map_string = fid.read()
File "C:\Users\Gabriel\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\lib\io\file_io.py", line 122, in read
self._preread_check()
File "C:\Users\Gabriel\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\lib\io\file_io.py", line 84, in _preread_check
compat.as_bytes(self.__name), 1024 * 512)
File "C:\Users\Gabriel\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\util\compat.py", line 71, in as_bytes
(bytes_or_text,))
TypeError: Expected binary or unicode string, got item {
name: "1DIG"
id: 1
}
item {
name: "2DIG"
id: 2
}
item {
name: "3DIG"
id: 3
}
item {
name: "4DIG"
id: 4
}
最佳答案
我在另一个链接中找到了答案:
TypeError: Expected binary or unicode string, got item error
您可能还需要检查 xml_df.to_csv
位置
关于python - 类型错误 : Expected binary or unicode string, 得到了项目 {,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65208475/