From 7028b05856ef9c3b689958aa066d4e75db74a169 Mon Sep 17 00:00:00 2001 From: blakeblackshear Date: Tue, 4 Jun 2019 21:38:41 -0500 Subject: [PATCH] add a benchmark script --- Dockerfile | 1 + benchmark.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 benchmark.py diff --git a/Dockerfile b/Dockerfile index 18611113b..c35c8c8b8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -102,5 +102,6 @@ RUN (apt-get autoremove -y; \ WORKDIR /opt/frigate/ ADD frigate frigate/ COPY detect_objects.py . +COPY benchmark.py . CMD ["python3", "-u", "detect_objects.py"] diff --git a/benchmark.py b/benchmark.py new file mode 100644 index 000000000..4ef1fe9de --- /dev/null +++ b/benchmark.py @@ -0,0 +1,20 @@ +import statistics +import numpy as np +from edgetpu.detection.engine import DetectionEngine + +# Path to frozen detection graph. This is the actual model that is used for the object detection. +PATH_TO_CKPT = '/frozen_inference_graph.pb' + +# Load the edgetpu engine and labels +engine = DetectionEngine(PATH_TO_CKPT) + +frame = np.zeros((300,300,3), np.uint8) +flattened_frame = np.expand_dims(frame, axis=0).flatten() + +detection_times = [] + +for x in range(0, 1000): + objects = engine.DetectWithInputTensor(flattened_frame, threshold=0.1, top_k=3) + detection_times.append(engine.get_inference_time()) + +print("Average inference time: " + str(statistics.mean(detection_times))) \ No newline at end of file