如何在tensorflow对象检测中只检测一个指定的类而不是所有类?

时间:2018-06-09 08:31:04

标签: tensorflow object-detection

我用六个类训练了我的数据集,它可以很好地检测不同的类。是否可以修改对象检测器脚本以仅检测一个指定的类而不是所有六个类?或者我必须从头开始重新训练一个班级的数据集?非常感谢任何推荐。 这是我的对象检测器脚本的绘图部分:

vis_util.visualize_boxes_and_labels_on_image_array(
image,
np.squeeze(boxes),
np.squeeze(classes).astype(np.int32),
np.squeeze(scores),
category_index,
use_normalized_coordinates=True,
line_thickness=1,
agnostic_mode=False,
groundtruth_box_visualization_color='black',
skip_scores=False,
skip_labels=False,
min_score_thresh=0.80)

4 个答案:

答案 0 :(得分:0)

除非您更改代码,否则您将获得所有课程的概率。 Ofc,你可以选择em中最高的一个。有意义吗?

答案 1 :(得分:0)

这可能不是解决此问题的最佳方法,但是您可以尝试制作label_map.pbtxt文件的副本(一个用于更改,一个用于安全保存),然后删除所有标签,但您感兴趣的一个标签,其中之一。

然后,您可以将min_score_thresh降低到0.1左右(或根本不修改此参数),并且仅检测保留在label_map.pbtxt文件中的一个标签。

如果您使用的是GitHub上的对象检测API,则可以在models-master / research / object_detection / data /中找到mscoco_label_map.pbtxt文件(请记住使用文本编辑器将其打开)

答案 2 :(得分:0)

在调用可视化功能之前,添加以下代码-


objectOfInterest = 1  # Interested object class number as per label file 
box = np.asarray(boxes)
cls = np.asarray(classes).astype(np.int32)
scr = np.asarray(scores)
bl = (cls == objectOfInterest) 
classes = np.extract(boolar,cls)
scores = np.extract(boolar,scr)
boxes = np.extract(boolar,box)

答案 3 :(得分:0)

下面 Suman 建议的代码几乎是完美的,但是“boxes”数组需要是一个 4 位置的元组(box 坐标)。要选择特定的类,需要选择匹配的框坐标元组。所以我在 Suman 建议的代码之前添加了一些行。检查下面的代码:

objectOfInterest = 1  # Interested object class number as per label file
box = np.asarray(boxes)
cls = np.asarray(classes).astype(np.int32)
scr = np.asarray(scores)
    
boxes = [] 
for in range(1, len(cls)):    
    if cls[i] == objectOfInterest:
           boxes.append(box[i])
boxes = np.array(boxes)
     
bl = (cls == objectOfInterest)
classes = np.extract(boolar,cls)
scores = np.extract(boolar,scr)