benchmark.py 674 B

1234567891011121314151617181920
  1. import statistics
  2. import numpy as np
  3. from edgetpu.detection.engine import DetectionEngine
  4. # Path to frozen detection graph. This is the actual model that is used for the object detection.
  5. PATH_TO_CKPT = '/frozen_inference_graph.pb'
  6. # Load the edgetpu engine and labels
  7. engine = DetectionEngine(PATH_TO_CKPT)
  8. frame = np.zeros((300,300,3), np.uint8)
  9. flattened_frame = np.expand_dims(frame, axis=0).flatten()
  10. detection_times = []
  11. for x in range(0, 1000):
  12. objects = engine.detect_with_input_tensor(flattened_frame, threshold=0.1, top_k=3)
  13. detection_times.append(engine.get_inference_time())
  14. print("Average inference time: " + str(statistics.mean(detection_times)))