# 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
                      task_type, delegates):
  """Runs classification or detection job with `num_threads`.

  Args:
    model_name: string
    input_filename: string
    num_inferences: int
    num_threads: int
    task_type: string, `classification` or `detection`
    delegates: list of Delegate objects, all aviable edgtpu devices.

  Returns:
    double, wall time (in seconds) for running the job.
  """

  def thread_job(model_name, input_filename, num_inferences, task_type,
                 delegate):
    """Runs classification or detection job on one Python thread."""
    tid = threading.get_ident()
    logging.info('Thread: %d, # inferences: %d, model: %s', tid, num_inferences,
                 model_name)

    interpreter = edgetpu.make_interpreter(
        benchmark_utils.test_data_path(model_name), delegate=delegate)
    interpreter.allocate_tensors()
    with benchmark_utils.test_image(input_filename) as img:
      if task_type == 'classification':
        resize_image = img.resize(common.input_size(interpreter), Image.NEAREST)
        common.set_input(interpreter, resize_image)
      elif task_type == 'detection':

# 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

                      task_type, delegates):
  """Runs classification or detection job with `num_threads`.

  Args:
    model_name: string
    input_filename: string
    num_inferences: int
    num_threads: int
    task_type: string, `classification` or `detection`
    delegates: list of Delegate objects, all aviable edgtpu devices.

  Returns:
    double, wall time (in seconds) for running the job.
  """

  def thread_job(model_name, input_filename, num_inferences, task_type,
                 delegate):
    """Runs classification or detection job on one Python thread."""
    tid = threading.get_ident()
    logging.info('Thread: %d, # inferences: %d, model: %s', tid, num_inferences,
                 model_name)

    interpreter = edgetpu.make_interpreter(
        benchmark_utils.test_data_path(model_name), delegate=delegate)
    interpreter.allocate_tensors()
    with benchmark_utils.test_image(input_filename) as img:
      if task_type == 'classification':
        resize_image = img.resize(common.input_size(interpreter), Image.NEAREST)
        common.set_input(interpreter, resize_image)
      elif task_type == 'detection':

        common.set_resized_input(interpreter, img.size,