# Path: benchmarks/benchmark_utils.py
# def parse_args():
# def check_cpu_scaling_governor_status():
# def machine_info():
# def test_data_path(path, *paths):
# def reference_path(path, *paths):
# def benchmark_result_path(path, *paths):
# def test_image(path, *paths):
# def read_reference(file_name):
# def check_result(reference, result_list, enable_assertion):
# def save_as_csv(file_name, result):
# TEST_DATA_DIR = os.path.join(
#     os.path.dirname(os.path.realpath(__file__)), '..', 'test_data')
# REFERENCE_DATA_DIR = os.path.join(
#     os.path.dirname(os.path.realpath(__file__)), 'reference')
# BENCHMARK_RESULT_DIR = os.path.join(tempfile.gettempdir(), 'result')
# 
# Path: pycoral/adapters/classify.py
# def num_classes(interpreter):
# def get_scores(interpreter):
# def get_classes_from_scores(scores,
#                             top_k=float('inf'),
#                             score_threshold=-float('inf')):
# def get_classes(interpreter, top_k=float('inf'), score_threshold=-float('inf')):
# 
# Path: pycoral/adapters/common.py
# def output_tensor(interpreter, i):
# def input_details(interpreter, key):
# def input_size(interpreter):
# def input_tensor(interpreter):
# def set_input(interpreter, data):
# def set_resized_input(interpreter, size, resize):
# 
# Path: pycoral/adapters/detect.py
# class BBox(collections.namedtuple('BBox', ['xmin', 'ymin', 'xmax', 'ymax'])):
#   def width(self):
#   def height(self):
#   def area(self):
#   def valid(self):
#   def scale(self, sx, sy):
#   def translate(self, dx, dy):
#   def map(self, f):
#   def intersect(a, b):
#   def union(a, b):
#   def iou(a, b):
# def get_objects(interpreter,
#                 score_threshold=-float('inf'),
#                 image_scale=(1.0, 1.0)):
#   def make(i):
# 
# Path: pycoral/utils/edgetpu.py
# _EDGETPU_SHARED_LIB = {
#   'Linux': 'libedgetpu.so.1',
#   'Darwin': 'libedgetpu.1.dylib',
#   'Windows': 'edgetpu.dll'
# }[platform.system()]
# def load_edgetpu_delegate(options=None):
# def make_interpreter(model_path_or_content, device=None, delegate=None):
# def _is_valid_ctypes_input(input_data):
# def _gst_buffer_map(buffer):
# def _check_input_size(input_size, expected_input_size):
# def run_inference(interpreter, input_data):
# class _GstMapInfo(ctypes.Structure):


import logging
import sys
import threading
import time
from PIL import Image
from benchmarks import benchmark_utils
from pycoral.adapters import classify
from pycoral.adapters import common
from pycoral.adapters import detect
from pycoral.utils import edgetpu
          detect.get_objects(interpreter)
    logging.info('Thread: %d, model: %s done', tid, model_name)

  start_time = time.perf_counter()
  # Round up a bit if not divisible.
  num_inferences_per_thread = (num_inferences + num_threads - 1) // num_threads
  workers = []
  for i in range(num_threads):
    workers.append(
        threading.Thread(
            target=thread_job,
            args=(model_name, input_filename, num_inferences_per_thread,
                  task_type, delegates[i])))

  for worker in workers:
    worker.start()
  for worker in workers:
    worker.join()
  return time.perf_counter() - start_time


def main():
  num_inferences = 30000
  input_filename = 'cat.bmp'
  all_tpus = edgetpu.list_edge_tpus()
  num_devices = len(all_tpus)
  num_pci_devices = sum(1 for device in all_tpus if device['type'] == 'pci')
  devices = ['pci:%d' % i for i in range(min(num_devices, num_pci_devices))] + [
      'usb:%d' % i for i in range(max(0, num_devices - num_pci_devices))
  ]

