【问题标题】:Get Class Label in Faster -RCNN with gluoncv使用 gluoncv 在 Faster -RCNN 中获取类标签
【发布时间】:2020-04-09 12:53:32
【问题描述】:

我正在尝试使用 gluoncv 中的 Faster-RCNN 实现来计算图像中的车辆数量,如here 所示。我想获取图像的字符串标签。例如,在下图中,字符串标签将是“总线”。我怎样才能得到它?

An image of a 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()

【问题讨论】:

    标签: python python-3.x faster-rcnn


    【解决方案1】:

    这样的事情怎么样?

    # 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]
    

    【讨论】:

      猜你喜欢
      • 2016-09-26
      • 2020-12-24
      • 1970-01-01
      • 2018-06-14
      • 2020-06-17
      • 2018-01-09
      • 1970-01-01
      • 2019-11-06
      • 2018-11-24
      相关资源
      最近更新 更多