# 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/learn/imprinting/engine.py
# class ImprintingEngine:
#   def __init__(self, model_path, keep_classes=False):
#   def embedding_dim(self):
#   def num_classes(self):
#   def serialize_extractor_model(self):
#   def serialize_model(self):
#   def train(self, embedding, class_id):
# 
# 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 collections
import sys
import time
import numpy as np
import tflite_runtime.interpreter as tflite
from benchmarks import benchmark_utils
from pycoral.adapters import classify
from pycoral.adapters import common
from pycoral.learn.imprinting import engine
from pycoral.utils import edgetpu
  inference_time = 0.
  for class_id, tensors in enumerate(data_by_category.values()):
    for tensor in tensors:
      common.set_input(extractor, tensor)
      extractor.invoke()
      imprinting_engine.train(classify.get_scores(extractor), class_id=class_id)

    start = time.perf_counter()
    interpreter = tflite.Interpreter(
        model_content=imprinting_engine.serialize_model(),
        experimental_delegates=[delegate])
    interpreter.allocate_tensors()
    common.set_input(interpreter, tensors[0])
    interpreter.invoke()
    classify.get_classes(interpreter, top_k=3)
    inference_time += (time.perf_counter() - start) * 1000

  print('Model: %s' % model)
  print('Inference time: %.2fms' % inference_time)
  return inference_time


def main():
  print('Python version: ', sys.version)
  args = benchmark_utils.parse_args()
  machine = benchmark_utils.machine_info()
  benchmark_utils.check_cpu_scaling_governor_status()
  models, reference = benchmark_utils.read_reference(
      'imprinting_reference_inference_%s.csv' % machine)
  results = [('MODEL', 'DATA_SET', 'INFERENCE_TIME')]

# 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/learn/imprinting/engine.py
# class ImprintingEngine:
#   def __init__(self, model_path, keep_classes=False):
#   def embedding_dim(self):
#   def num_classes(self):
#   def serialize_extractor_model(self):
#   def serialize_model(self):
#   def train(self, embedding, class_id):
# 
# 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/online_imprinting_benchmarks.py
import collections
import sys
import time
import numpy as np
import tflite_runtime.interpreter as tflite
from benchmarks import benchmark_utils
from pycoral.adapters import classify
from pycoral.adapters import common
from pycoral.learn.imprinting import engine
from pycoral.utils import edgetpu

  inference_time = 0.
  for class_id, tensors in enumerate(data_by_category.values()):
    for tensor in tensors:
      common.set_input(extractor, tensor)
      extractor.invoke()
      imprinting_engine.train(classify.get_scores(extractor), class_id=class_id)

    start = time.perf_counter()
    interpreter = tflite.Interpreter(
        model_content=imprinting_engine.serialize_model(),
        experimental_delegates=[delegate])
    interpreter.allocate_tensors()
    common.set_input(interpreter, tensors[0])
    interpreter.invoke()
    classify.get_classes(interpreter, top_k=3)
    inference_time += (time.perf_counter() - start) * 1000

  print('Model: %s' % model)
  print('Inference time: %.2fms' % inference_time)
  return inference_time


def main():
  print('Python version: ', sys.version)
  args = benchmark_utils.parse_args()
  machine = benchmark_utils.machine_info()
  benchmark_utils.check_cpu_scaling_governor_status()
  models, reference = benchmark_utils.read_reference(
      'imprinting_reference_inference_%s.csv' % machine)
  results = [('MODEL', 'DATA_SET', 'INFERENCE_TIME')]

  delegate = edgetpu.load_edgetpu_delegate()