<jupyter_start><jupyter_text>Testing the models<jupyter_code>!wget --no-clobber "https://images.canadagoose.com/image/upload/w_1333,c_scale,f_auto,q_auto:best/v1601577550/product-image/5558U_1073.jpg" -O mask_example1.jpg
!wget --no-clobber  "https://i.cbc.ca/1.5901311.1612993040!/fileImage/httpImage/image.jpg_gen/derivatives/original_780/face-recognition-test.jpg" -O mask_example2.jpg
!wget --no-clobber  "https://media.npr.org/assets/img/2021/01/29/_dsf1400_custom-01c8b25d39b298816ef6996981e39e40477fe7c6.jpg" -O mask_example3.jpg
img_filename = "mask_example2.jpg"
# PATH_TO_TFLITE = "ssdlite_mobiledet_mask.tflite"
PATH_TO_TFLITE = "ssdlite_mobiledet_mask_edgetpu.tflite"
run_inference_for_single_image_tflite_ssd = inference_for_single_image_tflite(PATH_TO_TFLITE)
import numpy as np

image = Image.open(img_filename)
image = image.convert('RGB')
image_width, image_height = image.size

# tflite will not have the image resizing in the model
input_width = run_inference_for_single_image_tflite_ssd.width
input_height = run_inference_for_single_image_tflite_ssd.height

resized_image = image.resize((input_width, input_height))
np_image = np.asarray(resized_image)

image_np_expanded = np.expand_dims(np_image, axis=0)

# Actual detection.
boxes, classes, scores, _ = run_inference_for_single_image_tflite_ssd(image_np_expanded)

classes = [i+1 for i in classes] # class indices here start at 0
classes
scores
resized_image
process_bboxes(resized_image.copy(), boxes, classes, scores, threshold=0.5)
import time

total_loops = 10
init_time = time.monotonic()
for i in range(total_loops):
    # Actual detection.
    boxes, classes, scores, _ = run_inference_for_single_image_tflite_ssd(image_np_expanded)
    
final_time = time.monotonic()
print(f"Total time: {final_time-init_time}")
print(f"FPS: {1/((final_time-init_time)/total_loops)}")<jupyter_output>Total time: 0.5588072470000043
FPS: 17.895258255303055
{'fraction_non_alphanumeric': 0.10531803962460896, 'fraction_numerical': 0.06777893639207508, 'mean_word_length': 7.09704641350211, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '408928', 'license': 'Apache-2.0', 'n_tokens_mistral': 836, 'n_tokens_neox': 763, 'n_words': 111, 'path': 'Masks Detection on RPI0 - EdgeTPU or CPU.ipynb', 'repo_name': 'ricardodeazambuja/MaskDetection-EdgeTPU-RPI0', 'size': '1918'}