Commit Graph

163 Commits (f56355d3210f3b6448834e4d48fba458b9fcb150)

Author SHA1 Message Date
daquexian 92e47b85d9
Upgrade onnxsim to v0.4.1 (#8632)
* upgrade onnxsim to v0.4.1

Signed-off-by: daquexian <daquexian566@gmail.com>

* Update export.py

* Update export.py

* Update export.py

* Update export.py

* Update export.py

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
2022-07-19 19:01:24 +02:00
Colin Wong f4b05680f8
Assert `--optimize` not used with cuda device (#8569) 2022-07-15 16:01:01 +02:00
Glenn Jocher c215e87393
XML export `--half` fix (#8522)
Improved error reporting for https://github.com/ultralytics/yolov5/issues/8519
2022-07-08 13:49:20 +02:00
Glenn Jocher 63ba0cb18a
Add `--half` arguments to export.py Usage examples (#8516) 2022-07-08 00:46:56 +02:00
Glenn Jocher 3e54651fca
Add `--hard-fail` argument to benchmarks for CI errors (#8513)
* Add `--hard-fail` list argument to benchmarks for CI

Will cause CI to fail on a benchmark failure for given indices.

* Update ci-testing.yml

* Attempt Failure (CI should fail)

* Update benchmarks.py

* Update export.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update benchmarks.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update ci-testing.yml

* Update benchmarks.py

* Update benchmarks.py

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-07-07 23:41:34 +02:00
Glenn Jocher 0c1324067c
Fix ONNX `--dynamic` export on GPU (#8378)
* Fix ONNX `--dynamic` export on GPU

Patch forces --dynamic export model and image to CPU. Resolves bug raised in https://github.com/ultralytics/yolov5/issues/8377

* Update export.py
2022-06-28 15:22:15 +02:00
Sahil Chachra 6dd6aea086
Fix FP32 TensorRT model export (#8046)
Fixed FP32 TRT  model export

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
2022-05-31 12:41:09 +02:00
Glenn Jocher 945579699a
Remove `formats` variable to avoid `pd` conflict (#7993)
* Remove `formats` variable to avoid `pd` conflict

* Update export.py
2022-05-26 16:07:58 +02:00
Glenn Jocher c215878f11
YOLOv5 Apple Metal Performance Shader (MPS) support (#7878)
* Apple Metal Performance Shader (MPS) device support

Following https://pytorch.org/blog/introducing-accelerated-pytorch-training-on-mac/

Should work with Apple M1 devices with PyTorch nightly installed with command `--device mps`. Usage examples:
```bash
python train.py --device mps
python detect.py --device mps
python val.py --device mps
```

* Update device strategy to fix MPS issue
2022-05-24 13:34:32 +02:00
xylieong 27911dc824
OpenVINO metadata fix2 (#7954)
* Bug Fixed: OpenVINO metadata

* Bug Fixed: OpenVINO metadata

* Update export.py

* Update export.py

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
2022-05-24 13:19:25 +02:00
Glenn Jocher 0dd66e2dc7
OpenVINO metadata fix (#7952)
* Rename OpenVINO meta.yaml to model name

* Rename OpenVINO meta.yaml to model name

* Rename OpenVINO meta.yaml to model name

* fix
2022-05-24 11:59:59 +02:00
xylieong a3a652c933
Add OpenVINO metadata to export (#7947)
* Write .yaml file when exporting model to openvino

Write .yaml file automatically when exporting model to openvino to be used during inference

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update export.py

* Update export.py

* Load metadata on inference

* Update common.py

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
2022-05-24 11:30:36 +02:00
Glenn Jocher 547c89b3a0
Add `--keras` argument for TF exports (#7921)
Resolves https://github.com/ultralytics/yolov5/issues/7911#issuecomment-1133671255
2022-05-22 13:33:36 +02:00
Jaewon Lee fe1b503cbb
Removed shell=True from subprocess commands that require user inputs (#7875)
* Removed shell=True from subprocess commands that require user inputs. Also removed unused arguments

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Added check=True

* Revert line add

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
2022-05-19 11:49:13 +02:00
Glenn Jocher f00071416f
Refactor collections and fstrings (#7821)
* Update torch_utils.py

* Additional code refactoring

* tuples to sets

* Cleanup
2022-05-15 16:38:26 +02:00
Glenn Jocher 9d8ed37df7
Rename `utils/datasets.py` > `utils/dataloaders.py` (#7799) 2022-05-13 14:34:16 +02:00
Glenn Jocher d4ea61e043
FROM nvcr.io/nvidia/pytorch:22.04-py3 (#7680)
* FROM nvcr.io/nvidia/pytorch:22.04-py3

* Update Docker

* Update Docker

* Update Docker

* Update Docker

* Update TRT auto-install

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Cleanup

* Cleanup

* Cleanup cpu

* Cleanup cpu

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-05-03 13:47:30 -07:00
David Matos bff6e51bc4
Disallow `--dynamic` when `--half` is passed (#7669)
* disallow dynamic arg when half is given

* Update export.py

Co-authored-by: David Matos <david@track32.nl>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
2022-05-02 09:00:24 -07:00
Duncan Moss 177da7f348
Add `--half` support for OpenVINO exports (#7615)
* feature(export): add half support for openvino models

* Update export.py

* Update export.py

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
2022-04-27 17:29:59 -07:00
Glenn Jocher 1f1ec1c3e7
Restrict TRT autoinstall to Linux-only (#7549)
May partially resolve concerns in https://github.com/ultralytics/yolov5/pull/7537#discussion_r856843711
2022-04-23 09:36:36 -07:00
Glenn Jocher f62609eb52
Update check_requirements() with `cmds=()` argument (#7543) 2022-04-22 14:31:05 -07:00
Glenn Jocher cc1d7df03c
Autoinstall TensorRT if missing (#7537)
* Autoinstall TensorRT if missing

May resolve https://github.com/ultralytics/yolov5/issues/7464

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update export.py

* Update export.py

* Update export.py

* Update export.py

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-04-22 12:31:33 -07:00
Cedric Perauer 7926afccde
Add `--half` support for FP16 CoreML exports with (#7446)
* add fp16 for coreml using --half

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix

* Cleanup

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update export.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
2022-04-16 18:00:50 +02:00
Glenn Jocher 3eefab1bb1
Remove `tensorrt` pip install check (#7439) 2022-04-15 21:48:52 +02:00
Glenn Jocher 2da2466168
Fix EdgeTPU output directory (#7399)
* Fix EdgeTPU output directory

Outputs to same directory as --weights

* Update export.py
2022-04-12 15:08:53 +02:00
Glenn Jocher 5333b55e74
Remove OpenVINO ONNX `opset<=12` check (#7398)
No longer needed.
2022-04-12 14:57:50 +02:00
Glenn Jocher 3bb233a7fb
Add ONNX export metadata (#7353) 2022-04-09 13:27:49 +02:00
Glenn Jocher 446e6f563a
Rename 'MacOS' to 'macOS' (#7349) 2022-04-08 23:05:15 +02:00
Glenn Jocher d257c75c84
Update export.py (#7301)
* Update export.py

Simplify code.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-04-05 21:21:57 +02:00
Glenn Jocher 5f97001ed4
Context manager `open(file) as f` fixes (#7289)
* Flask context manager `open()` fix

* Additional read context manager fixes
2022-04-05 12:54:25 +02:00
leeflix 8d0291f3af
Enable TensorFlow ops for `--nms` and `--agnostic-nms` (#7281)
* enable TensorFlow ops if flag --nms or --agnostic-nms is used

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update export.py

* Update export.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
2022-04-05 11:33:08 +02:00
Glenn Jocher 8bc839ed8e
TorchScript single-output fix (#7261) 2022-04-03 22:51:11 +02:00
Glenn Jocher 05cf0d1a44
Export single output only (#7259)
* Update

* Update

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-04-03 21:29:20 +02:00
Glenn Jocher ffcbd8ca97
Export with official `nn.SiLU()` (#7256)
* Update

* Update time_limit
2022-04-03 18:45:05 +02:00
Glenn Jocher 734ab033fd
SavedModel TF Serve Fix (#7228)
* SavedModel TF Serve Fix

Fix for https://github.com/ultralytics/yolov5/issues/7205 proposed by @tylertroy

* Update export.py
2022-04-01 00:07:23 +02:00
Glenn Jocher 2c3221844b
CLI `fire` prep updates (#7229)
* CLI fire prep updates

* revert unintentional TF export change
2022-03-31 17:11:43 +02:00
Jirka Borovec c3d5ac151e
precommit: yapf (#5494)
* precommit: yapf

* align isort

* fix

# Conflicts:
#	utils/plots.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update setup.cfg

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update setup.cfg

* Update setup.cfg

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update wandb_utils.py

* Update augmentations.py

* Update setup.cfg

* Update yolo.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update val.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* simplify colorstr

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* val run fix

* export.py last comma

* Update export.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update hubconf.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* PyTorch Hub tuple fix

* PyTorch Hub tuple fix2

* PyTorch Hub tuple fix3

* Update setup

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
2022-03-31 16:52:34 +02:00
Glenn Jocher e19f87eb4b
Sidestep `os.path.relpath()` Windows bug (#7158)
* Sidestep os.path.relpath() Windows bug

os.path.relpath() seems to have a major bug on Windows due to Windows horrible path handling. This fix attempts to sidestep the issue.

```
File "C:\Users\mkokg/.cache\torch\hub\ultralytics_yolov5_master\export.py", line 64, in
ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative
File "C:\Users\mkokg\AppData\Local\Programs\Python\Python310\lib\ntpath.py", line 718, in relpath
raise ValueError("path is on mount %r, start on mount %r" % (
ValueError: path is on mount 'C:', start on mount 'D:'
```

* Update yolo.py

* Update yolo.py

* Update yolo.py

* Update export.py
2022-03-26 14:18:53 +01:00
Mrinal Jain 4effd064b1
Consistent saved_model output format (#7032) 2022-03-18 12:29:24 +01:00
Glenn Jocher 932dc78496
YOLOv5 Export Benchmarks for GPU (#6963)
* Add benchmarks.py GPU support

* Updates

* Updates

* Updates

* Updates

* Add --half

* Add TRT requirements

* Cleanup

* Add TF to warmup types

* Update export.py

* Update export.py

* Update benchmarks.py
2022-03-14 15:07:13 +01:00
Glenn Jocher 99de551f97
pt model to cpu on TF export 2022-03-14 12:41:06 +01:00
paradigm c13d4ce7ef
EdgeTPU optimizations (#6808)
* removed transpose op for better edgetpu support

* fix for training case

* enabled experimental new quantizer flag

* precalculate add and mul ops at compile time

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
2022-03-12 16:15:09 +01:00
Glenn Jocher acc58c1dcf
Fix TRT `max_workspace_size` deprecation notice (#6856)
* Fix TRT `max_workspace_size` deprecation notice

* Update export.py

* Update export.py
2022-03-07 13:52:53 +01:00
DavidB 596de6d5a0
Default FP16 TensorRT export (#6798)
* Assert engine precision #6777

* Default to FP32 inputs for TensorRT engines

* Default to FP16 TensorRT exports #6777

* Remove wrong line #6777

* Automatically adjust detect.py input precision #6777

* Automatically adjust val.py input precision #6777

* Add missing colon

* Cleanup

* Cleanup

* Remove default trt_fp16_input definition

* Experiment

* Reorder detect.py if statement to after half checks

* Update common.py

* Update export.py

* Cleanup

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
2022-03-06 21:21:16 +01:00
Louis Combaldieu b2adc7c39a
Fix export for 1-channel images (#6780)
Export failed for 1-channel input shape, 1-liner fix
2022-02-25 10:56:37 +01:00
Glenn Jocher de9c25b35e
Use `export_formats()` in export.py (#6705)
* Use `export_formats()` in export.py

* list fix
2022-02-19 16:08:33 +01:00
Jiacong Fang 66e5d794c7
Fix TF exports >= 2GB (#6292)
* Fix exporting saved_model: pb exceeds 2GB

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Replace TF v1.x API with TF v2.x API for saved_model export

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Clean up

* Remove lambda in tf.function()

* Revert "Remove lambda in tf.function()" to be compatible with TF v2.4

This reverts commit 46c7931f11dfdea6ae340c77287c35c30b9e0779.

* Fix for pre-commit.ci

* Cleanup1

* Cleanup2

* Backwards compatibility update

* Update common.py

* Update common.py

* Cleanup3

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
2022-02-18 16:36:45 +01:00
Glenn Jocher a45e472358
YOLOv5 Export Benchmarks (#6613)
* Add benchmarks.py

* Update

* Add requirements

* Updates

* Updates

* Updates

* Updates

* Updates

* Updates

* dataset autodownload from root

* Update

* Redirect to /dev/null

* sudo --help

* Cleanup

* Add exports pd df

* Updates

* Updates

* Updates

* Cleanup

* dir handling fix

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Cleanup

* Cleanup2

* Cleanup3

* Cleanup model_type

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-02-12 16:05:43 +01:00
Glenn Jocher 22da63e30f
Fix zero-export handling with `if any(f):` (#6569)
* Fix zero-export handling with `if any(f):`

Partial fix for https://github.com/ultralytics/yolov5/issues/6563

* Cleanup
2022-02-08 12:20:39 +01:00
Jirka Borovec cba4303d32
Fix 6 Flake8 issues (#6541)
* F541

* F821

* F841

* E741

* E302

* E722

* Apply suggestions from code review

* Update general.py

* Update datasets.py

* Update export.py

* Update plots.py

* Update plots.py

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
2022-02-05 15:22:59 +01:00
Glenn Jocher 9bc72a3ac2
Edge TPU export 'list index out of range' fix (#6533) 2022-02-04 00:04:06 +01:00
Glenn Jocher 8d05716b66
Edge TPU compiler `sudo` fix (#6531)
* Edge TPU compiler sudo fix

Allows for auto-install of Edge TPU compiler on non-sudo systems like the YOLOv5 Docker image.

@kalenmike

* Update export.py

* Update export.py

* Update export.py
2022-02-03 20:40:09 +01:00
Glenn Jocher 4c40933266
Suppress export.run() TracerWarnings (#6499)
Suppresses warnings when calling export.run() directly, not just CLI python export.py.

Also adds Requirements examples for CPU and GPU backends
2022-02-01 23:52:50 +01:00
Glenn Jocher 842d049e1b
Suppress `torch.jit.TracerWarning` on export (#6498)
* Suppress torch.jit.TracerWarning

TracerWarnings can be safely ignored.

* Cleanup
2022-02-01 22:59:26 +01:00
Glenn Jocher 5e4ff195b2
Improved `export.py` usage examples (#6495)
* Improved `export.py` usage examples

* Cleanup
2022-02-01 22:06:29 +01:00
Glenn Jocher 750c42e43e
`export.py` automatic `forward_export` (#6352)
* `export.py` automatic `forward_export`

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-01-19 12:24:40 -10:00
Glenn Jocher 0cf932bf63
`export.py` return exported files/dirs (#6343)
* `export.py` return exported files/dirs

* Path to str
2022-01-18 15:18:23 -10:00
Glenn Jocher e2e95b2d8e
TensorRT `assert im.device.type != 'cpu'` on export (#6340)
* TensorRT `assert im.device.type != 'cpu'` on export

* Update export.py
2022-01-18 13:52:25 -10:00
Glenn Jocher fd55271c04
Console corrupted -> corrupt (#6338)
* Console corrupted -> corrupt 

Minor style changes.

* Update export.py
2022-01-18 10:49:26 -10:00
Glenn Jocher 80473a6551
Update `export.py` with Detect, Validate usages (#6280) 2022-01-12 15:48:40 -10:00
Jinwoong Yoo 9b13a594e9
Fix `cmd` string on `tfjs` export (#6243)
* Fix cmd string on tfjs export

* Cleanup

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
2022-01-09 20:40:47 -10:00
Glenn Jocher 6865d19a92
TensorRT 7 export fix (#6235) 2022-01-07 09:31:17 -08:00
Glenn Jocher f80c463010
Attempt `edgetpu-compiler` autoinstall (#6223)
* Attempt `edgetpu-compiler` autoinstall

Attempt to install edgetpu-compiler dependency if missing on Linux.

* Update export.py

* Update export.py
2022-01-05 20:57:20 -08:00
Glenn Jocher b4ac3df6ff
Add `edgetpu_compiler` checks (#6218)
* Add `edgetpu_compiler` checks

* Update export.py

* Update export.py

* Update export.py

* Update export.py

* Update export.py

* Update export.py
2022-01-05 14:55:04 -08:00
Glenn Jocher 00d7b97869
TFLite `--int8` 'flatbuffers==1.12' fix 2 (#6217)
* TFLite `--int8` 'flatbuffers==1.12' fix 2

Reorganizes #6216 fix to update before `tensorflow` import so no restart required.

* Update export.py
2022-01-05 13:34:36 -08:00
Glenn Jocher 8125ec5d42
TFLite `--int8` 'flatbuffers==1.12' fix (#6216)
* TFLite `--int8` 'flatbuffers==1.12' fix

Temporary workaround for TFLite INT8 export.

* Update export.py

* Update export.py
2022-01-05 13:01:21 -08:00
Glenn Jocher 5402753a53
Edge TPU compiler comment (#6196)
* Edge TPU compiler comment

* 7 to 8 fix
2022-01-04 19:36:12 -08:00
Glenn Jocher b5b56a3c88
Add CoreML inference (#6195)
* Add Apple CoreML inference

* Cleanup
2022-01-04 17:49:09 -08:00
Glenn Jocher 7b31a531b4
Add `tensorrt>=7.0.0` checks (#6193)
* Add `tensorrt>=7.0.0` checks

* Update export.py

* Update common.py

* Update export.py
2022-01-04 13:39:13 -08:00
imyhxy a2f4a1799b
TensorRT 7 `anchor_grid` compatibility fix (#6185)
* fix: TensorRT 7 incompatiable

* Add comment

* Add if: else and comment

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
2022-01-04 11:09:25 -08:00
Yin Rong fb839298a1
Fix TorchScript on mobile export (#6183)
* fix export of TorchScript on mobile

* Cleanup

Co-authored-by: yinrong <yinrong@xiaomi.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
2022-01-03 20:25:48 -08:00
Glenn Jocher 5bd6a97b18
Global export format sort (#6182)
* Global export sort

* Cleanup
2022-01-03 20:08:15 -08:00
Glenn Jocher 63a4d862aa
Add OpenVINO inference (#6179) 2022-01-03 15:41:26 -08:00
Glenn Jocher ec4b6dd2a3
Update export format docstrings (#6151)
* Update export documentation

* Cleanup

* Update export.py

* Update README.md

* Update README.md

* Update README.md

* Update README.md

* Update README.md

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update README.md

* Update README.md

* Update README.md

* Update train.py

* Update train.py

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-01-02 16:09:45 -08:00
Jiacong Fang d95978a562
Add EdgeTPU support (#3630)
* Add models/tf.py for TensorFlow and TFLite export

* Set auto=False for int8 calibration

* Update requirements.txt for TensorFlow and TFLite export

* Read anchors directly from PyTorch weights

* Add --tf-nms to append NMS in TensorFlow SavedModel and GraphDef export

* Remove check_anchor_order, check_file, set_logging from import

* Reformat code and optimize imports

* Autodownload model and check cfg

* update --source path, img-size to 320, single output

* Adjust representative_dataset

* Put representative dataset in tfl_int8 block

* detect.py TF inference

* weights to string

* weights to string

* cleanup tf.py

* Add --dynamic-batch-size

* Add xywh normalization to reduce calibration error

* Update requirements.txt

TensorFlow 2.3.1 -> 2.4.0 to avoid int8 quantization error

* Fix imports

Move C3 from models.experimental to models.common

* Add models/tf.py for TensorFlow and TFLite export

* Set auto=False for int8 calibration

* Update requirements.txt for TensorFlow and TFLite export

* Read anchors directly from PyTorch weights

* Add --tf-nms to append NMS in TensorFlow SavedModel and GraphDef export

* Remove check_anchor_order, check_file, set_logging from import

* Reformat code and optimize imports

* Autodownload model and check cfg

* update --source path, img-size to 320, single output

* Adjust representative_dataset

* detect.py TF inference

* Put representative dataset in tfl_int8 block

* weights to string

* weights to string

* cleanup tf.py

* Add --dynamic-batch-size

* Add xywh normalization to reduce calibration error

* Update requirements.txt

TensorFlow 2.3.1 -> 2.4.0 to avoid int8 quantization error

* Fix imports

Move C3 from models.experimental to models.common

* implement C3() and SiLU()

* Add TensorFlow and TFLite Detection

* Add --tfl-detect for TFLite Detection

* Add int8 quantized TFLite inference in detect.py

* Add --edgetpu for Edge TPU detection

* Fix --img-size to add rectangle TensorFlow and TFLite input

* Add --no-tf-nms to detect objects using models combined with TensorFlow NMS

* Fix --img-size list type input

* Update README.md

* Add Android project for TFLite inference

* Upgrade TensorFlow v2.3.1 -> v2.4.0

* Disable normalization of xywh

* Rewrite names init in detect.py

* Change input resolution 640 -> 320 on Android

* Disable NNAPI

* Update README.me --img 640 -> 320

* Update README.me for Edge TPU

* Update README.md

* Fix reshape dim to support dynamic batching

* Fix reshape dim to support dynamic batching

* Add epsilon argument in tf_BN, which is different between TF and PT

* Set stride to None if not using PyTorch, and do not warmup without PyTorch

* Add list support in check_img_size()

* Add list input support in detect.py

* sys.path.append('./') to run from yolov5/

* Add int8 quantization support for TensorFlow 2.5

* Add get_coco128.sh

* Remove --no-tfl-detect in models/tf.py (Use tf-android-tfl-detect branch for EdgeTPU)

* Update requirements.txt

* Replace torch.load() with attempt_load()

* Update requirements.txt

* Add --tf-raw-resize to set half_pixel_centers=False

* Remove android directory

* Update README.md

* Update README.md

* Add multiple OS support for EdgeTPU detection

* Fix export and detect

* Export 3 YOLO heads with Edge TPU models

* Remove xywh denormalization with Edge TPU models in detect.py

* Fix saved_model and pb detect error

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix pre-commit.ci failure

* Add edgetpu in export.py docstring

* Fix Edge TPU model detection exported by TF 2.7

* Add class names for TF/TFLite in DetectMultibackend

* Fix assignment with nl in TFLite Detection

* Add check when getting Edge TPU compiler version

* Add UTF-8 encoding in opening --data file for Windows

* Remove redundant TensorFlow import

* Add Edge TPU in export.py's docstring

* Add the detect layer in Edge TPU model conversion

* Default `dnn=False`

* Cleanup data.yaml loading

* Update detect.py

* Update val.py

* Comments and generalize data.yaml names

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
Co-authored-by: unknown <fangjiacong@ut.cn>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2021-12-31 09:47:52 -08:00
Glenn Jocher 95c7bc25d3
OpenVINO Export (#6057)
* OpenVINO export

* Remove timeout

* Add 3 files

* str

* Constrain opset to 12

* Default ONNX opset to 12

* Make dir

* Make dir

* Cleanup

* Cleanup

* check_requirements(('openvino-dev',))
2021-12-22 20:29:48 +01:00
Diego Montes 2c6317547a
Add nms and agnostic nms to export.py (#5938)
* add nms and agnostic nms to export.py

* fix agnostic implies nms

* reorder args to group TF args

* PEP8 120 char

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
2021-12-10 18:24:32 +01:00
Diego Montes 4fb6dd4b26
Fix ONNX opset inconsistency with parseargs and run args (#5937) 2021-12-09 23:10:16 +01:00
Glenn Jocher 1075488d89
Single-command multiple-model export (#5882)
* Export multiple models in series

Export multiple models in series by adding additional `*.pt` files to the `--weights` argument, i.e.:

```bash
python export.py --include tflite --weights yolov5n.pt  # export 1 model
python export.py --include tflite --weights yolov5n.pt yolov5s.pt yolov5m.pt yolov5l.pt yolov5x.pt  # export 5 models
```

* Update export.py

* Update README.md
2021-12-04 16:28:40 +01:00
Glenn Jocher 7bf04d9bbf
`AutoShape()` models as `DetectMultiBackend()` instances (#5845)
* Update AutoShape()

* autodownload ONNX

* Cleanup

* Finish updates

* Add Usage

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* fix device

* Update hubconf.py

* Update common.py

* smart param selection

* autodownload all formats

* autopad only pytorch models

* new_shape edits

* stride tensor fix

* Cleanup
2021-12-04 15:00:07 +01:00
Glenn Jocher 00e308f7be
Update TorchScript suffix to `*.torchscript` (#5856) 2021-12-02 16:06:45 +01:00
imyhxy a4207a202d
Fix TensorRT potential unordered binding addresses (#5826)
* feat: change file suffix in pythonic way

* fix: enforce binding addresses order

* fix: enforce binding addresses order
2021-11-30 13:52:22 +01:00
rockstarr 4c7b2bdc30
TorchScript `torch==1.7.0` Path support (#5781)
* fix path error in export.py

* Update export.py

updated!

* Update export.py

oops forget something
2021-11-25 11:18:30 +01:00
imyhxy 7a39803476
Export, detect and validation with TensorRT engine file (#5699)
* Export and detect with TensorRT engine file

* Resolve `isort`

* Make validation works with TensorRT engine

* feat: update export docstring

* feat: change suffix from *.trt to *.engine

* feat: get rid of pycuda

* feat: make compatiable with val.py

* feat: support detect with fp16 engine

* Add Lite to Edge TPU string

* Remove *.trt comment

* Revert to standard success logger.info string

* Fix Deprecation Warning

```
export.py:310: DeprecationWarning: Use build_serialized_network instead.
  with builder.build_engine(network, config) as engine, open(f, 'wb') as t:
```

* Revert deprecation warning fix

@imyhxy it seems we can't apply the deprecation warning fix because then export fails, so I'm reverting my previous change here.

* Update export.py

* Update export.py

* Update common.py

* export onnx to file before building TensorRT engine file

* feat: triger ONNX export failed early

* feat: load ONNX model from file

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
2021-11-22 14:58:07 +01:00
Glenn Jocher 562191f575
Update export.py docstring (#5689) 2021-11-17 15:18:50 +01:00
Glenn Jocher 3883261143
New `DetectMultiBackend()` class (#5549)
* New `DetectMultiBackend()` class

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* pb to pt fix

* Cleanup

* explicit apply_classifier path

* Cleanup2

* Cleanup3

* Cleanup4

* Cleanup5

* Cleanup6

* val.py MultiBackend inference

* warmup fix

* to device fix

* pt fix

* device fix

* Val cleanup

* COCO128 URL to assets

* half fix

* detect fix

* detect fix 2

* remove half from DetectMultiBackend

* training half handling

* training half handling 2

* training half handling 3

* Cleanup

* Fix CI error

* Add torchscript _extra_files

* Add TorchScript

* Add CoreML

* CoreML cleanup

* New `DetectMultiBackend()` class

* pb to pt fix

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Cleanup

* explicit apply_classifier path

* Cleanup2

* Cleanup3

* Cleanup4

* Cleanup5

* Cleanup6

* val.py MultiBackend inference

* warmup fix

* to device fix

* pt fix

* device fix

* Val cleanup

* COCO128 URL to assets

* half fix

* detect fix

* detect fix 2

* remove half from DetectMultiBackend

* training half handling

* training half handling 2

* training half handling 3

* Cleanup

* Fix CI error

* Add torchscript _extra_files

* Add TorchScript

* Add CoreML

* CoreML cleanup

* revert default to pt

* Add Usage examples

* Cleanup val

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2021-11-09 16:45:02 +01:00
Jirka Borovec 0155548384
precommit: isort (#5493)
* precommit: isort

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update isort config

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update name

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
2021-11-04 17:24:25 +01:00
Glenn Jocher 5866646cc8
Fix float zeros format (#5491)
* Fix float zeros format

* 255 to integer
2021-11-03 23:36:53 +01:00
Glenn Jocher 7b1f7aec46
Update `get_loggers()` (#4854)
* Update `set_logging()`

* Update export.py

* pre-commit fixes

* Update LoadImages

* Update LoadStreams

* Update print_args

* Single LOGGER definition

* yolo.py fix

Co-authored-by: pre-commit <pre-commit@example.com>
2021-11-01 18:22:13 +01:00
Malte Lorbach 153873e9e4
Fix `ROOT` as relative path (#5129)
* use os.path.relpath instead of relative_to

* use os.path.relpath instead of relative_to

* Remove os.path from val.py

* Remove os.path from train.py

* Update detect.py import to os

* Update export.py import to os

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
2021-10-11 09:47:24 -07:00
Glenn Jocher 4e04cb0dc8
Allow YOLOv5 execution from arbitrary `cwd` (#4954)
* Allow YOLOv5 execution from arbitrary `cwd`

* Fix str bugs
2021-09-27 17:40:20 -07:00
Jiacong Fang 2c2ef25f8b
TensorFlow.js export enhancements (#4905)
* Add arguments to TensorFlow NMS call

* Add regex substitution to reorder Identity_*

* Delete reorder in docstring

* Cleanup

* Cleanup2

* Removed `+ \` on string ends (not needed)

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
2021-09-24 14:18:15 -07:00
Glenn Jocher 4d1a2ac87e
Update `sys.path.append(str(ROOT))` (#4852)
* Update `sys.path.append(str(ROOT))`

* Cleanup
2021-09-18 15:02:08 +02:00
Glenn Jocher 3732f9ac8a
Refactor argparser printing to `print_args()` (#4850)
* Refactor argparser printing to `print_args()`

* Cleanup
2021-09-18 14:16:19 +02:00
Jiacong Fang 3beb871ba4
Multiple TF export improvements (#4824)
* Add fused conv support

* Set all saved_model values to non trainable

* Fix TFLite fp16 model export

* Fix int8 TFLite conversion
2021-09-16 15:27:22 +02:00
Glenn Jocher 6b44ecd53d
Fix 'PyTorch starting from' for URL weights (#4828)
Follows #4823
2021-09-16 14:38:35 +02:00
Kalen Michael 43b2817f6e
Feature/fix export on url (#4823)
* added callbacks

* added back callback to main

* added save_dir to callback output

* merged in upstream

* removed ghost code

* added url check

* Add url2file()

* Update file-only

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
2021-09-16 13:33:54 +02:00
Glenn Jocher b74dd4ba4f
Add `--int8` argument (#4799)
* Add `--int8` argument

* parents[0] bug fix

* Fix order
2021-09-15 11:33:46 +02:00
Glenn Jocher c3a93d783d
Add TensorFlow formats to `export.py` (#4479)
* Initial commit

* Remove unused export_torchscript return

* ROOT variable

* Add prefix to fcn arg

* fix ROOT

* check_yaml into run()

* interim fixes

* imgsz=(320, 320)

* Hardcode tf_raw_resize False

* Finish opt elimination

* Update representative_dataset_gen()

* Update export.py with TF methods

* SiLU and GraphDef fixes

* file_size() directory handling feature

* export fixes

* add lambda: to representative_dataset

* Detect training False default

* Fuse false for TF models

* Embed agnostic NMS arguments

* Remove lambda

* TensorFlow.js export success

* Add pb to Usage

* Add *_tfjs_model/ to ignore files

* prepend YOLOv5 to function headers

* Remove end --- comments

* parameterize tfjs export pb file

* update run() data default /ROOT

* update --include help

* update imports

* return ct_model

* Consolidate TFLite export

* pb prerequisite to tfjs

* TF modules CamelCase

* Remove exports from tf.py and cleanup

* pass agnostic NMS arguments

* CI

* CI

* ignore *_web_model/

* Add tensorflow to CI dependencies

* CI tensorflow-cpu

* Update requirements.txt

* Remove tensorflow check_requirement

* CI coreml tfjs

* export only onnx torchscript

* reorder exports torchscript first
2021-09-12 15:52:24 +02:00
Glenn Jocher c47be26f34
Replace `path.absolute()` with `path.resolve()` (#4763) 2021-09-11 22:46:33 +02:00