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












0















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









share|improve this question



























    0















    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









    share|improve this question

























      0












      0








      0








      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









      share|improve this question














      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






      object tensorflow detection






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 23 '18 at 3:30









      gerygery

      408




      408
























          1 Answer
          1






          active

          oldest

          votes


















          1














          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.






          share|improve this answer
























          • Thank you for comment. I feel I've found some useful materials, I'm now trying to understand it. Maybe few days later, I'll solve this problem and post the anwer.

            – gery
            Nov 26 '18 at 1:09











          • But still welcome many other possible answers ^_^

            – gery
            Nov 26 '18 at 1:10











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53440338%2fhow-to-detect-person-only-instead-of-whole-labeled-objects-using-tensorflow-obje%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          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.






          share|improve this answer
























          • Thank you for comment. I feel I've found some useful materials, I'm now trying to understand it. Maybe few days later, I'll solve this problem and post the anwer.

            – gery
            Nov 26 '18 at 1:09











          • But still welcome many other possible answers ^_^

            – gery
            Nov 26 '18 at 1:10
















          1














          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.






          share|improve this answer
























          • Thank you for comment. I feel I've found some useful materials, I'm now trying to understand it. Maybe few days later, I'll solve this problem and post the anwer.

            – gery
            Nov 26 '18 at 1:09











          • But still welcome many other possible answers ^_^

            – gery
            Nov 26 '18 at 1:10














          1












          1








          1







          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.






          share|improve this answer













          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 23 '18 at 13:05









          D.negnD.negn

          7815




          7815













          • Thank you for comment. I feel I've found some useful materials, I'm now trying to understand it. Maybe few days later, I'll solve this problem and post the anwer.

            – gery
            Nov 26 '18 at 1:09











          • But still welcome many other possible answers ^_^

            – gery
            Nov 26 '18 at 1:10



















          • Thank you for comment. I feel I've found some useful materials, I'm now trying to understand it. Maybe few days later, I'll solve this problem and post the anwer.

            – gery
            Nov 26 '18 at 1:09











          • But still welcome many other possible answers ^_^

            – gery
            Nov 26 '18 at 1:10

















          Thank you for comment. I feel I've found some useful materials, I'm now trying to understand it. Maybe few days later, I'll solve this problem and post the anwer.

          – gery
          Nov 26 '18 at 1:09





          Thank you for comment. I feel I've found some useful materials, I'm now trying to understand it. Maybe few days later, I'll solve this problem and post the anwer.

          – gery
          Nov 26 '18 at 1:09













          But still welcome many other possible answers ^_^

          – gery
          Nov 26 '18 at 1:10





          But still welcome many other possible answers ^_^

          – gery
          Nov 26 '18 at 1:10


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53440338%2fhow-to-detect-person-only-instead-of-whole-labeled-objects-using-tensorflow-obje%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Wiesbaden

          Marschland

          Dieringhausen