Tensorflow对象检测API:输出概率低于50%的检测框

我指的是Tensorflow对象检测API (https://github.com/tensorflow/models/tree/master/research/object_detection):这是我使用的检测代码的IPython笔记本 (https://github.com/tensorflow/models/blob/master/research/object_detection/object_detection_tutorial.ipynb)。在这个文件中,输出值设置为在概率大于50%时绘制检测框。检测代码如下:

with detection_graph.as_default():  with tf.Session(graph=detection_graph) as sess:    # 定义检测图的输入和输出张量    image_tensor = detection_graph.get_tensor_by_name('image_tensor:0')    # 每个框代表图像中检测到的特定对象的一部分。    detection_boxes = detection_graph.get_tensor_by_name('detection_boxes:0')    # 每个分数表示每个对象的置信度水平。    # 分数显示在结果图像上,与类别标签一起。    detection_scores = detection_graph.get_tensor_by_name('detection_scores:0')    detection_classes = detection_graph.get_tensor_by_name('detection_classes:0')    num_detections = detection_graph.get_tensor_by_name('num_detections:0')    #myFile = open('example2.csv', 'w')    i=0    #boxeslist=[]    new_boxes = []    for image_path in TEST_IMAGE_PATHS:      image = Image.open(image_path)      # 图像的数组表示将在稍后用于准备带有框和标签的结果图像。      image_np = load_image_into_numpy_array(image)      # 扩展维度,因为模型期望图像具有形状:[1, None, None, 3]      image_np_expanded = np.expand_dims(image_np, axis=0)      # 实际检测。      (boxes, scores, classes, num) = sess.run(          [detection_boxes, detection_scores, detection_classes, num_detections],          feed_dict={image_tensor: image_np_expanded})      # 可视化检测结果。      vis_util.visualize_boxes_and_labels_on_image_array(          image_np,          np.squeeze(boxes),          np.squeeze(classes).astype(np.int32),          np.squeeze(scores),          category_index,          use_normalized_coordinates=True,          line_thickness=8)      plt.figure(figsize=IMAGE_SIZE)      plt.imshow(image_np)

如何修改代码以便在概率大于10%时输出对象周围的检测框?


回答:

应该很简单。

正如你所见,这个教程调用了函数’vis_util.visualize_boxes_and_labels_on_image_array’,其参数是:

imageboxesclassesscorescategory_indexuse_normalized_coordinatesline_thickness

如果你在文件’research/object_detection/utils/visualization_utils.py’中搜索,可以找到这个函数,并看到还有其他可以设置的参数。

其中你可以找到:min_score_thresh,其默认值设置为.5

如果你设置:

min_score_thresh=.1

应该能得到你想要的结果。

请注意,因为这可能会显示出更多的检测框。

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注