我想从 Tensorflow 对象检测 api 获取标签并将它们放入数组中,而不是在视频上显示它们
这是 detector_object 函数
def detect_objects(image_np, sess, detection_graph):
# Expand dimensions since the model expects images to have shape: [1, None, None, 3]
image_np_expanded = np.expand_dims(image_np, axis=0)
image_tensor = detection_graph.get_tensor_by_name('image_tensor:0')
# Each box represents a part of the image where a particular object was detected.
boxes = detection_graph.get_tensor_by_name('detection_boxes:0')
# Each score represent how level of confidence for each of the objects.
# Score is shown on the result image, together with the class label.
scores = detection_graph.get_tensor_by_name('detection_scores:0')
classes = detection_graph.get_tensor_by_name('detection_classes:0')
num_detections = detection_graph.get_tensor_by_name('num_detections:0')
# Actual detection.
(boxes, scores, classes, num_detections) = sess.run(
[boxes, scores, classes, num_detections],
feed_dict={image_tensor: image_np_expanded})
# Visualization of the results of a detection.
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)
return image_np
最佳答案
经过一番研究,这就是我的想法
final_score = np.squeeze(scores)
count = 0
for i in range(100):
if scores is None or final_score[i] > 0.5:
count = count + 1
print('cpunt',count)
printcount =0;
for i in classes[0]:
printcount = printcount +1
print(category_index[i]['name'])
if(printcount == count):
break
这将打印所有检测到的对象,如果你想返回它,你可以将它添加到某个变量并返回。
如果您只想打印检测到的对象,请在 util 文件夹内的 Visualization_utils.py 文件中添加 print(class_name)
if not agnostic_mode:
if classes[i] in category_index.keys():
class_name = category_index[classes[i]]['name']
**print(class_name)** --> this line
else:
关于python - Tensorflow对象检测api获取数组中的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50077353/