From a95218be5b2a2a2c9d10fc308792e2e3f0388943 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 3 Feb 2022 20:22:55 +0100 Subject: [PATCH 1/4] Edge TPU compiler sudo fix Allows for auto-install of Edge TPU compiler on non-sudo systems like the YOLOv5 Docker image. @kalenmike --- export.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/export.py b/export.py index 09c50baa415a..a5e154707263 100644 --- a/export.py +++ b/export.py @@ -318,13 +318,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}' + sudo = subprocess.run('sudo --help', shell=True).returncode == 0 # sudo installed on system if subprocess.run(cmd, shell=True).returncode != 0: LOGGER.info(f'\n{prefix} export requires Edge TPU compiler. Attempting install from {help_url}') 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) + subprocess.run(c if sudo else c.replace('sudo ', ''), shell=True, check=True) 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 351af8cba036b61d24b9ed9cb278dc7e1bae9322 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 3 Feb 2022 20:34:50 +0100 Subject: [PATCH 2/4] Update export.py --- export.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/export.py b/export.py index a5e154707263..2d9ae5210f8c 100644 --- a/export.py +++ b/export.py @@ -318,9 +318,9 @@ 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}' - sudo = subprocess.run('sudo --help', shell=True).returncode == 0 # sudo installed on system if subprocess.run(cmd, shell=True).returncode != 0: LOGGER.info(f'\n{prefix} export requires Edge TPU compiler. Attempting install from {help_url}') + sudo = subprocess.run('sudo --help', shell=True).returncode == 0 # sudo installed on system 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', From a88a3c64f74a910e913b4c30f8bbd02b4793026f Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 3 Feb 2022 20:38:59 +0100 Subject: [PATCH 3/4] Update export.py --- export.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/export.py b/export.py index 2d9ae5210f8c..d001edbc1a54 100644 --- a/export.py +++ b/export.py @@ -315,17 +315,19 @@ def export_tflite(keras_model, im, file, int8, data, ncalib, prefix=colorstr('Te 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' + cmd = 'edgetpu_compiler --version >/dev/null' help_url = 'https://coral.ai/docs/edgetpu/compiler/' 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}') - sudo = subprocess.run('sudo --help', shell=True).returncode == 0 # sudo installed on system + sudo = subprocess.run('sudo --version >/dev/null', shell=True).returncode == 0 # sudo installed on system 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 if sudo else c.replace('sudo ', ''), shell=True, check=True) + c_ = c if sudo else c.replace('sudo ', '') + print(c_) + subprocess.run(c_, shell=True, check=True) 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 ecda93b383c43c4d81329c54f413ee3fd0a687bb Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 3 Feb 2022 20:39:28 +0100 Subject: [PATCH 4/4] Update export.py --- export.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/export.py b/export.py index d001edbc1a54..6fcab69139d7 100644 --- a/export.py +++ b/export.py @@ -325,9 +325,7 @@ def export_edgetpu(keras_model, im, file, prefix=colorstr('Edge TPU:')): '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']: - c_ = c if sudo else c.replace('sudo ', '') - print(c_) - subprocess.run(c_, shell=True, check=True) + subprocess.run(c if sudo else c.replace('sudo ', ''), shell=True, check=True) 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}...')