Skip to content

Instantly share code, notes, and snippets.

@zakirangwala
Created December 1, 2020 06:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zakirangwala/61c28859c6dbba6dedc7ad58a890f7dc to your computer and use it in GitHub Desktop.
Save zakirangwala/61c28859c6dbba6dedc7ad58a890f7dc to your computer and use it in GitHub Desktop.
Check Model - Mask Detection
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