# 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: tests/test_utils.py
# _TEST_DATA_DIR = ''
#   _TEST_DATA_DIR = args.test_data_dir
# def get_test_tmpdir():
# def test_data_path(path, *paths):
# def test_image(path, *paths):
# def temporary_file(suffix=None):
# def generate_random_input(seed, n):
# def prepare_images(image_list, directory, shape):
# def area(box):
# def iou(box_a, box_b):
# def prepare_data_set_from_directory(path, test_ratio, fixed_order):
# def coral_test_main():


import contextlib
import os
import unittest
from PIL import Image
from pycoral.adapters import classify
from pycoral.adapters import common
from pycoral.learn.imprinting import engine
from pycoral.utils import edgetpu
from tests import test_utils
      image_num = 0
      for category, image_list in test_set.items():
        n = len(image_list)
        print('Evaluating {} ({} images)'.format(category, n))
        for image_name in image_list:
          with test_image(os.path.join(dataset_path, category,
                                       image_name)) as img:
            # Set threshold as a negative number to ensure we get top k
            # candidates even if its score is 0.
            size = common.input_size(classifier)
            common.set_input(classifier, img.resize(size, Image.NEAREST))
            classifier.invoke()
            candidates = classify.get_classes(classifier, top_k=top_k_range)

            for i in range(len(candidates)):
              candidate = candidates[i]
              if candidate.id in labels_map and \
                 labels_map[candidate.id] == category:
                top_k_correct_count[i] += 1
                break
        image_num += n
      for i in range(1, top_k_range):
        top_k_correct_count[i] += top_k_correct_count[i - 1]

    return [top_k_correct_count[i] / image_num for i in range(top_k_range)]

  def _test_oxford17_flowers_single(self, model_path, keep_classes, expected):
    top_k_range = len(expected)
    ret = self._transfer_learn_and_evaluate(
        test_utils.test_data_path(model_path), keep_classes,

# 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: tests/test_utils.py
# _TEST_DATA_DIR = ''
#   _TEST_DATA_DIR = args.test_data_dir
# def get_test_tmpdir():
# def test_data_path(path, *paths):
# def test_image(path, *paths):
# def temporary_file(suffix=None):
# def generate_random_input(seed, n):
# def prepare_images(image_list, directory, shape):
# def area(box):
# def iou(box_a, box_b):
# def prepare_data_set_from_directory(path, test_ratio, fixed_order):
# def coral_test_main():


# Path: tests/imprinting_evaluation_test.py
import contextlib
import os
import unittest
from PIL import Image
from pycoral.adapters import classify
from pycoral.adapters import common
from pycoral.learn.imprinting import engine
from pycoral.utils import edgetpu
from tests import test_utils

      image_num = 0
      for category, image_list in test_set.items():
        n = len(image_list)
        print('Evaluating {} ({} images)'.format(category, n))
        for image_name in image_list:
          with test_image(os.path.join(dataset_path, category,
                                       image_name)) as img:
            # Set threshold as a negative number to ensure we get top k
            # candidates even if its score is 0.
            size = common.input_size(classifier)
            common.set_input(classifier, img.resize(size, Image.NEAREST))
            classifier.invoke()
            candidates = classify.get_classes(classifier, top_k=top_k_range)

            for i in range(len(candidates)):
              candidate = candidates[i]
              if candidate.id in labels_map and \
                 labels_map[candidate.id] == category:
                top_k_correct_count[i] += 1
                break
        image_num += n
      for i in range(1, top_k_range):
        top_k_correct_count[i] += top_k_correct_count[i - 1]

    return [top_k_correct_count[i] / image_num for i in range(top_k_range)]

  def _test_oxford17_flowers_single(self, model_path, keep_classes, expected):
    top_k_range = len(expected)
    ret = self._transfer_learn_and_evaluate(
        test_utils.test_data_path(model_path), keep_classes,

        test_utils.test_data_path('oxford_17flowers'), 0.25, top_k_range)