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
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
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
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!
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!
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.
Solve it simply print length of boxes.shape
print(len(boxes.shape))