我正在使用tensorflow的对象检测api来检测对象。我训练模型及其工作正常,但我想将被检测对象的名称作为字符串。有人可以帮我吗?
API提供了一个名为object_detection_tutorial.ipynb的教程文件,在此文件中,函数run_inference_for_single_image
返回包含密钥output_dict
的检测字典detection_classes
,这对应于您在label_map.pbtxt文件中定义的id。此外,在此文件变量中,category_index
是存储为字典的标签映射。因此,只需要获取检测到的所有对象的字符串名称,只需添加:
string_name = [category_index[i] for i in output_dict['detection_classes']]
在教程中这行output_dict = run_inference_for_single_image(image_np, detection_graph)
之后。