Created
December 1, 2020 06:57
-
-
Save zakirangwala/61c28859c6dbba6dedc7ad58a890f7dc to your computer and use it in GitHub Desktop.
Check Model - Mask Detection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def check(image): | |
image_np = cv2.imread(image) | |
input_tensor = tf.convert_to_tensor( | |
np.expand_dims(image_np, 0), dtype=tf.float32) | |
detections = detect_fn(input_tensor) | |
category_index = label_map_util.create_category_index_from_labelmap( | |
ANNOTATION_PATH+'/label_map.pbtxt') | |
num_detections = int(detections.pop('num_detections')) | |
detections = {key: value[0, :num_detections].numpy() | |
for key, value in detections.items()} | |
detections['num_detections'] = num_detections | |
detections['detection_classes'] = detections['detection_classes'].astype( | |
np.int64) | |
label_id_offset = 1 | |
image_np_with_detections = image_np.copy() | |
viz_utils.visualize_boxes_and_labels_on_image_array( | |
image_np_with_detections, | |
detections['detection_boxes'], | |
detections['detection_classes']+label_id_offset, | |
detections['detection_scores'], | |
category_index, | |
use_normalized_coordinates=True, | |
max_boxes_to_draw=1, | |
min_score_thresh=0.1, | |
agnostic_mode=False) | |
cv2.imwrite('Tensorflow/workspace/images/check/results/six.png', | |
image_np_with_detections) | |
print( | |
f"Class - {detections['detection_classes'][0] + label_id_offset}\nScores - {detections['detection_scores'][0]}\nBoxes - {detections['detection_boxes'][0]}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment