# 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/utils/dataset.py
# def read_label_file(file_path):
#   """Reads labels from a text file and returns it as a dictionary.
# 
#   This function supports label files with the following formats:
# 
#   + Each line contains id and description separated by colon or space.
#     Example: ``0:cat`` or ``0 cat``.
#   + Each line contains a description only. The returned label id's are based on
#     the row number.
# 
#   Args:
#     file_path (str): path to the label file.
# 
#   Returns:
#     Dict of (int, string) which maps label id to description.
#   """
#   with open(file_path, 'r', encoding='utf-8') as f:
#     lines = f.readlines()
#   ret = {}
#   for row_number, content in enumerate(lines):
#     pair = re.split(r'[:\s]+', content.strip(), maxsplit=1)
#     if len(pair) == 2 and pair[0].strip().isdigit():
#       ret[int(pair[0])] = pair[1].strip()
#     else:
#       ret[row_number] = content.strip()
#   return ret
# 
# 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: pycoral/utils/edgetpu.py
# def make_interpreter(model_path_or_content, device=None, delegate=None):
#   """Creates a new ``tf.lite.Interpreter`` instance using the given model.
# 
#   **Note:** If you have multiple Edge TPUs, you should always specify the
#   ``device`` argument.
# 
#   Args:
#      model_path_or_content (str or bytes): `str` object is interpreted as
#        model path, `bytes` object is interpreted as model content.
#      device (str): The Edge TPU device you want:
# 
#        + None      -- use any Edge TPU (this is the default)
#        + ":<N>"    -- use N-th Edge TPU (this corresponds to the enumerated
#          index position from :func:`list_edge_tpus`)
#        + "usb"     -- use any USB Edge TPU
#        + "usb:<N>" -- use N-th USB Edge TPU
#        + "pci"     -- use any PCIe Edge TPU
#        + "pci:<N>" -- use N-th PCIe Edge TPU
# 
#        If left as None, you cannot reliably predict which device you'll get.
#        So if you have multiple Edge TPUs and want to run a specific model on
#        each one, then you must specify the device.
#      delegate: A pre-loaded Edge TPU delegate object, as provided by
#        :func:`load_edgetpu_delegate`. If provided, the `device` argument
#        is ignored.
# 
#   Returns:
#      New ``tf.lite.Interpreter`` instance.
#   """
#   if delegate:
#     delegates = [delegate]
#   else:
#     delegates = [load_edgetpu_delegate({'device': device} if device else {})]
#   if isinstance(model_path_or_content, bytes):
#     return tflite.Interpreter(
#         model_content=model_path_or_content, experimental_delegates=delegates)
#   else:
#     return tflite.Interpreter(
#         model_path=model_path_or_content, experimental_delegates=delegates)


import argparse
import re
import threading
import time
import numpy as np
import pycoral.pipeline.pipelined_model_runner as pipeline
from PIL import Image
from pycoral.adapters import classify
from pycoral.adapters import common
from pycoral.utils.dataset import read_label_file
from pycoral.utils.edgetpu import list_edge_tpus
from pycoral.utils.edgetpu import make_interpreter
      '--top_k',
      type=int,
      default=1,
      help='Max number of classification results')
  parser.add_argument(
      '-t',
      '--threshold',
      type=float,
      default=0.0,
      help='Classification score threshold')
  parser.add_argument(
      '-c',
      '--count',
      type=int,
      default=5,
      help='Number of times to run inference')
  args = parser.parse_args()
  labels = read_label_file(args.labels) if args.labels else {}

  result = re.search(r'^.*_segment_%d_of_(?P<num_segments>[0-9]+)_.*.tflite',
                     args.models)
  if not result:
    raise ValueError(
        '--models should follow *_segment%d_of_[num_segments]_*.tflite pattern')
  num_segments = int(result.group('num_segments'))
  model_paths = [args.models % i for i in range(num_segments)]
  devices = _get_devices(num_segments)
  runner = _make_runner(model_paths, devices)

  size = common.input_size(runner.interpreters()[0])

# 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/utils/dataset.py
# def read_label_file(file_path):
#   """Reads labels from a text file and returns it as a dictionary.
# 
#   This function supports label files with the following formats:
# 
#   + Each line contains id and description separated by colon or space.
#     Example: ``0:cat`` or ``0 cat``.
#   + Each line contains a description only. The returned label id's are based on
#     the row number.
# 
#   Args:
#     file_path (str): path to the label file.
# 
#   Returns:
#     Dict of (int, string) which maps label id to description.
#   """
#   with open(file_path, 'r', encoding='utf-8') as f:
#     lines = f.readlines()
#   ret = {}
#   for row_number, content in enumerate(lines):
#     pair = re.split(r'[:\s]+', content.strip(), maxsplit=1)
#     if len(pair) == 2 and pair[0].strip().isdigit():
#       ret[int(pair[0])] = pair[1].strip()
#     else:
#       ret[row_number] = content.strip()
#   return ret
# 
# 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: pycoral/utils/edgetpu.py
# def make_interpreter(model_path_or_content, device=None, delegate=None):
#   """Creates a new ``tf.lite.Interpreter`` instance using the given model.
# 
#   **Note:** If you have multiple Edge TPUs, you should always specify the
#   ``device`` argument.
# 
#   Args:
#      model_path_or_content (str or bytes): `str` object is interpreted as
#        model path, `bytes` object is interpreted as model content.
#      device (str): The Edge TPU device you want:
# 
#        + None      -- use any Edge TPU (this is the default)
#        + ":<N>"    -- use N-th Edge TPU (this corresponds to the enumerated
#          index position from :func:`list_edge_tpus`)
#        + "usb"     -- use any USB Edge TPU
#        + "usb:<N>" -- use N-th USB Edge TPU
#        + "pci"     -- use any PCIe Edge TPU
#        + "pci:<N>" -- use N-th PCIe Edge TPU
# 
#        If left as None, you cannot reliably predict which device you'll get.
#        So if you have multiple Edge TPUs and want to run a specific model on
#        each one, then you must specify the device.
#      delegate: A pre-loaded Edge TPU delegate object, as provided by
#        :func:`load_edgetpu_delegate`. If provided, the `device` argument
#        is ignored.
# 
#   Returns:
#      New ``tf.lite.Interpreter`` instance.
#   """
#   if delegate:
#     delegates = [delegate]
#   else:
#     delegates = [load_edgetpu_delegate({'device': device} if device else {})]
#   if isinstance(model_path_or_content, bytes):
#     return tflite.Interpreter(
#         model_content=model_path_or_content, experimental_delegates=delegates)
#   else:
#     return tflite.Interpreter(
#         model_path=model_path_or_content, experimental_delegates=delegates)


# Path: examples/model_pipelining_classify_image.py
import argparse
import re
import threading
import time
import numpy as np
import pycoral.pipeline.pipelined_model_runner as pipeline
from PIL import Image
from pycoral.adapters import classify
from pycoral.adapters import common
from pycoral.utils.dataset import read_label_file
from pycoral.utils.edgetpu import list_edge_tpus
from pycoral.utils.edgetpu import make_interpreter

      '--top_k',
      type=int,
      default=1,
      help='Max number of classification results')
  parser.add_argument(
      '-t',
      '--threshold',
      type=float,
      default=0.0,
      help='Classification score threshold')
  parser.add_argument(
      '-c',
      '--count',
      type=int,
      default=5,
      help='Number of times to run inference')
  args = parser.parse_args()
  labels = read_label_file(args.labels) if args.labels else {}

  result = re.search(r'^.*_segment_%d_of_(?P<num_segments>[0-9]+)_.*.tflite',
                     args.models)
  if not result:
    raise ValueError(
        '--models should follow *_segment%d_of_[num_segments]_*.tflite pattern')
  num_segments = int(result.group('num_segments'))
  model_paths = [args.models % i for i in range(num_segments)]
  devices = _get_devices(num_segments)
  runner = _make_runner(model_paths, devices)

  size = common.input_size(runner.interpreters()[0])

  name = common.input_details(runner.interpreters()[0], 'name')