I\'m trying to return list of objects that have been found at image with TF Object Detection API.
To do that I\'m using print([category_index.get(i) for
// this will load the labels and categories along with category index
label_map = label_map_util.load_labelmap(PATH_TO_LABELS)
categories = label_map_util.convert_label_map_to_categories(label_map, max_num_classes=NUM_CLASSES, use_display_name=True)
category_index = label_map_util.create_category_index(categories)
//to print the identified object do the following :
print category instead of category index. The index holds the numeric value and the category contains the name of the objects. Once identified with the mentioned threshold the
min_score_thresh = 0.5
print([category.get(1)] for i in classes[0] if scores[0, i] > min_score_thresh)
this will print the identified category.
open visualization_utils.py and add--> print(class_name)
after
else:
class_name = 'N/A'
display_str = '{}: {}%'.format(
class_name,
int(100*scores[i]))
this will print the detected objects
From the function signature visualize_boxes_and_labels_on_image_array, you have to set the arguments max_boxes_to_draw
, min_score_thresh
,
visualize_boxes_and_labels_on_image_array(image,
boxes,
classes,
scores,
category_index,
instance_masks=None,
keypoints=None,
use_normalized_coordinates=False,
max_boxes_to_draw=20,
min_score_thresh=.5,
agnostic_mode=False,
line_thickness=4)
Try to set the min_score_thresh to 0. Then you will probably see 300 detections.
adding print(class_name)
after
else:
class_name = 'N/A'
display_str = '{}: {}%'.format(
class_name,
int(100*scores[i]))
in visualization_utils.py
file prints the detected object.
I wonder where to add print command to print timestamps as well as percentage of accuracy in output.
As far as I can see you have 300 detections. visualize_boxes_and_labels_on_image_array
shows very few of them because min_score_thresh=.5
(this is the default value) is too high for the most of them.
If you want to add such filtering to the output you can write:
min_score_thresh = 0.5
print([category_index.get(i) for i in classes[0] if scores[0, i] > min_score_thresh)
You can change min_score_thresh
to choose threshold value you need. It may be useful to print the score values with the category names.