Skip to content

Instantly share code, notes, and snippets.

@hmahadik
Last active September 14, 2021 19:32
Show Gist options
  • Save hmahadik/cc50bc19bb9c7b3dc03591ba87240b1f to your computer and use it in GitHub Desktop.
Save hmahadik/cc50bc19bb9c7b3dc03591ba87240b1f to your computer and use it in GitHub Desktop.
Script to measure time taken to run an embeddings model using pyarmnn
import os
import cv_utils
import network_executor
import utils
import cv2
import time
import sys
try:
model_path = os.path.join('/tmp', sys.argv[1])
except:
print(f"Error: args missing. e.g. python3 pyarmnn_embed.py /tmp/mobilenet_v1_embed.tflite")
sys.exit(0)
backends = ["CpuAcc", "CpuRef"]
executor = network_executor.ArmnnNetworkExecutor(model_path, backends)
img = cv2.imread('/usr/local/share/deepvision/images/identities/person-0132/0132_c1s1_023176_00.jpg')
input_tensors = cv_utils.preprocess(img, executor.input_binding_info)
output_result = executor.run(input_tensors)
start = time.time()
output_result = executor.run(input_tensors)
end = time.time()
print(f"Output: {output_result}")
print(f"Embed time: {round((end-start)*1000,1)} ms")
@hmahadik
Copy link
Author

hmahadik commented Sep 14, 2021

First make sure that you clone armnn and cd into the right folder before running this gist:

wget https://github.com/ARM-software/armnn/archive/refs/heads/branches/armnn_21_08.zip
unzip armnn_21_08.zip
cd armnn-branches-armnn_21_08/python/pyarmnn/examples/common
wget https://gist.githubusercontent.com/hmahadik/cc50bc19bb9c7b3dc03591ba87240b1f/raw/369b686fe5c0035dfa02517996599bf82f9eb236/pyarmnn_embed.py
python3 pyarmnn_embed.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment