guorui
guorui

Reputation: 891

How to detect person only instead of whole labeled objects using tensorflow object-detection API?

I want to detect person only in a given picture (with person, cat, bicycle etc on it) using Tensorflow object detection API (and a pre-trained model "ssd_mobilenet_v1_coco_2017_11_17/frozen_inference_graph.pb"). How should I modify the following code? Maybe I should modify this line detection_graph.get_tensor_by_name('detection_classes:0'), but I have no idea what exactly I should do. Help me my friends, please! Thank you in advance. Or some references will also be great.

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

Upvotes: 1

Views: 611

Answers (1)

D_negn
D_negn

Reputation: 378

If I understand it correctly, you have to know the class label for person, then you can select only for that class in the part where you visualize the result of detection. Assuming the classes and boxes can be sliced.

Upvotes: 1

Related Questions