【问题标题】:Tensorflow object detection api get predictions sorted by bounding box coordinatesTensorflow 对象检测 api 获取按边界框坐标排序的预测
【发布时间】:2020-05-19 12:43:55
【问题描述】:

我使用 tensorflow 对象检测 API 训练了一个神经网络来解决简单的验证码,但是当我使用以下代码输出预测时:

for index, value in enumerate(classes[0]):
object_dict = {}
if scores[0, index] > threshold:
    object_dict[(category_index.get(value)).get('name').encode('utf8')] = scores[0, index]
    objects.append(object_dict)

每个函数运行时,我都会以随机顺序获得预测。我之前问过一个问题,有人建议我尝试使用坐标,但是我找不到连接类和与该类关联的框的坐标的方法。附上已解决的验证码示例,因此我需要一种从左到右的顺序输出预测的方法。

Image

【问题讨论】:

    标签: python tensorflow computer-vision captcha object-detection-api


    【解决方案1】:

    鉴于boxes[0] 是一个形状为 num_boxes * 4 的数组,其中框中的第一个值是 xmin,这可以让您得到框的索引,按 xmin 最低的那个(开始的那个更左)。

    indices = np.argsort(boxes[0][:,0])
    

    然后就可以使用这些索引对boxes、scores、classed进行排序了,如下:

    sorted_scores = scores[0][indices]
    sorted_boxes = boxes[0][indices]
    sorted_classes = classes[0] indicies
    

    例如,如果您想按 xmax 排序,则可以使用 np.argsort(boxes[0][:,2])。 您可以尝试使用 0-3 按 xmin、ymin、xmax 和 ymax 排序。

    【讨论】:

    猜你喜欢
    • 2018-08-01
    • 2019-10-11
    • 2020-06-23
    • 2019-09-30
    • 2019-09-18
    • 2018-04-17
    • 2019-04-22
    • 2021-06-16
    • 2020-04-03
    相关资源
    最近更新 更多