我想使用Tensorflow对象检测API(以及预先训练的模型“ ssd_mobilenet_v1_coco_2017_11_17 / frozen_inference_graph.pb”)仅在给定图片中检测人(上面有人,猫,自行车等)。我应该如何修改以下代码?也许我应该修改此行detection_graph.get_tensor_by_name('detection_classes:0')
,但是我不知道该怎么做。请帮我我的朋友们!先感谢您。否则某些参考也将很棒。
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
答案 0 :(得分:1)
如果我对它的理解正确,则必须知道人的类别标签,然后才能在可视化检测结果的部分中为该类别进行选择。假设可以对classes
和boxes
进行切片。