Categories
Misc

Object Detection API – Get classes + scores

Hi all,I have successfully used the Object Detection API to train a model and am now trying to obtain a list of the class name and scores for the objects detected. Here is the code:

EDIT: Scores will not be required if the final output would only be a single class name. Thank you.

 input_tensor = tf.convert_to_tensor(np.expand_dims(image, 0), dtype=tf.float32) detections, predictions_dict, shapes = detect_fn(input_tensor) # print(detections) # print(predictions_dict) # print(shapes) label_id_offset = 1 image_np_with_detections = image.copy() viz_utils.visualize_boxes_and_labels_on_image_array( image_np_with_detections, detections['detection_boxes'][0].numpy(), (detections['detection_classes'][0].numpy() + label_id_offset).astype(int), detections['detection_scores'][0].numpy(), category_index, use_normalized_coordinates=True, max_boxes_to_draw=200, min_score_thresh=.30, agnostic_mode=False) cv2.imshow('object detection', cv2.resize(image_np_with_detections, (800, 600))) 

I would like to be able to do something like this:

if object_name == 'object1': {action 1} elif object_name == 'object2': {action 2} 

While this launches the cv2 display window successfully, I have been unable to find any workable solution to get class name or the score. Generally, I was unable to find no viable solutions at all, barring this one, but after trying the solution it has proven to unsuccessful too.

I hope that I can be pointed towards a tutorial for this, but any help/thoughts will be greatly appreciated.

Thank you in advance!

submitted by /u/potatooBros
[visit reddit] [comments]

Leave a Reply

Your email address will not be published. Required fields are marked *