# Path: benchmarks/benchmark_utils.py
# def parse_args():
# def check_cpu_scaling_governor_status():
# def machine_info():
# def test_data_path(path, *paths):
# def reference_path(path, *paths):
# def benchmark_result_path(path, *paths):
# def test_image(path, *paths):
# def read_reference(file_name):
# def check_result(reference, result_list, enable_assertion):
# def save_as_csv(file_name, result):
# TEST_DATA_DIR = os.path.join(
#     os.path.dirname(os.path.realpath(__file__)), '..', 'test_data')
# REFERENCE_DATA_DIR = os.path.join(
#     os.path.dirname(os.path.realpath(__file__)), 'reference')
# BENCHMARK_RESULT_DIR = os.path.join(tempfile.gettempdir(), 'result')
# 
# Path: pycoral/adapters/classify.py
# def num_classes(interpreter):
# def get_scores(interpreter):
# def get_classes_from_scores(scores,
#                             top_k=float('inf'),
#                             score_threshold=-float('inf')):
# def get_classes(interpreter, top_k=float('inf'), score_threshold=-float('inf')):
# 
# Path: pycoral/adapters/common.py
# def output_tensor(interpreter, i):
# def input_details(interpreter, key):
# def input_size(interpreter):
# def input_tensor(interpreter):
# def set_input(interpreter, data):
# def set_resized_input(interpreter, size, resize):
# 
# Path: pycoral/adapters/detect.py
# class BBox(collections.namedtuple('BBox', ['xmin', 'ymin', 'xmax', 'ymax'])):
#   def width(self):
#   def height(self):
#   def area(self):
#   def valid(self):
#   def scale(self, sx, sy):
#   def translate(self, dx, dy):
#   def map(self, f):
#   def intersect(a, b):
#   def union(a, b):
#   def iou(a, b):
# def get_objects(interpreter,
#                 score_threshold=-float('inf'),
#                 image_scale=(1.0, 1.0)):
#   def make(i):
# 
# Path: pycoral/utils/edgetpu.py
# _EDGETPU_SHARED_LIB = {
#   'Linux': 'libedgetpu.so.1',
#   'Darwin': 'libedgetpu.1.dylib',
#   'Windows': 'edgetpu.dll'
# }[platform.system()]
# def load_edgetpu_delegate(options=None):
# def make_interpreter(model_path_or_content, device=None, delegate=None):
# def _is_valid_ctypes_input(input_data):
# def _gst_buffer_map(buffer):
# def _check_input_size(input_size, expected_input_size):
# def run_inference(interpreter, input_data):
# class _GstMapInfo(ctypes.Structure):


# Path: benchmarks/multiple_tpus_performance_analysis.py
import logging
import sys
import threading
import time
from PIL import Image
from benchmarks import benchmark_utils
from pycoral.adapters import classify
from pycoral.adapters import common
from pycoral.adapters import detect
from pycoral.utils import edgetpu

          detect.get_objects(interpreter)
    logging.info('Thread: %d, model: %s done', tid, model_name)

  start_time = time.perf_counter()
  # Round up a bit if not divisible.
  num_inferences_per_thread = (num_inferences + num_threads - 1) // num_threads
  workers = []
  for i in range(num_threads):
    workers.append(
        threading.Thread(
            target=thread_job,
            args=(model_name, input_filename, num_inferences_per_thread,
                  task_type, delegates[i])))

  for worker in workers:
    worker.start()
  for worker in workers:
    worker.join()
  return time.perf_counter() - start_time


def main():
  num_inferences = 30000
  input_filename = 'cat.bmp'
  all_tpus = edgetpu.list_edge_tpus()
  num_devices = len(all_tpus)
  num_pci_devices = sum(1 for device in all_tpus if device['type'] == 'pci')
  devices = ['pci:%d' % i for i in range(min(num_devices, num_pci_devices))] + [
      'usb:%d' % i for i in range(max(0, num_devices - num_pci_devices))
  ]

  delegates = [edgetpu.load_edgetpu_delegate({'device': d}) for d in devices]