From f2bd8e6a04614f5d0f1d3eaac3906b1bebbb82bc Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 5 Jan 2022 20:36:40 -0800 Subject: [PATCH 1/3] Attempt `edgetpu-compiler` autoinstall Attempt to install edgetpu-compiler dependency if missing on Linux. --- export.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/export.py b/export.py index 21aa67ff0a4..2abd881ad78 100644 --- a/export.py +++ b/export.py @@ -309,11 +309,19 @@ def export_edgetpu(keras_model, im, file, prefix=colorstr('Edge TPU:')): # YOLOv5 Edge TPU export https://coral.ai/docs/edgetpu/models-intro/ try: cmd = 'edgetpu_compiler --version' - help = 'See https://coral.ai/docs/edgetpu/compiler/' - assert platform.system() == 'Linux', f'export only supported on Linux. {help}' - assert subprocess.run(cmd, shell=True).returncode == 0, f'export requires edgetpu-compiler. {help}' - out = subprocess.run(cmd, shell=True, capture_output=True, check=True) - ver = out.stdout.decode().split()[-1] + help_url = 'https://coral.ai/docs/edgetpu/compiler/' + assert platform.system() == 'Linux', f'export only supported on Linux. See {help_url}' + # assert subprocess.run(cmd, shell=True).returncode == 0, f'export requires edgetpu-compiler. {help}' + if subprocess.run(cmd, shell=True).returncode != 0: + LOGGER.info(f'\n{prefix} export requires edgetpu-compiler. Installing from {help_url} ...') + cmds = ['curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -', + 'echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | sudo tee /etc/apt/sources.list.d/coral-edgetpu.list', + 'sudo apt-get update', + 'sudo apt-get install edgetpu-compiler'] + for c in cmds: + subprocess.run(c, shell=True, check=True) + LOGGER.info(f'\n{prefix} edgetpu-compiler install complete.') + ver = subprocess.run(cmd, shell=True, capture_output=True, check=True).stdout.decode().split()[-1] LOGGER.info(f'\n{prefix} starting export with Edge TPU compiler {ver}...') f = str(file).replace('.pt', '-int8_edgetpu.tflite') # Edge TPU model From 2079ecbd8c594f6958ad120010b5de4da3b66e6f Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 5 Jan 2022 20:47:26 -0800 Subject: [PATCH 2/3] Update export.py --- export.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/export.py b/export.py index 2abd881ad78..961eafd82ed 100644 --- a/export.py +++ b/export.py @@ -311,16 +311,14 @@ def export_edgetpu(keras_model, im, file, prefix=colorstr('Edge TPU:')): cmd = 'edgetpu_compiler --version' help_url = 'https://coral.ai/docs/edgetpu/compiler/' assert platform.system() == 'Linux', f'export only supported on Linux. See {help_url}' - # assert subprocess.run(cmd, shell=True).returncode == 0, f'export requires edgetpu-compiler. {help}' if subprocess.run(cmd, shell=True).returncode != 0: - LOGGER.info(f'\n{prefix} export requires edgetpu-compiler. Installing from {help_url} ...') + LOGGER.info(f'\n{prefix} export requires Edge TPU compiler. Attempting install from {help_url}') cmds = ['curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -', 'echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | sudo tee /etc/apt/sources.list.d/coral-edgetpu.list', 'sudo apt-get update', 'sudo apt-get install edgetpu-compiler'] for c in cmds: subprocess.run(c, shell=True, check=True) - LOGGER.info(f'\n{prefix} edgetpu-compiler install complete.') ver = subprocess.run(cmd, shell=True, capture_output=True, check=True).stdout.decode().split()[-1] LOGGER.info(f'\n{prefix} starting export with Edge TPU compiler {ver}...') From 14f9f46e1bfe3c5693f7f9f90d5a2718051f3c14 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 5 Jan 2022 20:49:12 -0800 Subject: [PATCH 3/3] Update export.py --- export.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/export.py b/export.py index 961eafd82ed..6d15b21d031 100644 --- a/export.py +++ b/export.py @@ -313,11 +313,10 @@ def export_edgetpu(keras_model, im, file, prefix=colorstr('Edge TPU:')): assert platform.system() == 'Linux', f'export only supported on Linux. See {help_url}' if subprocess.run(cmd, shell=True).returncode != 0: LOGGER.info(f'\n{prefix} export requires Edge TPU compiler. Attempting install from {help_url}') - cmds = ['curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -', - 'echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | sudo tee /etc/apt/sources.list.d/coral-edgetpu.list', - 'sudo apt-get update', - 'sudo apt-get install edgetpu-compiler'] - for c in cmds: + for c in ['curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -', + 'echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | sudo tee /etc/apt/sources.list.d/coral-edgetpu.list', + 'sudo apt-get update', + 'sudo apt-get install edgetpu-compiler']: subprocess.run(c, shell=True, check=True) ver = subprocess.run(cmd, shell=True, capture_output=True, check=True).stdout.decode().split()[-1]