How to count objects in Tensorflow Object Detection API

前端 未结 5 1252
旧巷少年郎
旧巷少年郎 2020-12-05 16:23

I am executing https://github.com/tensorflow/tensorflow this example of detecting objects in image.

I want to get count of detected objects following is the code tha

相关标签:
5条回答
  • 2020-12-05 16:35

    add this part to count objects

    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
    

    count is the number of objects detected

    this part will print count but will print it in continuous manner can it be used to print only once like final count = some value instead of printing it repeatedly

    0 讨论(0)
  • 2020-12-05 16:37

    You should check scores and count objects as manual. Code is here:

    #code to test image start
    
        (boxes, scores, classes, num) = sess.run(
            [detection_boxes, detection_scores, detection_classes, num_detections],
            feed_dict={image_tensor: image_np_expanded})
    
    #code to test image finish
    
    #add this part to count objects
    
        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
    
    #count is the number of objects detected
    
    0 讨论(0)
  • 2020-12-05 16:44

    You can use the TensorFlow Object Counting API that is an open source framework built on top of TensorFlow that makes it easy to develop object counting systems to count any objects!

    • Sample Project#1 is "Pedestrian Counting" developed using TensorFlow Object Counting API:

    • Sample Project#2 is "Vehicle Counting" developed using TensorFlow Object Counting API:

    • Sample Project#3 is "Object Counting in Real-Time" developed using TensorFlow Object Counting API:

    See the TensorFlow Object Counting API for more info and please give a star that repo for showing your support to open source community if you find it useful!

    0 讨论(0)
  • 2020-12-05 16:46

    It's important to note that the number of boxes is always 100.

    If you look at the code that actually draws the boxes, i.e., the vis_util.visualize_boxes_and_labels_on_image_array function, you'll see that they're defining a threshold -- min_score_thresh=.5 -- to limit the boxes drawn to only those detections in which the score is > 0.5. You can think of this as only drawing boxes where the probability of accurate detection is >50%. You can adjust this threshold up or down to increase the number of boxes drawn. If you decrease it too low, however, you will get a lot of inaccurate boxes.

    0 讨论(0)
  • 2020-12-05 16:51

    Solve it simply print length of boxes.shape

    print(len(boxes.shape))
    
    0 讨论(0)
提交回复
热议问题