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

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

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