# 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/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 sys
import time
import timeit
import numpy as np
from benchmarks import benchmark_utils
from pycoral.utils import edgetpu
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Benchmark of models.

Benchmark are measured with CPU 'performance' mode. To enable it, you need to
install 'cpupower' and run:
sudo cpupower frequency-set --governor performance

The reference number is measured on:
  - 'x86_64': Intel Xeon E5-1650 v3(3.50GHz) + Edge TPU accelarator + USB 3.0
  - 'rp3b': Raspberry Pi 3 B (version1.2)+ Edge TPU accelarator + USB 2.0
  - 'rp3b+': Raspberry Pi 3 B+ (version1.3)+ Edge TPU accelarator + USB 2.0
  - 'aarch64': Edge TPU dev board.
"""





def run_benchmark(model, delegate):
  """Returns average inference time in ms on specified model with random input."""

  print('Benchmark for [%s]' % model)

# 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/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/inference_benchmarks.py
import sys
import time
import timeit
import numpy as np
from benchmarks import benchmark_utils
from pycoral.utils import edgetpu

# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Benchmark of models.

Benchmark are measured with CPU 'performance' mode. To enable it, you need to
install 'cpupower' and run:
sudo cpupower frequency-set --governor performance

The reference number is measured on:
  - 'x86_64': Intel Xeon E5-1650 v3(3.50GHz) + Edge TPU accelarator + USB 3.0
  - 'rp3b': Raspberry Pi 3 B (version1.2)+ Edge TPU accelarator + USB 2.0
  - 'rp3b+': Raspberry Pi 3 B+ (version1.3)+ Edge TPU accelarator + USB 2.0
  - 'aarch64': Edge TPU dev board.
"""





def run_benchmark(model, delegate):
  """Returns average inference time in ms on specified model with random input."""

  print('Benchmark for [%s]' % model)

  print('model path = %s' % benchmark_utils.test_data_path(model))