glenn-jocher
commited on
Commit
•
b4ac3df
1
Parent(s):
00d7b97
Add `edgetpu_compiler` checks (#6218)
Browse files* Add `edgetpu_compiler` checks
* Update export.py
* Update export.py
* Update export.py
* Update export.py
* Update export.py
* Update export.py
export.py
CHANGED
@@ -41,6 +41,7 @@ TensorFlow.js:
|
|
41 |
import argparse
|
42 |
import json
|
43 |
import os
|
|
|
44 |
import subprocess
|
45 |
import sys
|
46 |
import time
|
@@ -307,11 +308,15 @@ def export_tflite(keras_model, im, file, int8, data, ncalib, prefix=colorstr('Te
|
|
307 |
def export_edgetpu(keras_model, im, file, prefix=colorstr('Edge TPU:')):
|
308 |
# YOLOv5 Edge TPU export https://coral.ai/docs/edgetpu/models-intro/
|
309 |
try:
|
310 |
-
cmd = 'edgetpu_compiler --version'
|
|
|
|
|
|
|
311 |
out = subprocess.run(cmd, shell=True, capture_output=True, check=True)
|
312 |
ver = out.stdout.decode().split()[-1]
|
|
|
313 |
LOGGER.info(f'\n{prefix} starting export with Edge TPU compiler {ver}...')
|
314 |
-
f = str(file).replace('.pt', '-int8_edgetpu.tflite')
|
315 |
f_tfl = str(file).replace('.pt', '-int8.tflite') # TFLite model
|
316 |
|
317 |
cmd = f"edgetpu_compiler -s {f_tfl}"
|
@@ -434,7 +439,7 @@ def run(data=ROOT / 'data/coco128.yaml', # 'dataset.yaml path'
|
|
434 |
# TensorFlow Exports
|
435 |
if any(tf_exports):
|
436 |
pb, tflite, edgetpu, tfjs = tf_exports[1:]
|
437 |
-
if
|
438 |
check_requirements(('flatbuffers==1.12',)) # required before `import tensorflow`
|
439 |
assert not (tflite and tfjs), 'TFLite and TF.js models must be exported separately, please pass only one type.'
|
440 |
model = export_saved_model(model, im, file, dynamic, tf_nms=nms or agnostic_nms or tfjs,
|
|
|
41 |
import argparse
|
42 |
import json
|
43 |
import os
|
44 |
+
import platform
|
45 |
import subprocess
|
46 |
import sys
|
47 |
import time
|
|
|
308 |
def export_edgetpu(keras_model, im, file, prefix=colorstr('Edge TPU:')):
|
309 |
# YOLOv5 Edge TPU export https://coral.ai/docs/edgetpu/models-intro/
|
310 |
try:
|
311 |
+
cmd = 'edgetpu_compiler --version'
|
312 |
+
help = 'See https://coral.ai/docs/edgetpu/compiler/'
|
313 |
+
assert platform.system() == 'Linux', f'export only supported on Linux. {help}'
|
314 |
+
assert subprocess.run(cmd, shell=True).returncode == 0, f'export requires edgetpu-compiler. {help}'
|
315 |
out = subprocess.run(cmd, shell=True, capture_output=True, check=True)
|
316 |
ver = out.stdout.decode().split()[-1]
|
317 |
+
|
318 |
LOGGER.info(f'\n{prefix} starting export with Edge TPU compiler {ver}...')
|
319 |
+
f = str(file).replace('.pt', '-int8_edgetpu.tflite') # Edge TPU model
|
320 |
f_tfl = str(file).replace('.pt', '-int8.tflite') # TFLite model
|
321 |
|
322 |
cmd = f"edgetpu_compiler -s {f_tfl}"
|
|
|
439 |
# TensorFlow Exports
|
440 |
if any(tf_exports):
|
441 |
pb, tflite, edgetpu, tfjs = tf_exports[1:]
|
442 |
+
if int8 or edgetpu: # TFLite --int8 bug https://github.com/ultralytics/yolov5/issues/5707
|
443 |
check_requirements(('flatbuffers==1.12',)) # required before `import tensorflow`
|
444 |
assert not (tflite and tfjs), 'TFLite and TF.js models must be exported separately, please pass only one type.'
|
445 |
model = export_saved_model(model, im, file, dynamic, tf_nms=nms or agnostic_nms or tfjs,
|