简体   繁体   English

Tensorflow object 检测 api 得到按边界框坐标排序的预测

[英]Tensorflow object detection api get predictions sorted by bounding box coordinates

I trained a neural network to solve simple captcha using tensorflow object-detection API, but when I output the predictions with the following code:我使用 tensorflow 对象检测 API 训练了一个神经网络来解决简单的验证码,但是当我使用以下代码进行 output 预测时:

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)

I get predictions in random order with every function run.每次运行 function 时,我都会以随机顺序获得预测。 I asked a question earlier, and I was advised to try using the coordinates, but I could not find a way to connect the classes and the coordinates of the box that is associated with this class.我之前问了一个问题,有人建议我尝试使用坐标,但我找不到一种方法来连接与此 class 关联的框的类和坐标。 Example of solved captcha is attached, so I need a way to output predictions in order from left to right.附上已解决的验证码示例,因此我需要一种方法来按从左到右的顺序进行 output 预测。

Image图片

Given that boxes[0] is an array of shape num_boxes * 4, where the first value in the box is xmin, this can get you the indicies of the boxes, sorted by the one with the lowest xmin (the one that starts further left).鉴于boxes[0]是一个形状为 num_boxes * 4 的数组,其中框中的第一个值是 xmin,这可以为您提供框的索引,按 xmin 最低的那个(从更左边开始的那个)排序)。

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

Then you can use these indices to sort the boxes, scores, and classed, as follows:然后您可以使用这些索引对框、分数和分类进行排序,如下所示:

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

If you wanted to, for example, sort by xmax instead, you'd use np.argsort(boxes[0][:,2]) .例如,如果您想按 xmax 排序,则可以使用np.argsort(boxes[0][:,2]) You can play around with using 0-3 to sort by xmin, ymin, xmax, and ymax.您可以使用 0-3 按 xmin、ymin、xmax 和 ymax 进行排序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TensorFlow对象检测API教程中获取bounding box坐标 - Get the bounding box coordinates in the TensorFlow object detection API tutorial 如何使用 Tensorflow 在视频中的 object 检测中获取预测边界框的坐标(甚至中心点) - How to get coordinates(or even center point) of predicted bounding box in object detection in a video using Tensorflow 如何在YOLO物体检测中获取边界框的坐标? - How to get the coordinates of the bounding box in YOLO object detection? 使用 Tensorflow Object 检测 API 在边界框内提取图像 - Extraction of images within a bounding box using Tensorflow Object Detection API 具有多边形边界框的 Tensorflow 对象检测 API 的数据增强 - Data augmentation for Tensorflow Object Detection API with polygon bounding box Tensorflow 对象检测 API - 获取框的坐标 - Tensorflow Object Detection API - Get Coordinates of Boxes 张量流中边界框的坐标 - coordinates of bounding box in tensorflow Tensorflow 对象检测 API 中预测数量的限制 - Limitation of number of predictions in Tensorflow Object Detection API 如何从 YOLOv5 预测中得到 class 和边界框坐标? - How to get class and bounding box coordinates from YOLOv5 predictions? 从边界框获取对象 [对象检测] - Get object from bounding box [Object Detection]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM