python - 使用 gluoncv 在 Faster -RCNN 中获取类标签
问题描述
我正在尝试使用 gluoncv 中的 Faster-RCNN 实现来计算图像中的车辆数量,如下所示。我想获取图像的字符串标签。例如,在下图中,字符串标签将为“bus”。我怎么才能得到它?
以下是我的实现。
import os
import glob
from matplotlib import pyplot as plt
from gluoncv import model_zoo, data, utils
vehiclesum1 = []
for filename in glob.glob('/home/xx/PythonCode/test/*.jpg'):
x, orig_img = data.transforms.presets.rcnn.load_test(filename)
box_ids, scores, bboxes = net(x)
ax = utils.viz.plot_bbox(orig_img, bboxes[0], scores[0], box_ids[0], class_names=net.classes)
# I want to identify this label1
vehiclesum1.append(label1.count('car') + label1.count('truck') + label1.count('motorcycle') + label1.count('bus'))
plt.show()
解决方案
这样的事情怎么样?
# map class ID to classes
id2string = [i:name for i, name in enumerate(net.classes)]
# filter on score.
thresh = 0.8
top_classIDs = [c for c, s in zip(box_ids[0], scores[0]) if s > thresh]
# convert IDs to class names into "label1"
label1 = [id2string[c] for c in top_classIDs]
推荐阅读
- prometheus - 如何使用 prometheus-am-executor 运行 shell 脚本
- visual-studio-2012 - Visual Studio Online 上的 MSBUILD 错误
- chisel - 如何在凿子中打印 f 或 println UInt?
- java - Java Rest Service 工作了一段时间,然后由于 jpa-Hibernate 的多个根本原因而开始失败
- python - 为什么不能在 Python 中删除 LinkedList 中的头元素?
- javascript - 打开图层压扁的瓷砖,直到页面放大
- airflow - 如果未触发某些直接上游,则气流运行任务
- c# - Azure Functions - Microsoft.AspNetCore.Server.Kestrel.Core:请求正文太大
- powerbi-embedded - PowerBI 中的划分
- python-3.x - PYQT:TableWidget:替换“nan”单元格