Instructions to use nnopt-dev/YOLO11n-TensorRT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- TensorRT
How to use nnopt-dev/YOLO11n-TensorRT with TensorRT:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
nnopt port: YOLO11n-TensorRT
Browse files- .gitattributes +17 -32
- LICENSE +661 -0
- NOTICE +6 -0
- README.md +70 -0
- config.json +34 -0
- orin-nano-gpu-int8/build.sh +12 -0
- orin-nano-gpu-int8/deploy.sh +15 -0
- orin-nano-gpu-int8/fetch.sh +28 -0
- orin-nano-gpu-int8/report.html +0 -0
- orin-nano-gpu-int8/report/reproduce.sh +14 -0
- orin-nano-gpu-int8/report/results.csv +71 -0
- orin-nano-gpu-int8/report/results.json +0 -0
- orin-nano-gpu-int8/src/build_engine.py +457 -0
- orin-nano-gpu-int8/src/calib/act_amax.json +0 -0
- orin-nano-gpu-int8/src/cudart.py +64 -0
- orin-nano-gpu-int8/src/export_weights.py +160 -0
- orin-nano-gpu-int8/src/port.json +1 -0
- orin-nano-gpu-int8/src/prepost.py +101 -0
- orin-nano-gpu-int8/src/run.py +99 -0
- orin-nano-gpu-int8/src/run.sh +4 -0
- orin-nano-gpu-int8/src/tools/calib_stats.py +44 -0
- orin-nano-gpu-int8/src/tools/sensitivity.py +96 -0
.gitattributes
CHANGED
|
@@ -1,35 +1,20 @@
|
|
| 1 |
-
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
-
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
-
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
-
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
-
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
-
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
-
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
-
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
-
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
-
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
-
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
-
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
-
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
-
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
-
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
-
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
-
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
-
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
-
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
-
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
-
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
-
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
-
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
-
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
-
*.
|
| 31 |
-
*.
|
| 32 |
-
*.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
-
*.
|
| 35 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
*.bin filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.gguf filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.wav filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.so filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.bf16 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.f16 filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.f32 filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.tkb filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.png filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.jpg filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.pdf filter=lfs diff=lfs merge=lfs -text
|
| 17 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
LICENSE
ADDED
|
@@ -0,0 +1,661 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
GNU AFFERO GENERAL PUBLIC LICENSE
|
| 2 |
+
Version 3, 19 November 2007
|
| 3 |
+
|
| 4 |
+
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
| 5 |
+
Everyone is permitted to copy and distribute verbatim copies
|
| 6 |
+
of this license document, but changing it is not allowed.
|
| 7 |
+
|
| 8 |
+
Preamble
|
| 9 |
+
|
| 10 |
+
The GNU Affero General Public License is a free, copyleft license for
|
| 11 |
+
software and other kinds of works, specifically designed to ensure
|
| 12 |
+
cooperation with the community in the case of network server software.
|
| 13 |
+
|
| 14 |
+
The licenses for most software and other practical works are designed
|
| 15 |
+
to take away your freedom to share and change the works. By contrast,
|
| 16 |
+
our General Public Licenses are intended to guarantee your freedom to
|
| 17 |
+
share and change all versions of a program--to make sure it remains free
|
| 18 |
+
software for all its users.
|
| 19 |
+
|
| 20 |
+
When we speak of free software, we are referring to freedom, not
|
| 21 |
+
price. Our General Public Licenses are designed to make sure that you
|
| 22 |
+
have the freedom to distribute copies of free software (and charge for
|
| 23 |
+
them if you wish), that you receive source code or can get it if you
|
| 24 |
+
want it, that you can change the software or use pieces of it in new
|
| 25 |
+
free programs, and that you know you can do these things.
|
| 26 |
+
|
| 27 |
+
Developers that use our General Public Licenses protect your rights
|
| 28 |
+
with two steps: (1) assert copyright on the software, and (2) offer
|
| 29 |
+
you this License which gives you legal permission to copy, distribute
|
| 30 |
+
and/or modify the software.
|
| 31 |
+
|
| 32 |
+
A secondary benefit of defending all users' freedom is that
|
| 33 |
+
improvements made in alternate versions of the program, if they
|
| 34 |
+
receive widespread use, become available for other developers to
|
| 35 |
+
incorporate. Many developers of free software are heartened and
|
| 36 |
+
encouraged by the resulting cooperation. However, in the case of
|
| 37 |
+
software used on network servers, this result may fail to come about.
|
| 38 |
+
The GNU General Public License permits making a modified version and
|
| 39 |
+
letting the public access it on a server without ever releasing its
|
| 40 |
+
source code to the public.
|
| 41 |
+
|
| 42 |
+
The GNU Affero General Public License is designed specifically to
|
| 43 |
+
ensure that, in such cases, the modified source code becomes available
|
| 44 |
+
to the community. It requires the operator of a network server to
|
| 45 |
+
provide the source code of the modified version running there to the
|
| 46 |
+
users of that server. Therefore, public use of a modified version, on
|
| 47 |
+
a publicly accessible server, gives the public access to the source
|
| 48 |
+
code of the modified version.
|
| 49 |
+
|
| 50 |
+
An older license, called the Affero General Public License and
|
| 51 |
+
published by Affero, was designed to accomplish similar goals. This is
|
| 52 |
+
a different license, not a version of the Affero GPL, but Affero has
|
| 53 |
+
released a new version of the Affero GPL which permits relicensing under
|
| 54 |
+
this license.
|
| 55 |
+
|
| 56 |
+
The precise terms and conditions for copying, distribution and
|
| 57 |
+
modification follow.
|
| 58 |
+
|
| 59 |
+
TERMS AND CONDITIONS
|
| 60 |
+
|
| 61 |
+
0. Definitions.
|
| 62 |
+
|
| 63 |
+
"This License" refers to version 3 of the GNU Affero General Public License.
|
| 64 |
+
|
| 65 |
+
"Copyright" also means copyright-like laws that apply to other kinds of
|
| 66 |
+
works, such as semiconductor masks.
|
| 67 |
+
|
| 68 |
+
"The Program" refers to any copyrightable work licensed under this
|
| 69 |
+
License. Each licensee is addressed as "you". "Licensees" and
|
| 70 |
+
"recipients" may be individuals or organizations.
|
| 71 |
+
|
| 72 |
+
To "modify" a work means to copy from or adapt all or part of the work
|
| 73 |
+
in a fashion requiring copyright permission, other than the making of an
|
| 74 |
+
exact copy. The resulting work is called a "modified version" of the
|
| 75 |
+
earlier work or a work "based on" the earlier work.
|
| 76 |
+
|
| 77 |
+
A "covered work" means either the unmodified Program or a work based
|
| 78 |
+
on the Program.
|
| 79 |
+
|
| 80 |
+
To "propagate" a work means to do anything with it that, without
|
| 81 |
+
permission, would make you directly or secondarily liable for
|
| 82 |
+
infringement under applicable copyright law, except executing it on a
|
| 83 |
+
computer or modifying a private copy. Propagation includes copying,
|
| 84 |
+
distribution (with or without modification), making available to the
|
| 85 |
+
public, and in some countries other activities as well.
|
| 86 |
+
|
| 87 |
+
To "convey" a work means any kind of propagation that enables other
|
| 88 |
+
parties to make or receive copies. Mere interaction with a user through
|
| 89 |
+
a computer network, with no transfer of a copy, is not conveying.
|
| 90 |
+
|
| 91 |
+
An interactive user interface displays "Appropriate Legal Notices"
|
| 92 |
+
to the extent that it includes a convenient and prominently visible
|
| 93 |
+
feature that (1) displays an appropriate copyright notice, and (2)
|
| 94 |
+
tells the user that there is no warranty for the work (except to the
|
| 95 |
+
extent that warranties are provided), that licensees may convey the
|
| 96 |
+
work under this License, and how to view a copy of this License. If
|
| 97 |
+
the interface presents a list of user commands or options, such as a
|
| 98 |
+
menu, a prominent item in the list meets this criterion.
|
| 99 |
+
|
| 100 |
+
1. Source Code.
|
| 101 |
+
|
| 102 |
+
The "source code" for a work means the preferred form of the work
|
| 103 |
+
for making modifications to it. "Object code" means any non-source
|
| 104 |
+
form of a work.
|
| 105 |
+
|
| 106 |
+
A "Standard Interface" means an interface that either is an official
|
| 107 |
+
standard defined by a recognized standards body, or, in the case of
|
| 108 |
+
interfaces specified for a particular programming language, one that
|
| 109 |
+
is widely used among developers working in that language.
|
| 110 |
+
|
| 111 |
+
The "System Libraries" of an executable work include anything, other
|
| 112 |
+
than the work as a whole, that (a) is included in the normal form of
|
| 113 |
+
packaging a Major Component, but which is not part of that Major
|
| 114 |
+
Component, and (b) serves only to enable use of the work with that
|
| 115 |
+
Major Component, or to implement a Standard Interface for which an
|
| 116 |
+
implementation is available to the public in source code form. A
|
| 117 |
+
"Major Component", in this context, means a major essential component
|
| 118 |
+
(kernel, window system, and so on) of the specific operating system
|
| 119 |
+
(if any) on which the executable work runs, or a compiler used to
|
| 120 |
+
produce the work, or an object code interpreter used to run it.
|
| 121 |
+
|
| 122 |
+
The "Corresponding Source" for a work in object code form means all
|
| 123 |
+
the source code needed to generate, install, and (for an executable
|
| 124 |
+
work) run the object code and to modify the work, including scripts to
|
| 125 |
+
control those activities. However, it does not include the work's
|
| 126 |
+
System Libraries, or general-purpose tools or generally available free
|
| 127 |
+
programs which are used unmodified in performing those activities but
|
| 128 |
+
which are not part of the work. For example, Corresponding Source
|
| 129 |
+
includes interface definition files associated with source files for
|
| 130 |
+
the work, and the source code for shared libraries and dynamically
|
| 131 |
+
linked subprograms that the work is specifically designed to require,
|
| 132 |
+
such as by intimate data communication or control flow between those
|
| 133 |
+
subprograms and other parts of the work.
|
| 134 |
+
|
| 135 |
+
The Corresponding Source need not include anything that users
|
| 136 |
+
can regenerate automatically from other parts of the Corresponding
|
| 137 |
+
Source.
|
| 138 |
+
|
| 139 |
+
The Corresponding Source for a work in source code form is that
|
| 140 |
+
same work.
|
| 141 |
+
|
| 142 |
+
2. Basic Permissions.
|
| 143 |
+
|
| 144 |
+
All rights granted under this License are granted for the term of
|
| 145 |
+
copyright on the Program, and are irrevocable provided the stated
|
| 146 |
+
conditions are met. This License explicitly affirms your unlimited
|
| 147 |
+
permission to run the unmodified Program. The output from running a
|
| 148 |
+
covered work is covered by this License only if the output, given its
|
| 149 |
+
content, constitutes a covered work. This License acknowledges your
|
| 150 |
+
rights of fair use or other equivalent, as provided by copyright law.
|
| 151 |
+
|
| 152 |
+
You may make, run and propagate covered works that you do not
|
| 153 |
+
convey, without conditions so long as your license otherwise remains
|
| 154 |
+
in force. You may convey covered works to others for the sole purpose
|
| 155 |
+
of having them make modifications exclusively for you, or provide you
|
| 156 |
+
with facilities for running those works, provided that you comply with
|
| 157 |
+
the terms of this License in conveying all material for which you do
|
| 158 |
+
not control copyright. Those thus making or running the covered works
|
| 159 |
+
for you must do so exclusively on your behalf, under your direction
|
| 160 |
+
and control, on terms that prohibit them from making any copies of
|
| 161 |
+
your copyrighted material outside their relationship with you.
|
| 162 |
+
|
| 163 |
+
Conveying under any other circumstances is permitted solely under
|
| 164 |
+
the conditions stated below. Sublicensing is not allowed; section 10
|
| 165 |
+
makes it unnecessary.
|
| 166 |
+
|
| 167 |
+
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
| 168 |
+
|
| 169 |
+
No covered work shall be deemed part of an effective technological
|
| 170 |
+
measure under any applicable law fulfilling obligations under article
|
| 171 |
+
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
| 172 |
+
similar laws prohibiting or restricting circumvention of such
|
| 173 |
+
measures.
|
| 174 |
+
|
| 175 |
+
When you convey a covered work, you waive any legal power to forbid
|
| 176 |
+
circumvention of technological measures to the extent such circumvention
|
| 177 |
+
is effected by exercising rights under this License with respect to
|
| 178 |
+
the covered work, and you disclaim any intention to limit operation or
|
| 179 |
+
modification of the work as a means of enforcing, against the work's
|
| 180 |
+
users, your or third parties' legal rights to forbid circumvention of
|
| 181 |
+
technological measures.
|
| 182 |
+
|
| 183 |
+
4. Conveying Verbatim Copies.
|
| 184 |
+
|
| 185 |
+
You may convey verbatim copies of the Program's source code as you
|
| 186 |
+
receive it, in any medium, provided that you conspicuously and
|
| 187 |
+
appropriately publish on each copy an appropriate copyright notice;
|
| 188 |
+
keep intact all notices stating that this License and any
|
| 189 |
+
non-permissive terms added in accord with section 7 apply to the code;
|
| 190 |
+
keep intact all notices of the absence of any warranty; and give all
|
| 191 |
+
recipients a copy of this License along with the Program.
|
| 192 |
+
|
| 193 |
+
You may charge any price or no price for each copy that you convey,
|
| 194 |
+
and you may offer support or warranty protection for a fee.
|
| 195 |
+
|
| 196 |
+
5. Conveying Modified Source Versions.
|
| 197 |
+
|
| 198 |
+
You may convey a work based on the Program, or the modifications to
|
| 199 |
+
produce it from the Program, in the form of source code under the
|
| 200 |
+
terms of section 4, provided that you also meet all of these conditions:
|
| 201 |
+
|
| 202 |
+
a) The work must carry prominent notices stating that you modified
|
| 203 |
+
it, and giving a relevant date.
|
| 204 |
+
|
| 205 |
+
b) The work must carry prominent notices stating that it is
|
| 206 |
+
released under this License and any conditions added under section
|
| 207 |
+
7. This requirement modifies the requirement in section 4 to
|
| 208 |
+
"keep intact all notices".
|
| 209 |
+
|
| 210 |
+
c) You must license the entire work, as a whole, under this
|
| 211 |
+
License to anyone who comes into possession of a copy. This
|
| 212 |
+
License will therefore apply, along with any applicable section 7
|
| 213 |
+
additional terms, to the whole of the work, and all its parts,
|
| 214 |
+
regardless of how they are packaged. This License gives no
|
| 215 |
+
permission to license the work in any other way, but it does not
|
| 216 |
+
invalidate such permission if you have separately received it.
|
| 217 |
+
|
| 218 |
+
d) If the work has interactive user interfaces, each must display
|
| 219 |
+
Appropriate Legal Notices; however, if the Program has interactive
|
| 220 |
+
interfaces that do not display Appropriate Legal Notices, your
|
| 221 |
+
work need not make them do so.
|
| 222 |
+
|
| 223 |
+
A compilation of a covered work with other separate and independent
|
| 224 |
+
works, which are not by their nature extensions of the covered work,
|
| 225 |
+
and which are not combined with it such as to form a larger program,
|
| 226 |
+
in or on a volume of a storage or distribution medium, is called an
|
| 227 |
+
"aggregate" if the compilation and its resulting copyright are not
|
| 228 |
+
used to limit the access or legal rights of the compilation's users
|
| 229 |
+
beyond what the individual works permit. Inclusion of a covered work
|
| 230 |
+
in an aggregate does not cause this License to apply to the other
|
| 231 |
+
parts of the aggregate.
|
| 232 |
+
|
| 233 |
+
6. Conveying Non-Source Forms.
|
| 234 |
+
|
| 235 |
+
You may convey a covered work in object code form under the terms
|
| 236 |
+
of sections 4 and 5, provided that you also convey the
|
| 237 |
+
machine-readable Corresponding Source under the terms of this License,
|
| 238 |
+
in one of these ways:
|
| 239 |
+
|
| 240 |
+
a) Convey the object code in, or embodied in, a physical product
|
| 241 |
+
(including a physical distribution medium), accompanied by the
|
| 242 |
+
Corresponding Source fixed on a durable physical medium
|
| 243 |
+
customarily used for software interchange.
|
| 244 |
+
|
| 245 |
+
b) Convey the object code in, or embodied in, a physical product
|
| 246 |
+
(including a physical distribution medium), accompanied by a
|
| 247 |
+
written offer, valid for at least three years and valid for as
|
| 248 |
+
long as you offer spare parts or customer support for that product
|
| 249 |
+
model, to give anyone who possesses the object code either (1) a
|
| 250 |
+
copy of the Corresponding Source for all the software in the
|
| 251 |
+
product that is covered by this License, on a durable physical
|
| 252 |
+
medium customarily used for software interchange, for a price no
|
| 253 |
+
more than your reasonable cost of physically performing this
|
| 254 |
+
conveying of source, or (2) access to copy the
|
| 255 |
+
Corresponding Source from a network server at no charge.
|
| 256 |
+
|
| 257 |
+
c) Convey individual copies of the object code with a copy of the
|
| 258 |
+
written offer to provide the Corresponding Source. This
|
| 259 |
+
alternative is allowed only occasionally and noncommercially, and
|
| 260 |
+
only if you received the object code with such an offer, in accord
|
| 261 |
+
with subsection 6b.
|
| 262 |
+
|
| 263 |
+
d) Convey the object code by offering access from a designated
|
| 264 |
+
place (gratis or for a charge), and offer equivalent access to the
|
| 265 |
+
Corresponding Source in the same way through the same place at no
|
| 266 |
+
further charge. You need not require recipients to copy the
|
| 267 |
+
Corresponding Source along with the object code. If the place to
|
| 268 |
+
copy the object code is a network server, the Corresponding Source
|
| 269 |
+
may be on a different server (operated by you or a third party)
|
| 270 |
+
that supports equivalent copying facilities, provided you maintain
|
| 271 |
+
clear directions next to the object code saying where to find the
|
| 272 |
+
Corresponding Source. Regardless of what server hosts the
|
| 273 |
+
Corresponding Source, you remain obligated to ensure that it is
|
| 274 |
+
available for as long as needed to satisfy these requirements.
|
| 275 |
+
|
| 276 |
+
e) Convey the object code using peer-to-peer transmission, provided
|
| 277 |
+
you inform other peers where the object code and Corresponding
|
| 278 |
+
Source of the work are being offered to the general public at no
|
| 279 |
+
charge under subsection 6d.
|
| 280 |
+
|
| 281 |
+
A separable portion of the object code, whose source code is excluded
|
| 282 |
+
from the Corresponding Source as a System Library, need not be
|
| 283 |
+
included in conveying the object code work.
|
| 284 |
+
|
| 285 |
+
A "User Product" is either (1) a "consumer product", which means any
|
| 286 |
+
tangible personal property which is normally used for personal, family,
|
| 287 |
+
or household purposes, or (2) anything designed or sold for incorporation
|
| 288 |
+
into a dwelling. In determining whether a product is a consumer product,
|
| 289 |
+
doubtful cases shall be resolved in favor of coverage. For a particular
|
| 290 |
+
product received by a particular user, "normally used" refers to a
|
| 291 |
+
typical or common use of that class of product, regardless of the status
|
| 292 |
+
of the particular user or of the way in which the particular user
|
| 293 |
+
actually uses, or expects or is expected to use, the product. A product
|
| 294 |
+
is a consumer product regardless of whether the product has substantial
|
| 295 |
+
commercial, industrial or non-consumer uses, unless such uses represent
|
| 296 |
+
the only significant mode of use of the product.
|
| 297 |
+
|
| 298 |
+
"Installation Information" for a User Product means any methods,
|
| 299 |
+
procedures, authorization keys, or other information required to install
|
| 300 |
+
and execute modified versions of a covered work in that User Product from
|
| 301 |
+
a modified version of its Corresponding Source. The information must
|
| 302 |
+
suffice to ensure that the continued functioning of the modified object
|
| 303 |
+
code is in no case prevented or interfered with solely because
|
| 304 |
+
modification has been made.
|
| 305 |
+
|
| 306 |
+
If you convey an object code work under this section in, or with, or
|
| 307 |
+
specifically for use in, a User Product, and the conveying occurs as
|
| 308 |
+
part of a transaction in which the right of possession and use of the
|
| 309 |
+
User Product is transferred to the recipient in perpetuity or for a
|
| 310 |
+
fixed term (regardless of how the transaction is characterized), the
|
| 311 |
+
Corresponding Source conveyed under this section must be accompanied
|
| 312 |
+
by the Installation Information. But this requirement does not apply
|
| 313 |
+
if neither you nor any third party retains the ability to install
|
| 314 |
+
modified object code on the User Product (for example, the work has
|
| 315 |
+
been installed in ROM).
|
| 316 |
+
|
| 317 |
+
The requirement to provide Installation Information does not include a
|
| 318 |
+
requirement to continue to provide support service, warranty, or updates
|
| 319 |
+
for a work that has been modified or installed by the recipient, or for
|
| 320 |
+
the User Product in which it has been modified or installed. Access to a
|
| 321 |
+
network may be denied when the modification itself materially and
|
| 322 |
+
adversely affects the operation of the network or violates the rules and
|
| 323 |
+
protocols for communication across the network.
|
| 324 |
+
|
| 325 |
+
Corresponding Source conveyed, and Installation Information provided,
|
| 326 |
+
in accord with this section must be in a format that is publicly
|
| 327 |
+
documented (and with an implementation available to the public in
|
| 328 |
+
source code form), and must require no special password or key for
|
| 329 |
+
unpacking, reading or copying.
|
| 330 |
+
|
| 331 |
+
7. Additional Terms.
|
| 332 |
+
|
| 333 |
+
"Additional permissions" are terms that supplement the terms of this
|
| 334 |
+
License by making exceptions from one or more of its conditions.
|
| 335 |
+
Additional permissions that are applicable to the entire Program shall
|
| 336 |
+
be treated as though they were included in this License, to the extent
|
| 337 |
+
that they are valid under applicable law. If additional permissions
|
| 338 |
+
apply only to part of the Program, that part may be used separately
|
| 339 |
+
under those permissions, but the entire Program remains governed by
|
| 340 |
+
this License without regard to the additional permissions.
|
| 341 |
+
|
| 342 |
+
When you convey a copy of a covered work, you may at your option
|
| 343 |
+
remove any additional permissions from that copy, or from any part of
|
| 344 |
+
it. (Additional permissions may be written to require their own
|
| 345 |
+
removal in certain cases when you modify the work.) You may place
|
| 346 |
+
additional permissions on material, added by you to a covered work,
|
| 347 |
+
for which you have or can give appropriate copyright permission.
|
| 348 |
+
|
| 349 |
+
Notwithstanding any other provision of this License, for material you
|
| 350 |
+
add to a covered work, you may (if authorized by the copyright holders of
|
| 351 |
+
that material) supplement the terms of this License with terms:
|
| 352 |
+
|
| 353 |
+
a) Disclaiming warranty or limiting liability differently from the
|
| 354 |
+
terms of sections 15 and 16 of this License; or
|
| 355 |
+
|
| 356 |
+
b) Requiring preservation of specified reasonable legal notices or
|
| 357 |
+
author attributions in that material or in the Appropriate Legal
|
| 358 |
+
Notices displayed by works containing it; or
|
| 359 |
+
|
| 360 |
+
c) Prohibiting misrepresentation of the origin of that material, or
|
| 361 |
+
requiring that modified versions of such material be marked in
|
| 362 |
+
reasonable ways as different from the original version; or
|
| 363 |
+
|
| 364 |
+
d) Limiting the use for publicity purposes of names of licensors or
|
| 365 |
+
authors of the material; or
|
| 366 |
+
|
| 367 |
+
e) Declining to grant rights under trademark law for use of some
|
| 368 |
+
trade names, trademarks, or service marks; or
|
| 369 |
+
|
| 370 |
+
f) Requiring indemnification of licensors and authors of that
|
| 371 |
+
material by anyone who conveys the material (or modified versions of
|
| 372 |
+
it) with contractual assumptions of liability to the recipient, for
|
| 373 |
+
any liability that these contractual assumptions directly impose on
|
| 374 |
+
those licensors and authors.
|
| 375 |
+
|
| 376 |
+
All other non-permissive additional terms are considered "further
|
| 377 |
+
restrictions" within the meaning of section 10. If the Program as you
|
| 378 |
+
received it, or any part of it, contains a notice stating that it is
|
| 379 |
+
governed by this License along with a term that is a further
|
| 380 |
+
restriction, you may remove that term. If a license document contains
|
| 381 |
+
a further restriction but permits relicensing or conveying under this
|
| 382 |
+
License, you may add to a covered work material governed by the terms
|
| 383 |
+
of that license document, provided that the further restriction does
|
| 384 |
+
not survive such relicensing or conveying.
|
| 385 |
+
|
| 386 |
+
If you add terms to a covered work in accord with this section, you
|
| 387 |
+
must place, in the relevant source files, a statement of the
|
| 388 |
+
additional terms that apply to those files, or a notice indicating
|
| 389 |
+
where to find the applicable terms.
|
| 390 |
+
|
| 391 |
+
Additional terms, permissive or non-permissive, may be stated in the
|
| 392 |
+
form of a separately written license, or stated as exceptions;
|
| 393 |
+
the above requirements apply either way.
|
| 394 |
+
|
| 395 |
+
8. Termination.
|
| 396 |
+
|
| 397 |
+
You may not propagate or modify a covered work except as expressly
|
| 398 |
+
provided under this License. Any attempt otherwise to propagate or
|
| 399 |
+
modify it is void, and will automatically terminate your rights under
|
| 400 |
+
this License (including any patent licenses granted under the third
|
| 401 |
+
paragraph of section 11).
|
| 402 |
+
|
| 403 |
+
However, if you cease all violation of this License, then your
|
| 404 |
+
license from a particular copyright holder is reinstated (a)
|
| 405 |
+
provisionally, unless and until the copyright holder explicitly and
|
| 406 |
+
finally terminates your license, and (b) permanently, if the copyright
|
| 407 |
+
holder fails to notify you of the violation by some reasonable means
|
| 408 |
+
prior to 60 days after the cessation.
|
| 409 |
+
|
| 410 |
+
Moreover, your license from a particular copyright holder is
|
| 411 |
+
reinstated permanently if the copyright holder notifies you of the
|
| 412 |
+
violation by some reasonable means, this is the first time you have
|
| 413 |
+
received notice of violation of this License (for any work) from that
|
| 414 |
+
copyright holder, and you cure the violation prior to 30 days after
|
| 415 |
+
your receipt of the notice.
|
| 416 |
+
|
| 417 |
+
Termination of your rights under this section does not terminate the
|
| 418 |
+
licenses of parties who have received copies or rights from you under
|
| 419 |
+
this License. If your rights have been terminated and not permanently
|
| 420 |
+
reinstated, you do not qualify to receive new licenses for the same
|
| 421 |
+
material under section 10.
|
| 422 |
+
|
| 423 |
+
9. Acceptance Not Required for Having Copies.
|
| 424 |
+
|
| 425 |
+
You are not required to accept this License in order to receive or
|
| 426 |
+
run a copy of the Program. Ancillary propagation of a covered work
|
| 427 |
+
occurring solely as a consequence of using peer-to-peer transmission
|
| 428 |
+
to receive a copy likewise does not require acceptance. However,
|
| 429 |
+
nothing other than this License grants you permission to propagate or
|
| 430 |
+
modify any covered work. These actions infringe copyright if you do
|
| 431 |
+
not accept this License. Therefore, by modifying or propagating a
|
| 432 |
+
covered work, you indicate your acceptance of this License to do so.
|
| 433 |
+
|
| 434 |
+
10. Automatic Licensing of Downstream Recipients.
|
| 435 |
+
|
| 436 |
+
Each time you convey a covered work, the recipient automatically
|
| 437 |
+
receives a license from the original licensors, to run, modify and
|
| 438 |
+
propagate that work, subject to this License. You are not responsible
|
| 439 |
+
for enforcing compliance by third parties with this License.
|
| 440 |
+
|
| 441 |
+
An "entity transaction" is a transaction transferring control of an
|
| 442 |
+
organization, or substantially all assets of one, or subdividing an
|
| 443 |
+
organization, or merging organizations. If propagation of a covered
|
| 444 |
+
work results from an entity transaction, each party to that
|
| 445 |
+
transaction who receives a copy of the work also receives whatever
|
| 446 |
+
licenses to the work the party's predecessor in interest had or could
|
| 447 |
+
give under the previous paragraph, plus a right to possession of the
|
| 448 |
+
Corresponding Source of the work from the predecessor in interest, if
|
| 449 |
+
the predecessor has it or can get it with reasonable efforts.
|
| 450 |
+
|
| 451 |
+
You may not impose any further restrictions on the exercise of the
|
| 452 |
+
rights granted or affirmed under this License. For example, you may
|
| 453 |
+
not impose a license fee, royalty, or other charge for exercise of
|
| 454 |
+
rights granted under this License, and you may not initiate litigation
|
| 455 |
+
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
| 456 |
+
any patent claim is infringed by making, using, selling, offering for
|
| 457 |
+
sale, or importing the Program or any portion of it.
|
| 458 |
+
|
| 459 |
+
11. Patents.
|
| 460 |
+
|
| 461 |
+
A "contributor" is a copyright holder who authorizes use under this
|
| 462 |
+
License of the Program or a work on which the Program is based. The
|
| 463 |
+
work thus licensed is called the contributor's "contributor version".
|
| 464 |
+
|
| 465 |
+
A contributor's "essential patent claims" are all patent claims
|
| 466 |
+
owned or controlled by the contributor, whether already acquired or
|
| 467 |
+
hereafter acquired, that would be infringed by some manner, permitted
|
| 468 |
+
by this License, of making, using, or selling its contributor version,
|
| 469 |
+
but do not include claims that would be infringed only as a
|
| 470 |
+
consequence of further modification of the contributor version. For
|
| 471 |
+
purposes of this definition, "control" includes the right to grant
|
| 472 |
+
patent sublicenses in a manner consistent with the requirements of
|
| 473 |
+
this License.
|
| 474 |
+
|
| 475 |
+
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
| 476 |
+
patent license under the contributor's essential patent claims, to
|
| 477 |
+
make, use, sell, offer for sale, import and otherwise run, modify and
|
| 478 |
+
propagate the contents of its contributor version.
|
| 479 |
+
|
| 480 |
+
In the following three paragraphs, a "patent license" is any express
|
| 481 |
+
agreement or commitment, however denominated, not to enforce a patent
|
| 482 |
+
(such as an express permission to practice a patent or covenant not to
|
| 483 |
+
sue for patent infringement). To "grant" such a patent license to a
|
| 484 |
+
party means to make such an agreement or commitment not to enforce a
|
| 485 |
+
patent against the party.
|
| 486 |
+
|
| 487 |
+
If you convey a covered work, knowingly relying on a patent license,
|
| 488 |
+
and the Corresponding Source of the work is not available for anyone
|
| 489 |
+
to copy, free of charge and under the terms of this License, through a
|
| 490 |
+
publicly available network server or other readily accessible means,
|
| 491 |
+
then you must either (1) cause the Corresponding Source to be so
|
| 492 |
+
available, or (2) arrange to deprive yourself of the benefit of the
|
| 493 |
+
patent license for this particular work, or (3) arrange, in a manner
|
| 494 |
+
consistent with the requirements of this License, to extend the patent
|
| 495 |
+
license to downstream recipients. "Knowingly relying" means you have
|
| 496 |
+
actual knowledge that, but for the patent license, your conveying the
|
| 497 |
+
covered work in a country, or your recipient's use of the covered work
|
| 498 |
+
in a country, would infringe one or more identifiable patents in that
|
| 499 |
+
country that you have reason to believe are valid.
|
| 500 |
+
|
| 501 |
+
If, pursuant to or in connection with a single transaction or
|
| 502 |
+
arrangement, you convey, or propagate by procuring conveyance of, a
|
| 503 |
+
covered work, and grant a patent license to some of the parties
|
| 504 |
+
receiving the covered work authorizing them to use, propagate, modify
|
| 505 |
+
or convey a specific copy of the covered work, then the patent license
|
| 506 |
+
you grant is automatically extended to all recipients of the covered
|
| 507 |
+
work and works based on it.
|
| 508 |
+
|
| 509 |
+
A patent license is "discriminatory" if it does not include within
|
| 510 |
+
the scope of its coverage, prohibits the exercise of, or is
|
| 511 |
+
conditioned on the non-exercise of one or more of the rights that are
|
| 512 |
+
specifically granted under this License. You may not convey a covered
|
| 513 |
+
work if you are a party to an arrangement with a third party that is
|
| 514 |
+
in the business of distributing software, under which you make payment
|
| 515 |
+
to the third party based on the extent of your activity of conveying
|
| 516 |
+
the work, and under which the third party grants, to any of the
|
| 517 |
+
parties who would receive the covered work from you, a discriminatory
|
| 518 |
+
patent license (a) in connection with copies of the covered work
|
| 519 |
+
conveyed by you (or copies made from those copies), or (b) primarily
|
| 520 |
+
for and in connection with specific products or compilations that
|
| 521 |
+
contain the covered work, unless you entered into that arrangement,
|
| 522 |
+
or that patent license was granted, prior to 28 March 2007.
|
| 523 |
+
|
| 524 |
+
Nothing in this License shall be construed as excluding or limiting
|
| 525 |
+
any implied license or other defenses to infringement that may
|
| 526 |
+
otherwise be available to you under applicable patent law.
|
| 527 |
+
|
| 528 |
+
12. No Surrender of Others' Freedom.
|
| 529 |
+
|
| 530 |
+
If conditions are imposed on you (whether by court order, agreement or
|
| 531 |
+
otherwise) that contradict the conditions of this License, they do not
|
| 532 |
+
excuse you from the conditions of this License. If you cannot convey a
|
| 533 |
+
covered work so as to satisfy simultaneously your obligations under this
|
| 534 |
+
License and any other pertinent obligations, then as a consequence you may
|
| 535 |
+
not convey it at all. For example, if you agree to terms that obligate you
|
| 536 |
+
to collect a royalty for further conveying from those to whom you convey
|
| 537 |
+
the Program, the only way you could satisfy both those terms and this
|
| 538 |
+
License would be to refrain entirely from conveying the Program.
|
| 539 |
+
|
| 540 |
+
13. Remote Network Interaction; Use with the GNU General Public License.
|
| 541 |
+
|
| 542 |
+
Notwithstanding any other provision of this License, if you modify the
|
| 543 |
+
Program, your modified version must prominently offer all users
|
| 544 |
+
interacting with it remotely through a computer network (if your version
|
| 545 |
+
supports such interaction) an opportunity to receive the Corresponding
|
| 546 |
+
Source of your version by providing access to the Corresponding Source
|
| 547 |
+
from a network server at no charge, through some standard or customary
|
| 548 |
+
means of facilitating copying of software. This Corresponding Source
|
| 549 |
+
shall include the Corresponding Source for any work covered by version 3
|
| 550 |
+
of the GNU General Public License that is incorporated pursuant to the
|
| 551 |
+
following paragraph.
|
| 552 |
+
|
| 553 |
+
Notwithstanding any other provision of this License, you have
|
| 554 |
+
permission to link or combine any covered work with a work licensed
|
| 555 |
+
under version 3 of the GNU General Public License into a single
|
| 556 |
+
combined work, and to convey the resulting work. The terms of this
|
| 557 |
+
License will continue to apply to the part which is the covered work,
|
| 558 |
+
but the work with which it is combined will remain governed by version
|
| 559 |
+
3 of the GNU General Public License.
|
| 560 |
+
|
| 561 |
+
14. Revised Versions of this License.
|
| 562 |
+
|
| 563 |
+
The Free Software Foundation may publish revised and/or new versions of
|
| 564 |
+
the GNU Affero General Public License from time to time. Such new versions
|
| 565 |
+
will be similar in spirit to the present version, but may differ in detail to
|
| 566 |
+
address new problems or concerns.
|
| 567 |
+
|
| 568 |
+
Each version is given a distinguishing version number. If the
|
| 569 |
+
Program specifies that a certain numbered version of the GNU Affero General
|
| 570 |
+
Public License "or any later version" applies to it, you have the
|
| 571 |
+
option of following the terms and conditions either of that numbered
|
| 572 |
+
version or of any later version published by the Free Software
|
| 573 |
+
Foundation. If the Program does not specify a version number of the
|
| 574 |
+
GNU Affero General Public License, you may choose any version ever published
|
| 575 |
+
by the Free Software Foundation.
|
| 576 |
+
|
| 577 |
+
If the Program specifies that a proxy can decide which future
|
| 578 |
+
versions of the GNU Affero General Public License can be used, that proxy's
|
| 579 |
+
public statement of acceptance of a version permanently authorizes you
|
| 580 |
+
to choose that version for the Program.
|
| 581 |
+
|
| 582 |
+
Later license versions may give you additional or different
|
| 583 |
+
permissions. However, no additional obligations are imposed on any
|
| 584 |
+
author or copyright holder as a result of your choosing to follow a
|
| 585 |
+
later version.
|
| 586 |
+
|
| 587 |
+
15. Disclaimer of Warranty.
|
| 588 |
+
|
| 589 |
+
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
| 590 |
+
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
| 591 |
+
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
| 592 |
+
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
| 593 |
+
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
| 594 |
+
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
| 595 |
+
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
| 596 |
+
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
| 597 |
+
|
| 598 |
+
16. Limitation of Liability.
|
| 599 |
+
|
| 600 |
+
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
| 601 |
+
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
| 602 |
+
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
| 603 |
+
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
| 604 |
+
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
| 605 |
+
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
| 606 |
+
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
| 607 |
+
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
| 608 |
+
SUCH DAMAGES.
|
| 609 |
+
|
| 610 |
+
17. Interpretation of Sections 15 and 16.
|
| 611 |
+
|
| 612 |
+
If the disclaimer of warranty and limitation of liability provided
|
| 613 |
+
above cannot be given local legal effect according to their terms,
|
| 614 |
+
reviewing courts shall apply local law that most closely approximates
|
| 615 |
+
an absolute waiver of all civil liability in connection with the
|
| 616 |
+
Program, unless a warranty or assumption of liability accompanies a
|
| 617 |
+
copy of the Program in return for a fee.
|
| 618 |
+
|
| 619 |
+
END OF TERMS AND CONDITIONS
|
| 620 |
+
|
| 621 |
+
How to Apply These Terms to Your New Programs
|
| 622 |
+
|
| 623 |
+
If you develop a new program, and you want it to be of the greatest
|
| 624 |
+
possible use to the public, the best way to achieve this is to make it
|
| 625 |
+
free software which everyone can redistribute and change under these terms.
|
| 626 |
+
|
| 627 |
+
To do so, attach the following notices to the program. It is safest
|
| 628 |
+
to attach them to the start of each source file to most effectively
|
| 629 |
+
state the exclusion of warranty; and each file should have at least
|
| 630 |
+
the "copyright" line and a pointer to where the full notice is found.
|
| 631 |
+
|
| 632 |
+
<one line to give the program's name and a brief idea of what it does.>
|
| 633 |
+
Copyright (C) <year> <name of author>
|
| 634 |
+
|
| 635 |
+
This program is free software: you can redistribute it and/or modify
|
| 636 |
+
it under the terms of the GNU Affero General Public License as published by
|
| 637 |
+
the Free Software Foundation, either version 3 of the License, or
|
| 638 |
+
(at your option) any later version.
|
| 639 |
+
|
| 640 |
+
This program is distributed in the hope that it will be useful,
|
| 641 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 642 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 643 |
+
GNU Affero General Public License for more details.
|
| 644 |
+
|
| 645 |
+
You should have received a copy of the GNU Affero General Public License
|
| 646 |
+
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
| 647 |
+
|
| 648 |
+
Also add information on how to contact you by electronic and paper mail.
|
| 649 |
+
|
| 650 |
+
If your software can interact with users remotely through a computer
|
| 651 |
+
network, you should also make sure that it provides a way for users to
|
| 652 |
+
get its source. For example, if your program is a web application, its
|
| 653 |
+
interface could display a "Source" link that leads users to an archive
|
| 654 |
+
of the code. There are many ways you could offer source, and different
|
| 655 |
+
solutions will be better for different programs; see section 13 for the
|
| 656 |
+
specific requirements.
|
| 657 |
+
|
| 658 |
+
You should also get your employer (if you work as a programmer) or school,
|
| 659 |
+
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
| 660 |
+
For more information on this, and how to apply and follow the GNU AGPL, see
|
| 661 |
+
<https://www.gnu.org/licenses/>.
|
NOTICE
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
This repository is a modified version of Ultralytics/YOLO11 by Ultralytics, revision v8.3.0 (yolo11n.pt, sha256 0ebbc80d4a7680d14987a577cd21342b65ecfd94632bd9a8da63ae6417644ee1).
|
| 2 |
+
|
| 3 |
+
Changes, made by nnopt (https://nnopt.dev):
|
| 4 |
+
- `orin-nano-gpu-int8/` (nnopt job NN-373FB4): fetched: fetch.sh downloads yolo11n.pt from Ultralytics; the INT8 engine is built on the Jetson by deploy.sh. The runtime code (src/, build.sh, deploy.sh, run.sh) is new, written by nnopt's agents for this device.
|
| 5 |
+
|
| 6 |
+
YOLO11n is Copyright Ultralytics and licensed under AGPL-3.0 (LICENSE). As AGPL-3.0 requires, the complete source of every modification is in this repository (src/, build.sh, deploy.sh). Ultralytics also offers an Enterprise License for uses that cannot follow AGPL-3.0: https://www.ultralytics.com/license
|
README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: agpl-3.0
|
| 3 |
+
base_model: Ultralytics/YOLO11
|
| 4 |
+
pipeline_tag: object-detection
|
| 5 |
+
tags:
|
| 6 |
+
- on-device
|
| 7 |
+
- nnopt
|
| 8 |
+
- tensorrt
|
| 9 |
+
- cuda
|
| 10 |
+
- jetson
|
| 11 |
+
- gpu
|
| 12 |
+
- int8
|
| 13 |
+
- object-detection
|
| 14 |
+
- jetson-orin-nano
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
# YOLO11n on NVIDIA Jetson Orin Nano (TensorRT)
|
| 18 |
+
|
| 19 |
+
Ported and verified on a real NVIDIA Jetson Orin Nano by [nnopt.dev](https://nnopt.dev) — AI agents that port and optimize models for the hardware you ship.
|
| 20 |
+
|
| 21 |
+
The model is [Ultralytics YOLO11n](https://huggingface.co/Ultralytics/YOLO11) (`yolo11n.pt` v8.3.0) by Ultralytics, and it is theirs. The TensorRT port in this repository is nnopt's work: nnopt job NN-373FB4.
|
| 22 |
+
|
| 23 |
+
| | |
|
| 24 |
+
|---|---|
|
| 25 |
+
| Device | NVIDIA Jetson Orin Nano, JetPack 6 (Linux) |
|
| 26 |
+
| Chip | Jetson Orin Nano |
|
| 27 |
+
| Processor | GPU (Jetson Orin Nano, CUDA) |
|
| 28 |
+
| Runtime | TensorRT 10.3 (Python API) + CUDA 12.6, JetPack 6 |
|
| 29 |
+
| Precision | int8 |
|
| 30 |
+
| Modality | image -> objects (detection) |
|
| 31 |
+
| Weights | fetched: fetch.sh downloads yolo11n.pt from Ultralytics; the INT8 engine is built on the Jetson by deploy.sh |
|
| 32 |
+
| nnopt job | NN-373FB4 (port) |
|
| 33 |
+
| Folder | [`orin-nano-gpu-int8/`](https://huggingface.co/nnopt-dev/YOLO11n-TensorRT/tree/main/orin-nano-gpu-int8) |
|
| 34 |
+
|
| 35 |
+
## Verified results
|
| 36 |
+
|
| 37 |
+
nnopt built the folder from a clean copy, deployed it to the device and checked it against the model's reference code on hidden inputs. The full report is `report.html` in the folder.
|
| 38 |
+
|
| 39 |
+
- Passed. mAP@0.5 vs reference 95.6% (bar at least 85.0%, int8 precision)
|
| 40 |
+
- Throughput 187 images/s
|
| 41 |
+
- Latency 5.4 ms
|
| 42 |
+
- Load time 519 ms
|
| 43 |
+
- Peak memory 455 MB
|
| 44 |
+
|
| 45 |
+
## Use it
|
| 46 |
+
|
| 47 |
+
```
|
| 48 |
+
mkdir YOLO11n-TensorRT && cd YOLO11n-TensorRT
|
| 49 |
+
curl -fsSL https://huggingface.co/nnopt-dev/YOLO11n-TensorRT/resolve/main/config.json -o config.json
|
| 50 |
+
hf download nnopt-dev/YOLO11n-TensorRT --include "orin-nano-gpu-int8/*" --local-dir .
|
| 51 |
+
cd orin-nano-gpu-int8
|
| 52 |
+
bash fetch.sh
|
| 53 |
+
NNOPT_WEIGHTS=$PWD/weights/yolo11n.pt bash build.sh # python3 with torch + numpy: module tree + BN-fused weights
|
| 54 |
+
bash deploy.sh nnopt/port # rsync to ssh host 'jetson', builds the INT8 TensorRT engine there (~10 min)
|
| 55 |
+
ssh jetson 'cd nnopt/port && sh ./run.sh --image bus.jpg --repeat 10 --out out.json --metrics m.json'
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
Needs: A build host with python3, torch and numpy; a Jetson Orin Nano with JetPack 6 (TensorRT 10.3, CUDA 12.6) reachable as ssh host `jetson`.
|
| 59 |
+
|
| 60 |
+
`README.md` in the folder has every flag, the requirements and the known limits; `REPRO.md` (where present) reproduces the measurements.
|
| 61 |
+
|
| 62 |
+
## License
|
| 63 |
+
|
| 64 |
+
AGPL-3.0, like Ultralytics YOLO11: see LICENSE and NOTICE. The full source of the port is in this repository. For uses that cannot follow AGPL-3.0, Ultralytics offers an Enterprise License.
|
| 65 |
+
|
| 66 |
+
## Made with nnopt
|
| 67 |
+
|
| 68 |
+
[nnopt](https://nnopt.dev) is a platform where AI agents port, optimize and benchmark a model for a specific device. They write the runtime code on the real device, and a locked verification kit then checks the result against the model's own reference code before anything ships. Every number on this page comes from that check.
|
| 69 |
+
|
| 70 |
+
Want your model on your device? Start a job at [nnopt.dev](https://nnopt.dev).
|
config.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"nnopt_manifest": 1,
|
| 3 |
+
"repo": "nnopt-dev/YOLO11n-TensorRT",
|
| 4 |
+
"model": {
|
| 5 |
+
"name": "YOLO11n",
|
| 6 |
+
"source_repo": "Ultralytics/YOLO11",
|
| 7 |
+
"source_revision": "v8.3.0 (yolo11n.pt, sha256 0ebbc80d4a7680d14987a577cd21342b65ecfd94632bd9a8da63ae6417644ee1)",
|
| 8 |
+
"source_file": "https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11n.pt",
|
| 9 |
+
"authors": "Ultralytics",
|
| 10 |
+
"license": "agpl-3.0"
|
| 11 |
+
},
|
| 12 |
+
"variants": [
|
| 13 |
+
{
|
| 14 |
+
"id": "orin-nano-gpu-int8",
|
| 15 |
+
"device": "NVIDIA Jetson Orin Nano",
|
| 16 |
+
"chip": "Jetson Orin Nano",
|
| 17 |
+
"os": "JetPack 6 (Linux)",
|
| 18 |
+
"processor": "GPU (Jetson Orin Nano, CUDA)",
|
| 19 |
+
"runtime": "TensorRT 10.3 (Python API) + CUDA 12.6, JetPack 6",
|
| 20 |
+
"runtime_version": "TensorRT 10.3",
|
| 21 |
+
"precision": "int8",
|
| 22 |
+
"weights": "fetched: fetch.sh downloads yolo11n.pt from Ultralytics; the INT8 engine is built on the Jetson by deploy.sh",
|
| 23 |
+
"nnopt_job": "NN-373FB4",
|
| 24 |
+
"job_kind": "port",
|
| 25 |
+
"verified": {
|
| 26 |
+
"verdict": "Passed. mAP@0.5 vs reference 95.6% (bar at least 85.0%, int8 precision)",
|
| 27 |
+
"speed": "Throughput 187 images/s; Latency 5.4 ms; Load time 519 ms; Peak memory 455 MB"
|
| 28 |
+
},
|
| 29 |
+
"fetch": "orin-nano-gpu-int8/fetch.sh"
|
| 30 |
+
}
|
| 31 |
+
],
|
| 32 |
+
"license": "agpl-3.0",
|
| 33 |
+
"made_by": "nnopt (https://nnopt.dev)"
|
| 34 |
+
}
|
orin-nano-gpu-int8/build.sh
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# Build host step: extract the customer's checkpoint into a module tree (model.json) + BN-fused fp32 weights
|
| 3 |
+
# (weights.npz). Needs only python3 with torch + numpy (no ultralytics). The TensorRT engine itself is built on
|
| 4 |
+
# the Jetson by deploy.sh (engines are device-specific).
|
| 5 |
+
set -euo pipefail
|
| 6 |
+
cd "$(dirname "$0")"
|
| 7 |
+
WEIGHTS="${NNOPT_WEIGHTS:-/work/inputs/weights/yolo11n.pt}"
|
| 8 |
+
rm -rf build && mkdir -p build/model
|
| 9 |
+
python3 -I src/export_weights.py "$WEIGHTS" build/model
|
| 10 |
+
cp src/run.py src/prepost.py src/cudart.py src/build_engine.py src/run.sh src/port.json build/
|
| 11 |
+
cp src/calib/act_amax.json build/model/act_amax.json
|
| 12 |
+
echo "build ok: $(ls build build/model | tr '\n' ' ')"
|
orin-nano-gpu-int8/deploy.sh
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# usage: bash deploy.sh DEST (DEST: folder on the Jetson, absolute or relative to the home folder)
|
| 3 |
+
# Copies the runtime + weights to DEST and builds the INT8 TensorRT engine there (DEST/model.engine).
|
| 4 |
+
set -euo pipefail
|
| 5 |
+
cd "$(dirname "$0")"
|
| 6 |
+
DEST="${1:?usage: deploy.sh DEST}"
|
| 7 |
+
SSH="ssh -o BatchMode=yes jetson"
|
| 8 |
+
[ -f build/model/weights.npz ] || { echo "run build.sh first" >&2; exit 1; }
|
| 9 |
+
$SSH "mkdir -p '$DEST'"
|
| 10 |
+
rsync -a --delete build/ "jetson:$DEST/"
|
| 11 |
+
# explicit INT8 (Q/DQ): activation ranges from src/calib/act_amax.json, per-channel weight scales, fp16 elsewhere
|
| 12 |
+
$SSH "cd '$DEST' && rm -f model.engine && python3 build_engine.py --model model --out model.engine \
|
| 13 |
+
--precision int8qdq --amax model/act_amax.json 2>&1 | grep -v -i -E 'deprecat|obedient|obeys'; test -s model.engine"
|
| 14 |
+
$SSH "cd '$DEST' && ls -la && test -f run.sh"
|
| 15 |
+
echo "deployed to jetson:$DEST"
|
orin-nano-gpu-int8/fetch.sh
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
# Run once after downloading this folder: bash fetch.sh
|
| 3 |
+
# Downloads Ultralytics' yolo11n.pt (v8.3.0, sha256-checked).
|
| 4 |
+
set -euo pipefail
|
| 5 |
+
cd "$(dirname "$0")"
|
| 6 |
+
REPO=nnopt-dev/YOLO11n-TensorRT
|
| 7 |
+
|
| 8 |
+
# The repository's manifest first (Hugging Face counts a download when config.json is requested).
|
| 9 |
+
curl -fsSL "https://huggingface.co/$REPO/resolve/main/config.json" -o ../config.json
|
| 10 |
+
|
| 11 |
+
sha256_of() { if command -v sha256sum >/dev/null 2>&1; then sha256sum "$1" | cut -d" " -f1; else shasum -a 256 "$1" | cut -d" " -f1; fi; }
|
| 12 |
+
get() { # get URL FILE SHA256: download once, check the sha256
|
| 13 |
+
if [ -f "$2" ] && [ "$(sha256_of "$2")" = "$3" ]; then return 0; fi
|
| 14 |
+
mkdir -p "$(dirname "$2")"
|
| 15 |
+
curl -fL --retry 3 -o "$2.part" "$1"
|
| 16 |
+
[ "$(sha256_of "$2.part")" = "$3" ] || { echo "fetch.sh: sha256 mismatch for $1" >&2; rm -f "$2.part"; exit 1; }
|
| 17 |
+
mv "$2.part" "$2"
|
| 18 |
+
}
|
| 19 |
+
git_at() { # git_at URL COMMIT DIR: the exact commit, shallow
|
| 20 |
+
if [ "$(git -C "$3" rev-parse HEAD 2>/dev/null || true)" = "$2" ]; then return 0; fi
|
| 21 |
+
rm -rf "$3"; mkdir -p "$3"
|
| 22 |
+
git -C "$3" init -q && git -C "$3" remote add origin "$1"
|
| 23 |
+
git -C "$3" fetch -q --depth 1 origin "$2" && git -C "$3" -c advice.detachedHead=false checkout -q FETCH_HEAD
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
get "https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11n.pt" \
|
| 27 |
+
weights/yolo11n.pt 0ebbc80d4a7680d14987a577cd21342b65ecfd94632bd9a8da63ae6417644ee1
|
| 28 |
+
echo "fetch.sh: done. Next: NNOPT_WEIGHTS=$PWD/weights/yolo11n.pt bash build.sh, then bash deploy.sh nnopt/port"
|
orin-nano-gpu-int8/report.html
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
orin-nano-gpu-int8/report/reproduce.sh
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/sh
|
| 2 |
+
# Reproduce the numbers in report.html with nnopt-verify 0.1.0.
|
| 3 |
+
# Needs: the frozen reference bundle, the port deployed on the device (./deploy.sh), and the device reachable.
|
| 4 |
+
# Connection: SSH_TARGET=user@host.
|
| 5 |
+
set -e
|
| 6 |
+
BUNDLE=${BUNDLE:-./reference-bundle} # bundle digest 6eda989b4342a95d04cff483210d622ad6220800f1361722620c812a919ff183
|
| 7 |
+
PORT_DIR=${PORT_DIR:-/home/user/nnopt/port} # where deploy.sh put the port
|
| 8 |
+
OUT=${OUT:-./reproduced}
|
| 9 |
+
mkdir -p "$OUT"
|
| 10 |
+
|
| 11 |
+
nnopt-verify check --bundle "$BUNDLE" --port "$PORT_DIR" --executor ssh --ssh "$SSH_TARGET" --precision int8 --split all --out "$OUT/check.json"
|
| 12 |
+
nnopt-verify bench --bundle "$BUNDLE" --port "$PORT_DIR" --executor ssh --ssh "$SSH_TARGET" --warmup 2 --runs 5 --repeat 3 --max-new-tokens 128 --sustained-s 0.0 --resolution 640x640 --env-specs '{"device": "NVIDIA Jetson Orin Nano", "gpu": "Ampere, 1024 CUDA cores", "name": "NVIDIA Jetson Orin Nano"}' --out "$OUT/bench.json"
|
| 13 |
+
nnopt-verify grade --check "$OUT/check.json" --bench "$OUT/bench.json" --out "$OUT/grade.json"
|
| 14 |
+
nnopt-verify report --check "$OUT/check.json" --bench "$OUT/bench.json" --grade "$OUT/grade.json" --bundle "$BUNDLE" --out "$OUT/report"
|
orin-nano-gpu-int8/report/results.csv
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
section,name,value,unit_or_op,threshold,passed
|
| 2 |
+
grade,correctness,True,,,True
|
| 3 |
+
grade,speed_target_met,,,,
|
| 4 |
+
check,cases_completed,1.0,>=,1.0,True
|
| 5 |
+
check,reference_detections,157.0,>=,1.0,True
|
| 6 |
+
check,detection_recall,0.97452,>=,0.93,True
|
| 7 |
+
check,detection_precision,0.98693,>=,0.93,True
|
| 8 |
+
check,map50_vs_reference,0.95552,>=,0.85,True
|
| 9 |
+
check,box_iou,0.98061,>=,0.9,True
|
| 10 |
+
check,score_drift,0.020219,<=,0.06,True
|
| 11 |
+
check_metric,detection_recall,0.97452,,,
|
| 12 |
+
check_metric,detection_precision,0.98693,,,
|
| 13 |
+
check_metric,map50_vs_reference,0.95552,,,
|
| 14 |
+
check_metric,box_iou,0.98061,,,
|
| 15 |
+
check_metric,score_drift,0.020219,,,
|
| 16 |
+
check_metric,max_score_drift,0.15486,,,
|
| 17 |
+
check_metric,reference_detections,157,,,
|
| 18 |
+
check_metric,port_detections,153,,,
|
| 19 |
+
check_metric,comparison_threshold,0.3041,,,
|
| 20 |
+
check_metric,score_margin,0.05,,,
|
| 21 |
+
check_metric,iou_match,0.5,,,
|
| 22 |
+
check_metric,per_class,"[{'class': 0, 'name': 'class 0', 'objects': 64, 'ap50': 0.9577}, {'class': 2, 'name': 'class 2', 'objects': 19, 'ap50': 1.0}, {'class': 11, 'name': 'class 11', 'objects': 9, 'ap50': 1.0}, {'class': 9, 'name': 'class 9', 'objects': 6, 'ap50': 1.0}, {'class': 62, 'name': 'class 62', 'objects': 5, 'ap50': 1.0}, {'class': 58, 'name': 'class 58', 'objects': 5, 'ap50': 1.0}, {'class': 56, 'name': 'class 56', 'objects': 4, 'ap50': 1.0}, {'class': 7, 'name': 'class 7', 'objects': 4, 'ap50': 1.0}, {'class': 4, 'name': 'class 4', 'objects': 4, 'ap50': 1.0}, {'class': 3, 'name': 'class 3', 'objects': 4, 'ap50': 0.7525}, {'class': 74, 'name': 'class 74', 'objects': 3, 'ap50': 1.0}, {'class': 38, 'name': 'class 38', 'objects': 3, 'ap50': 1.0}, {'class': 15, 'name': 'class 15', 'objects': 3, 'ap50': 1.0}, {'class': 5, 'name': 'class 5', 'objects': 2, 'ap50': 1.0}, {'class': 75, 'name': 'class 75', 'objects': 2, 'ap50': 1.0}, {'class': 59, 'name': 'class 59', 'objects': 2, 'ap50': 1.0}, {'class': 34, 'name': 'class 34', 'objects': 2, 'ap50': 1.0}, {'class': 50, 'name': 'class 50', 'objects': 2, 'ap50': 1.0}, {'class': 41, 'name': 'class 41', 'objects': 2, 'ap50': 1.0}, {'class': 31, 'name': 'class 31', 'objects': 2, 'ap50': 1.0}, {'class': 25, 'name': 'class 25', 'objects': 2, 'ap50': 1.0}, {'class': 33, 'name': 'class 33', 'objects': 1, 'ap50': 1.0}, {'class': 72, 'name': 'class 72', 'objects': 1, 'ap50': 1.0}, {'class': 60, 'name': 'class 60', 'objects': 1, 'ap50': 1.0}, {'class': 39, 'name': 'class 39', 'objects': 1, 'ap50': 1.0}, {'class': 49, 'name': 'class 49', 'objects': 1, 'ap50': 1.0}, {'class': 30, 'name': 'class 30', 'objects': 1, 'ap50': 0.0}, {'class': 27, 'name': 'class 27', 'objects': 1, 'ap50': 1.0}, {'class': 16, 'name': 'class 16', 'objects': 1, 'ap50': 1.0}]",,,
|
| 23 |
+
bench,fps.median,186.632,img/s,,
|
| 24 |
+
bench,fps.p10,185.181,img/s,,
|
| 25 |
+
bench,fps.p90,187.569,img/s,,
|
| 26 |
+
bench,fps.min,178.989,img/s,,
|
| 27 |
+
bench,fps.max,188.623,img/s,,
|
| 28 |
+
bench,fps.n,1860,img/s,,
|
| 29 |
+
bench,latency_ms.median,5.35813,ms,,
|
| 30 |
+
bench,latency_ms.p10,5.33136,ms,,
|
| 31 |
+
bench,latency_ms.p90,5.40011,ms,,
|
| 32 |
+
bench,latency_ms.min,5.30158,ms,,
|
| 33 |
+
bench,latency_ms.max,5.58693,ms,,
|
| 34 |
+
bench,latency_ms.n,1860,ms,,
|
| 35 |
+
bench,per_image_ms.median,5.35813,ms,,
|
| 36 |
+
bench,per_image_ms.p10,5.33136,ms,,
|
| 37 |
+
bench,per_image_ms.p90,5.40011,ms,,
|
| 38 |
+
bench,per_image_ms.min,5.30158,ms,,
|
| 39 |
+
bench,per_image_ms.max,5.58693,ms,,
|
| 40 |
+
bench,per_image_ms.n,1860,ms,,
|
| 41 |
+
bench,cold_latency_ms.median,5.63871,ms,,
|
| 42 |
+
bench,cold_latency_ms.p10,5.59194,ms,,
|
| 43 |
+
bench,cold_latency_ms.p90,5.704,ms,,
|
| 44 |
+
bench,cold_latency_ms.min,5.56226,ms,,
|
| 45 |
+
bench,cold_latency_ms.max,5.72201,ms,,
|
| 46 |
+
bench,cold_latency_ms.n,5,ms,,
|
| 47 |
+
bench,load_ms.median,518.979,ms,,
|
| 48 |
+
bench,load_ms.p10,515.093,ms,,
|
| 49 |
+
bench,load_ms.p90,524.296,ms,,
|
| 50 |
+
bench,load_ms.min,513.939,ms,,
|
| 51 |
+
bench,load_ms.max,526.767,ms,,
|
| 52 |
+
bench,load_ms.n,5,ms,,
|
| 53 |
+
bench,wall_ms.median,2688.6,ms,,
|
| 54 |
+
bench,wall_ms.p10,2682.09,ms,,
|
| 55 |
+
bench,wall_ms.p90,2699.67,ms,,
|
| 56 |
+
bench,wall_ms.min,2678.53,ms,,
|
| 57 |
+
bench,wall_ms.max,2704.35,ms,,
|
| 58 |
+
bench,wall_ms.n,5,ms,,
|
| 59 |
+
bench,peak_rss_mb,454.8,MB,,
|
| 60 |
+
bench,peak_hwm_mb,454.8,MB,,
|
| 61 |
+
bench,self_reported_peak_mem_mb,453.8,MB,,
|
| 62 |
+
graded,fps,186.632,img/s,,
|
| 63 |
+
graded,latency_ms,5.35813,ms,,
|
| 64 |
+
graded,per_image_ms,5.35813,ms,,
|
| 65 |
+
graded,cold_latency_ms,5.63871,ms,,
|
| 66 |
+
graded,load_ms,518.979,ms,,
|
| 67 |
+
graded,wall_ms,2688.6,ms,,
|
| 68 |
+
graded,peak_mem_mb,454.8,MB,,
|
| 69 |
+
graded,system_ram_delta_mb,312.0,MB,,
|
| 70 |
+
roofline,mem_bandwidth_gbps,,,,
|
| 71 |
+
roofline,peak_gflops,,,,
|
orin-nano-gpu-int8/report/results.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
orin-nano-gpu-int8/src/build_engine.py
ADDED
|
@@ -0,0 +1,457 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Build the YOLO11 TensorRT engine from model.json + weights.npz (written by export_weights.py).
|
| 2 |
+
|
| 3 |
+
The network is defined layer by layer with the TensorRT network API, following the checkpoint's module tree.
|
| 4 |
+
Each builder function quotes the ultralytics source it implements (reference_code commit fc26c3d).
|
| 5 |
+
|
| 6 |
+
usage: python3 build_engine.py --model DIR --out ENGINE [--precision int8|fp16|fp32]
|
| 7 |
+
[--calib-cache FILE] [--calib-images DIR]
|
| 8 |
+
"""
|
| 9 |
+
import argparse
|
| 10 |
+
import glob
|
| 11 |
+
import json
|
| 12 |
+
import os
|
| 13 |
+
import sys
|
| 14 |
+
import time
|
| 15 |
+
|
| 16 |
+
import numpy as np
|
| 17 |
+
import tensorrt as trt
|
| 18 |
+
|
| 19 |
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
| 20 |
+
|
| 21 |
+
IMGSZ = 640
|
| 22 |
+
LOGGER = trt.Logger(trt.Logger.WARNING)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
class Net:
|
| 26 |
+
def __init__(self, network, weights):
|
| 27 |
+
self.net = network
|
| 28 |
+
self.w = weights
|
| 29 |
+
self.keep = [] # numpy arrays must outlive the build
|
| 30 |
+
self.fp_layers = [] # layers we may pin to fp16 (precision-sensitive)
|
| 31 |
+
self.amax = None # explicit INT8: {conv path: activation amax}; convs listed here get Q/DQ inputs
|
| 32 |
+
self.qdq_skip = ()
|
| 33 |
+
|
| 34 |
+
def _qdq(self, x, scale, name, axis=None):
|
| 35 |
+
"""Quantize to int8 and dequantize back (TensorRT fuses the pair into the consumer's int8 kernel)."""
|
| 36 |
+
sc = np.ascontiguousarray(np.asarray(scale, np.float32))
|
| 37 |
+
self.keep.append(sc)
|
| 38 |
+
c = self._name(self.net.add_constant(sc.shape, trt.Weights(sc)), name + ".scale").get_output(0)
|
| 39 |
+
q = self.net.add_quantize(x, c)
|
| 40 |
+
if axis is not None:
|
| 41 |
+
q.axis = axis
|
| 42 |
+
dq = self.net.add_dequantize(q.get_output(0), c)
|
| 43 |
+
if axis is not None:
|
| 44 |
+
dq.axis = axis
|
| 45 |
+
self._name(q, name + ".q")
|
| 46 |
+
return self._name(dq, name + ".dq").get_output(0)
|
| 47 |
+
|
| 48 |
+
def _name(self, layer, name):
|
| 49 |
+
layer.name = name
|
| 50 |
+
for i in range(layer.num_outputs):
|
| 51 |
+
layer.get_output(i).name = name if layer.num_outputs == 1 else f"{name}:{i}"
|
| 52 |
+
return layer
|
| 53 |
+
|
| 54 |
+
def const(self, arr, name):
|
| 55 |
+
arr = np.ascontiguousarray(arr, dtype=np.float32)
|
| 56 |
+
self.keep.append(arr)
|
| 57 |
+
return self._name(self.net.add_constant(arr.shape, trt.Weights(arr)), name).get_output(0)
|
| 58 |
+
|
| 59 |
+
def ew(self, a, b, op, name):
|
| 60 |
+
return self._name(self.net.add_elementwise(a, b, op), name).get_output(0)
|
| 61 |
+
|
| 62 |
+
def reshape(self, x, shape, name):
|
| 63 |
+
l = self.net.add_shuffle(x)
|
| 64 |
+
l.reshape_dims = tuple(shape)
|
| 65 |
+
return self._name(l, name).get_output(0)
|
| 66 |
+
|
| 67 |
+
def slice(self, x, axis, start, size, name):
|
| 68 |
+
shp = list(x.shape)
|
| 69 |
+
st = [0] * len(shp)
|
| 70 |
+
st[axis] = start
|
| 71 |
+
shp[axis] = size
|
| 72 |
+
return self._name(self.net.add_slice(x, st, shp, [1] * len(shp)), name).get_output(0)
|
| 73 |
+
|
| 74 |
+
def concat(self, xs, axis, name):
|
| 75 |
+
l = self.net.add_concatenation(xs)
|
| 76 |
+
l.axis = axis
|
| 77 |
+
return self._name(l, name).get_output(0)
|
| 78 |
+
|
| 79 |
+
# ultralytics/nn/modules/conv.py Conv (BN folded at export, as Conv.forward_fuse after fuse_conv_and_bn):
|
| 80 |
+
# self.conv = nn.Conv2d(c1, c2, k, s, autopad(k, p, d), groups=g, dilation=d, bias=False)
|
| 81 |
+
# def forward_fuse(self, x): return self.act(self.conv(x)) # act = nn.SiLU() or nn.Identity()
|
| 82 |
+
# DWConv(Conv) is the same with groups=gcd(c1, c2); a plain nn.Conv2d (Detect's last 1x1 convs) has no act.
|
| 83 |
+
def conv(self, x, node, w=None):
|
| 84 |
+
p = node["path"]
|
| 85 |
+
w = self.w[p + ".w"] if w is None else w
|
| 86 |
+
b = self.w.get(p + ".b")
|
| 87 |
+
if b is None:
|
| 88 |
+
b = np.zeros(node["cout"], np.float32)
|
| 89 |
+
w = np.ascontiguousarray(w, np.float32)
|
| 90 |
+
b = np.ascontiguousarray(b, np.float32)
|
| 91 |
+
self.keep += [w, b]
|
| 92 |
+
quant = self.amax is not None and p in self.amax and not any(p == k or p.startswith(k + ".") for k in self.qdq_skip)
|
| 93 |
+
if quant:
|
| 94 |
+
# explicit INT8: per-tensor activation scale (calibrated amax / 127), per-output-channel weight scale
|
| 95 |
+
x = self._qdq(x, max(self.amax[p], 1e-6) / 127.0, p + ".in")
|
| 96 |
+
wa = np.maximum(np.abs(w).reshape(w.shape[0], -1).max(1), 1e-8) / 127.0
|
| 97 |
+
wt = self._name(self.net.add_constant(w.shape, trt.Weights(w)), p + ".wconst").get_output(0)
|
| 98 |
+
wt = self._qdq(wt, wa, p + ".w", axis=0)
|
| 99 |
+
l = self.net.add_convolution_nd(x, node["cout"], tuple(node["k"]), trt.Weights(), trt.Weights(b))
|
| 100 |
+
l.set_input(1, wt)
|
| 101 |
+
else:
|
| 102 |
+
l = self.net.add_convolution_nd(x, node["cout"], tuple(node["k"]), trt.Weights(w), trt.Weights(b))
|
| 103 |
+
l.stride_nd = tuple(node["s"])
|
| 104 |
+
l.padding_nd = tuple(node["p"])
|
| 105 |
+
l.num_groups = node["g"]
|
| 106 |
+
self._name(l, p)
|
| 107 |
+
y = l.get_output(0)
|
| 108 |
+
act = node.get("act", "Identity")
|
| 109 |
+
if act == "SiLU": # x * sigmoid(x)
|
| 110 |
+
s = self._name(self.net.add_activation(y, trt.ActivationType.SIGMOID), p + ".sig").get_output(0)
|
| 111 |
+
y = self.ew(y, s, trt.ElementWiseOperation.PROD, p + ".act")
|
| 112 |
+
elif act != "Identity":
|
| 113 |
+
raise NotImplementedError(f"activation {act} at {p}")
|
| 114 |
+
return y, l
|
| 115 |
+
|
| 116 |
+
def conv_(self, x, node):
|
| 117 |
+
return self.conv(x, node)[0]
|
| 118 |
+
|
| 119 |
+
# ultralytics/nn/modules/block.py:460-482 Bottleneck
|
| 120 |
+
# def forward(self, x): return x + self.cv2(self.cv1(x)) if self.add else self.cv2(self.cv1(x))
|
| 121 |
+
def bottleneck(self, x, node):
|
| 122 |
+
c = node["children"]
|
| 123 |
+
y = self.conv_(self.conv_(x, c["cv1"]), c["cv2"])
|
| 124 |
+
return self.ew(x, y, trt.ElementWiseOperation.SUM, node["path"] + ".add") if node.get("add") else y
|
| 125 |
+
|
| 126 |
+
# ultralytics/nn/modules/block.py:325-348 C3 (C3k subclasses it, block.py:1109-1127)
|
| 127 |
+
# def forward(self, x): return self.cv3(torch.cat((self.m(self.cv1(x)), self.cv2(x)), 1))
|
| 128 |
+
def c3(self, x, node):
|
| 129 |
+
c = node["children"]
|
| 130 |
+
a = self.module(self.conv_(x, c["cv1"]), c["m"])
|
| 131 |
+
b = self.conv_(x, c["cv2"])
|
| 132 |
+
return self.conv_(self.concat([a, b], 1, node["path"] + ".cat"), c["cv3"])
|
| 133 |
+
|
| 134 |
+
# ultralytics/nn/modules/block.py:291-322 C2f (C3k2 subclasses it, block.py:1069-1106)
|
| 135 |
+
# def forward(self, x):
|
| 136 |
+
# y = list(self.cv1(x).chunk(2, 1))
|
| 137 |
+
# y.extend((m(y[-1]) for m in self.m))
|
| 138 |
+
# return self.cv2(torch.cat(y, 1))
|
| 139 |
+
def c2f(self, x, node):
|
| 140 |
+
c, p = node["children"], node["path"]
|
| 141 |
+
y0 = self.conv_(x, c["cv1"])
|
| 142 |
+
ch = y0.shape[1] // 2
|
| 143 |
+
y = [self.slice(y0, 1, 0, ch, p + ".chunk0"), self.slice(y0, 1, ch, ch, p + ".chunk1")]
|
| 144 |
+
for k in sorted(c["m"]["children"], key=int):
|
| 145 |
+
y.append(self.module(y[-1], c["m"]["children"][k]))
|
| 146 |
+
return self.conv_(self.concat(y, 1, p + ".cat"), c["cv2"])
|
| 147 |
+
|
| 148 |
+
# ultralytics/nn/modules/block.py:211-240 SPPF
|
| 149 |
+
# y = [self.cv1(x)]
|
| 150 |
+
# y.extend((self.m(y[-1]) for _ in range(getattr(self, 'n', 3))))
|
| 151 |
+
# y = self.cv2(torch.cat(y, 1))
|
| 152 |
+
# return y + x if getattr(self, 'add', False) else y
|
| 153 |
+
def sppf(self, x, node):
|
| 154 |
+
c, p = node["children"], node["path"]
|
| 155 |
+
mp = c["m"]
|
| 156 |
+
y = [self.conv_(x, c["cv1"])]
|
| 157 |
+
for i in range(node.get("n", 3)):
|
| 158 |
+
k, s, pad = mp["kernel_size"], mp["stride"], mp["padding"]
|
| 159 |
+
l = self.net.add_pooling_nd(y[-1], trt.PoolingType.MAX, (k, k))
|
| 160 |
+
l.stride_nd = (s, s)
|
| 161 |
+
l.padding_nd = (pad, pad)
|
| 162 |
+
y.append(self._name(l, f"{p}.m{i}").get_output(0))
|
| 163 |
+
out = self.conv_(self.concat(y, 1, p + ".cat"), c["cv2"])
|
| 164 |
+
return self.ew(out, x, trt.ElementWiseOperation.SUM, p + ".add") if node.get("add") else out
|
| 165 |
+
|
| 166 |
+
# ultralytics/nn/modules/block.py:1442-1494 C2PSA
|
| 167 |
+
# a, b = self.cv1(x).split((self.c, self.c), dim=1)
|
| 168 |
+
# b = self.m(b)
|
| 169 |
+
# return self.cv2(torch.cat((a, b), 1))
|
| 170 |
+
def c2psa(self, x, node):
|
| 171 |
+
c, p, cc = node["children"], node["path"], node["c"]
|
| 172 |
+
y = self.conv_(x, c["cv1"])
|
| 173 |
+
a = self.slice(y, 1, 0, cc, p + ".a")
|
| 174 |
+
b = self.module(self.slice(y, 1, cc, cc, p + ".b"), c["m"])
|
| 175 |
+
return self.conv_(self.concat([a, b], 1, p + ".cat"), c["cv2"])
|
| 176 |
+
|
| 177 |
+
# ultralytics/nn/modules/block.py:1337-1384 PSABlock
|
| 178 |
+
# x = x + self.attn(x) if self.add else self.attn(x)
|
| 179 |
+
# x = x + self.ffn(x) if self.add else self.ffn(x)
|
| 180 |
+
def psablock(self, x, node):
|
| 181 |
+
c, p = node["children"], node["path"]
|
| 182 |
+
a = self.module(x, c["attn"])
|
| 183 |
+
x = self.ew(x, a, trt.ElementWiseOperation.SUM, p + ".add1") if node.get("add") else a
|
| 184 |
+
f = self.module(x, c["ffn"])
|
| 185 |
+
return self.ew(x, f, trt.ElementWiseOperation.SUM, p + ".add2") if node.get("add") else f
|
| 186 |
+
|
| 187 |
+
# ultralytics/nn/modules/block.py:1271-1334 Attention
|
| 188 |
+
# B, C, H, W = x.shape; N = H * W
|
| 189 |
+
# qkv = self.qkv(x)
|
| 190 |
+
# q, k, v = qkv.view(B, self.num_heads, self.key_dim * 2 + self.head_dim, N).split(
|
| 191 |
+
# [self.key_dim, self.key_dim, self.head_dim], dim=2)
|
| 192 |
+
# attn = ((q * self.scale).transpose(-2, -1) @ k).softmax(dim=-1)
|
| 193 |
+
# x = (v @ attn.transpose(-2, -1)).view(B, C, H, W) + self.pe(v.reshape(B, C, H, W))
|
| 194 |
+
# x = self.proj(x)
|
| 195 |
+
def attention(self, x, node):
|
| 196 |
+
c, p = node["children"], node["path"]
|
| 197 |
+
B, C, H, W = x.shape
|
| 198 |
+
N = H * W
|
| 199 |
+
nh, kd, hd = node["num_heads"], node["key_dim"], node["head_dim"]
|
| 200 |
+
qkv = self.reshape(self.conv_(x, c["qkv"]), (B, nh, 2 * kd + hd, N), p + ".qkv_view")
|
| 201 |
+
q = self.slice(qkv, 2, 0, kd, p + ".q")
|
| 202 |
+
k = self.slice(qkv, 2, kd, kd, p + ".k")
|
| 203 |
+
v = self.slice(qkv, 2, 2 * kd, hd, p + ".v")
|
| 204 |
+
q = self.ew(q, self.const(np.full((1, 1, 1, 1), node["scale"]), p + ".scale_c"),
|
| 205 |
+
trt.ElementWiseOperation.PROD, p + ".qs")
|
| 206 |
+
mm = self.net.add_matrix_multiply(q, trt.MatrixOperation.TRANSPOSE, k, trt.MatrixOperation.NONE)
|
| 207 |
+
self._name(mm, p + ".qk")
|
| 208 |
+
self.fp_layers.append(mm)
|
| 209 |
+
sm = self.net.add_softmax(mm.get_output(0))
|
| 210 |
+
sm.axes = 1 << 3
|
| 211 |
+
self._name(sm, p + ".softmax")
|
| 212 |
+
self.fp_layers.append(sm)
|
| 213 |
+
mm2 = self.net.add_matrix_multiply(v, trt.MatrixOperation.NONE, sm.get_output(0), trt.MatrixOperation.TRANSPOSE)
|
| 214 |
+
self._name(mm2, p + ".av")
|
| 215 |
+
self.fp_layers.append(mm2)
|
| 216 |
+
o = self.reshape(mm2.get_output(0), (B, C, H, W), p + ".av_view")
|
| 217 |
+
pe = self.conv_(self.reshape(v, (B, C, H, W), p + ".v_view"), c["pe"])
|
| 218 |
+
o = self.ew(o, pe, trt.ElementWiseOperation.SUM, p + ".pe_add")
|
| 219 |
+
return self.conv_(o, c["proj"])
|
| 220 |
+
|
| 221 |
+
def sequential(self, x, node):
|
| 222 |
+
for k in sorted(node["children"], key=int):
|
| 223 |
+
x = self.module(x, node["children"][k])
|
| 224 |
+
return x
|
| 225 |
+
|
| 226 |
+
# torch.nn.Upsample(scale_factor=2, mode="nearest"): out[y, x] = in[floor(y / 2), floor(x / 2)]
|
| 227 |
+
def upsample(self, x, node):
|
| 228 |
+
assert node.get("mode", "nearest") == "nearest"
|
| 229 |
+
s = float(node["scale_factor"])
|
| 230 |
+
l = self.net.add_resize(x)
|
| 231 |
+
l.resize_mode = trt.InterpolationMode.NEAREST
|
| 232 |
+
l.scales = [1.0, 1.0, s, s]
|
| 233 |
+
l.coordinate_transformation = trt.ResizeCoordinateTransformation.ASYMMETRIC
|
| 234 |
+
l.nearest_rounding = trt.ResizeRoundMode.FLOOR
|
| 235 |
+
return self._name(l, node["path"]).get_output(0)
|
| 236 |
+
|
| 237 |
+
def module(self, x, node):
|
| 238 |
+
t = node["type"]
|
| 239 |
+
if t in ("Conv", "DWConv", "Conv2d"):
|
| 240 |
+
return self.conv_(x, node)
|
| 241 |
+
fn = {"Bottleneck": self.bottleneck, "C3k": self.c3, "C3": self.c3, "C3k2": self.c2f, "C2f": self.c2f,
|
| 242 |
+
"SPPF": self.sppf, "C2PSA": self.c2psa, "PSABlock": self.psablock, "Attention": self.attention,
|
| 243 |
+
"Sequential": self.sequential, "Upsample": self.upsample}.get(t)
|
| 244 |
+
if fn is None:
|
| 245 |
+
raise NotImplementedError(f"module type {t} at {node['path']}")
|
| 246 |
+
return fn(x, node)
|
| 247 |
+
|
| 248 |
+
# ultralytics/nn/modules/head.py:38-295 Detect (one-to-many head, inference, export=False):
|
| 249 |
+
# boxes = torch.cat([box_head[i](x[i]).view(bs, 4 * self.reg_max, -1) for i in range(self.nl)], dim=-1)
|
| 250 |
+
# scores = torch.cat([cls_head[i](x[i]).view(bs, self.nc, -1) for i in range(self.nl)], dim=-1)
|
| 251 |
+
# dbox = self.decode_bboxes(self.dfl(x['boxes']), self.anchors.unsqueeze(0)) * self.strides
|
| 252 |
+
# y = torch.cat((dbox, x['scores'].sigmoid()), 1)
|
| 253 |
+
# block.py:60-81 DFL: self.conv(x.view(b, 4, self.c1, a).transpose(2, 1).softmax(1)).view(b, 4, a)
|
| 254 |
+
# utils/tal.py make_anchors(offset 0.5): anchor (sx, sy) = (x + 0.5, y + 0.5), row-major over (y, x)
|
| 255 |
+
# utils/tal.py dist2bbox: lt, rb = distance.chunk(2, dim); x1y1 = anchor - lt; x2y2 = anchor + rb
|
| 256 |
+
# We emit xyxy directly (nms.py converts the reference's xywh to xyxy before NMS), then the best class per
|
| 257 |
+
# anchor (non_max_suppression multi_label=False: conf, j = cls.max(1)) so the host only filters + NMSes.
|
| 258 |
+
def detect(self, xs, node):
|
| 259 |
+
c, p = node["children"], node["path"]
|
| 260 |
+
nc, reg_max = node["nc"], node["reg_max"]
|
| 261 |
+
strides = node["stride"]
|
| 262 |
+
assert not node.get("end2end") and "one2one_cv2" not in c, "end2end heads not supported"
|
| 263 |
+
boxes, scores, anchors, stride_t = [], [], [], []
|
| 264 |
+
for i, x in enumerate(xs):
|
| 265 |
+
_, _, H, W = x.shape
|
| 266 |
+
bh = c["cv2"]["children"][str(i)]
|
| 267 |
+
ch = c["cv3"]["children"][str(i)]
|
| 268 |
+
b = self.sequential(x, bh)
|
| 269 |
+
s = self.sequential(x, ch)
|
| 270 |
+
boxes.append(self.reshape(b, (1, 4 * reg_max, H * W), f"{p}.box{i}"))
|
| 271 |
+
scores.append(self.reshape(s, (1, nc, H * W), f"{p}.cls{i}"))
|
| 272 |
+
sy, sx = np.meshgrid(np.arange(H, dtype=np.float32) + 0.5, np.arange(W, dtype=np.float32) + 0.5,
|
| 273 |
+
indexing="ij")
|
| 274 |
+
anchors.append(np.stack((sx.ravel(), sy.ravel()), 0))
|
| 275 |
+
stride_t.append(np.full((1, H * W), strides[i], np.float32))
|
| 276 |
+
A = sum(a.shape[1] for a in anchors)
|
| 277 |
+
box = self.concat(boxes, 2, p + ".boxes")
|
| 278 |
+
score = self.concat(scores, 2, p + ".scores")
|
| 279 |
+
# DFL: softmax over the reg_max bins, then the 1x1 conv with weights 0..reg_max-1 (expected bin)
|
| 280 |
+
d = self.reshape(box, (1, 4, reg_max, A), p + ".dfl_view")
|
| 281 |
+
sm = self.net.add_softmax(d)
|
| 282 |
+
sm.axes = 1 << 2
|
| 283 |
+
self._name(sm, p + ".dfl_softmax")
|
| 284 |
+
self.fp_layers.append(sm)
|
| 285 |
+
wdfl = self.w[c["dfl"]["children"]["conv"]["path"] + ".w"].reshape(1, 1, reg_max, 1)
|
| 286 |
+
prod = self.ew(sm.get_output(0), self.const(wdfl, p + ".dfl_w"), trt.ElementWiseOperation.PROD, p + ".dfl_mul")
|
| 287 |
+
red = self.net.add_reduce(prod, trt.ReduceOperation.SUM, 1 << 2, False)
|
| 288 |
+
self._name(red, p + ".dfl")
|
| 289 |
+
dist = red.get_output(0) # [1, 4, A] = l, t, r, b
|
| 290 |
+
anc = self.const(np.concatenate(anchors, 1)[None], p + ".anchors") # [1, 2, A]
|
| 291 |
+
st = self.const(np.concatenate(stride_t, 1)[None], p + ".strides") # [1, 1, A]
|
| 292 |
+
lt = self.slice(dist, 1, 0, 2, p + ".lt")
|
| 293 |
+
rb = self.slice(dist, 1, 2, 2, p + ".rb")
|
| 294 |
+
x1y1 = self.ew(self.ew(anc, lt, trt.ElementWiseOperation.SUB, p + ".x1y1g"), st,
|
| 295 |
+
trt.ElementWiseOperation.PROD, p + ".x1y1")
|
| 296 |
+
x2y2 = self.ew(self.ew(anc, rb, trt.ElementWiseOperation.SUM, p + ".x2y2g"), st,
|
| 297 |
+
trt.ElementWiseOperation.PROD, p + ".x2y2")
|
| 298 |
+
# best class: sigmoid is monotonic, so top-1 over logits then sigmoid on the winner only
|
| 299 |
+
tk = self.net.add_topk(score, trt.TopKOperation.MAX, 1, 1 << 1)
|
| 300 |
+
self._name(tk, p + ".top1")
|
| 301 |
+
conf = self._name(self.net.add_activation(tk.get_output(0), trt.ActivationType.SIGMOID),
|
| 302 |
+
p + ".conf").get_output(0)
|
| 303 |
+
cls = self._name(self.net.add_cast(tk.get_output(1), trt.float32), p + ".cls").get_output(0)
|
| 304 |
+
out = self.concat([x1y1, x2y2, conf, cls], 1, "output") # [1, 6, A]
|
| 305 |
+
for l in (red,):
|
| 306 |
+
self.fp_layers.append(l)
|
| 307 |
+
return out
|
| 308 |
+
|
| 309 |
+
|
| 310 |
+
def build_network(builder, meta, weights, amax=None, qdq_skip=()):
|
| 311 |
+
network = builder.create_network(0)
|
| 312 |
+
g = Net(network, weights)
|
| 313 |
+
g.amax, g.qdq_skip = amax, tuple(qdq_skip)
|
| 314 |
+
# Input: the letterboxed 640x640 BGR uint8 image (HWC), exactly the array LetterBox returns.
|
| 315 |
+
# ultralytics/engine/predictor.py preprocess: im.permute(0, 3, 1, 2); im.flip(1) (BGR->RGB); im.float() / 255
|
| 316 |
+
# The BGR->RGB flip and the 1/255 are folded into the first conv's weights (conv is linear, zero padding).
|
| 317 |
+
inp = network.add_input("images", trt.uint8, (1, IMGSZ, IMGSZ, 3))
|
| 318 |
+
x = g._name(network.add_cast(inp, trt.float32), "input_cast").get_output(0)
|
| 319 |
+
sh = network.add_shuffle(x)
|
| 320 |
+
sh.first_transpose = (0, 3, 1, 2)
|
| 321 |
+
x = g._name(sh, "input_nchw").get_output(0)
|
| 322 |
+
outs = []
|
| 323 |
+
layers = meta["layers"]
|
| 324 |
+
for li, node in enumerate(layers):
|
| 325 |
+
f = node["f"]
|
| 326 |
+
if node["type"] == "Detect":
|
| 327 |
+
out = g.detect([outs[j] for j in f], node)
|
| 328 |
+
break
|
| 329 |
+
if node["type"] == "Concat":
|
| 330 |
+
y = g.concat([outs[j] if j != -1 else outs[-1] for j in f], node.get("d", 1), node["path"])
|
| 331 |
+
else:
|
| 332 |
+
src = x if li == 0 else outs[f if f != -1 else -1] if isinstance(f, int) else None
|
| 333 |
+
if li == 0: # (kept out of int8: 3 input channels, raw 0..255 pixels)
|
| 334 |
+
w0 = weights[node["path"] + ".w"][:, ::-1] / 255.0 # RGB-ordered weights applied to BGR / 255
|
| 335 |
+
y, first = g.conv(src, node, w=w0)
|
| 336 |
+
else:
|
| 337 |
+
y = g.module(src, node)
|
| 338 |
+
outs.append(y)
|
| 339 |
+
out.name = "output"
|
| 340 |
+
network.mark_output(out)
|
| 341 |
+
return network, g
|
| 342 |
+
|
| 343 |
+
|
| 344 |
+
def make_calibrator(kind, cache, images):
|
| 345 |
+
base = {"entropy": trt.IInt8EntropyCalibrator2, "minmax": trt.IInt8MinMaxCalibrator}[kind]
|
| 346 |
+
|
| 347 |
+
class Calibrator(_CalibData, base):
|
| 348 |
+
def __init__(self):
|
| 349 |
+
base.__init__(self)
|
| 350 |
+
_CalibData.__init__(self, cache, images)
|
| 351 |
+
|
| 352 |
+
return Calibrator()
|
| 353 |
+
|
| 354 |
+
|
| 355 |
+
class _CalibData:
|
| 356 |
+
def __init__(self, cache, images):
|
| 357 |
+
self.cache = cache
|
| 358 |
+
self.files = sorted(images)
|
| 359 |
+
self.idx = 0
|
| 360 |
+
self.dev = None
|
| 361 |
+
if self.files:
|
| 362 |
+
import cudart
|
| 363 |
+
self.cu = cudart
|
| 364 |
+
self.dev = cudart.malloc(IMGSZ * IMGSZ * 3)
|
| 365 |
+
|
| 366 |
+
def get_batch_size(self):
|
| 367 |
+
return 1
|
| 368 |
+
|
| 369 |
+
def get_batch(self, names):
|
| 370 |
+
if self.idx >= len(self.files):
|
| 371 |
+
return None
|
| 372 |
+
import cv2
|
| 373 |
+
from prepost import letterbox
|
| 374 |
+
im = np.ascontiguousarray(letterbox(cv2.imread(self.files[self.idx]), (IMGSZ, IMGSZ)))
|
| 375 |
+
self.idx += 1
|
| 376 |
+
self.cu.memcpy(self.dev, im.ctypes.data, im.nbytes, self.cu.H2D)
|
| 377 |
+
return [self.dev]
|
| 378 |
+
|
| 379 |
+
def read_calibration_cache(self):
|
| 380 |
+
if self.cache and os.path.exists(self.cache):
|
| 381 |
+
with open(self.cache, "rb") as f:
|
| 382 |
+
return f.read()
|
| 383 |
+
return None
|
| 384 |
+
|
| 385 |
+
def write_calibration_cache(self, cache):
|
| 386 |
+
if self.cache:
|
| 387 |
+
with open(self.cache, "wb") as f:
|
| 388 |
+
f.write(cache)
|
| 389 |
+
|
| 390 |
+
|
| 391 |
+
def main():
|
| 392 |
+
ap = argparse.ArgumentParser()
|
| 393 |
+
ap.add_argument("--model", required=True)
|
| 394 |
+
ap.add_argument("--out", required=True)
|
| 395 |
+
ap.add_argument("--precision", default="int8", choices=["int8", "int8qdq", "fp16", "fp32"])
|
| 396 |
+
ap.add_argument("--amax", default=None, help="int8qdq: JSON from tools/calib_stats.py")
|
| 397 |
+
ap.add_argument("--amax-mode", default="max", help="int8qdq: max | pNN (percentile of per-image amax)")
|
| 398 |
+
ap.add_argument("--qdq-skip", default="model.0,model.1,model.2,model.10,model.23",
|
| 399 |
+
help="int8qdq: module paths whose convs stay fp16 (chosen with tools/sensitivity.py)")
|
| 400 |
+
ap.add_argument("--calib-cache", default=None)
|
| 401 |
+
ap.add_argument("--calib-images", default=None)
|
| 402 |
+
ap.add_argument("--fp16-sensitive", type=int, default=1, help="pin attention/DFL math to fp16 in int8 mode")
|
| 403 |
+
# Default chosen with tools/sensitivity.py (simulated int8 vs fp32 detections, see NOTES.md): the stem
|
| 404 |
+
# (model.0-2), the attention block (model.10) and the Detect head (model.23) stay fp16.
|
| 405 |
+
ap.add_argument("--fp16-layers", default="input_cast,input_nchw,model.0,model.1,model.2,model.10,model.23,output",
|
| 406 |
+
help="comma-separated module paths kept out of int8 (int8 mode)")
|
| 407 |
+
ap.add_argument("--calibrator", default="minmax", choices=["minmax", "entropy"])
|
| 408 |
+
ap.add_argument("--opt-level", type=int, default=3, help="TensorRT builder optimization level (0-5)")
|
| 409 |
+
ap.add_argument("--workspace-mb", type=int, default=1024)
|
| 410 |
+
a = ap.parse_args()
|
| 411 |
+
t0 = time.time()
|
| 412 |
+
meta = json.load(open(os.path.join(a.model, "model.json")))
|
| 413 |
+
weights = dict(np.load(os.path.join(a.model, "weights.npz")))
|
| 414 |
+
builder = trt.Builder(LOGGER)
|
| 415 |
+
amax = None
|
| 416 |
+
if a.precision == "int8qdq":
|
| 417 |
+
st = json.load(open(a.amax))["amax"]
|
| 418 |
+
if a.amax_mode == "max":
|
| 419 |
+
amax = {k: float(np.max(v)) for k, v in st.items()}
|
| 420 |
+
else:
|
| 421 |
+
amax = {k: float(np.percentile(v, float(a.amax_mode[1:]))) for k, v in st.items()}
|
| 422 |
+
network, g = build_network(builder, meta, weights, amax, [s for s in a.qdq_skip.split(",") if s])
|
| 423 |
+
config = builder.create_builder_config()
|
| 424 |
+
config.set_memory_pool_limit(trt.MemoryPoolType.WORKSPACE, a.workspace_mb << 20)
|
| 425 |
+
config.builder_optimization_level = a.opt_level
|
| 426 |
+
if a.precision in ("fp16", "int8", "int8qdq"):
|
| 427 |
+
config.set_flag(trt.BuilderFlag.FP16)
|
| 428 |
+
if a.precision == "int8qdq":
|
| 429 |
+
config.set_flag(trt.BuilderFlag.INT8) # explicit quantization: int8 only where the Q/DQ pairs are
|
| 430 |
+
if a.precision == "int8":
|
| 431 |
+
config.set_flag(trt.BuilderFlag.INT8)
|
| 432 |
+
imgs = []
|
| 433 |
+
if a.calib_images:
|
| 434 |
+
imgs = glob.glob(os.path.join(a.calib_images, "*.jpg"))
|
| 435 |
+
if not imgs and not (a.calib_cache and os.path.exists(a.calib_cache)):
|
| 436 |
+
raise SystemExit("int8 needs --calib-images or an existing --calib-cache")
|
| 437 |
+
config.int8_calibrator = make_calibrator(a.calibrator, a.calib_cache, imgs)
|
| 438 |
+
pins = list(g.fp_layers) if a.fp16_sensitive else []
|
| 439 |
+
prefixes = [s for s in a.fp16_layers.split(",") if s]
|
| 440 |
+
if prefixes:
|
| 441 |
+
for i in range(network.num_layers):
|
| 442 |
+
l = network.get_layer(i)
|
| 443 |
+
if any(l.name == pfx or l.name.startswith((pfx + ".", pfx + ":")) for pfx in prefixes):
|
| 444 |
+
pins.append(l)
|
| 445 |
+
for l in pins:
|
| 446 |
+
l.precision = trt.float16
|
| 447 |
+
config.set_flag(trt.BuilderFlag.PREFER_PRECISION_CONSTRAINTS)
|
| 448 |
+
plan = builder.build_serialized_network(network, config)
|
| 449 |
+
if plan is None:
|
| 450 |
+
raise SystemExit("engine build failed")
|
| 451 |
+
with open(a.out, "wb") as f:
|
| 452 |
+
f.write(plan)
|
| 453 |
+
print(f"built {a.out} ({a.precision}, {network.num_layers} layers) in {time.time() - t0:.1f}s")
|
| 454 |
+
|
| 455 |
+
|
| 456 |
+
if __name__ == "__main__":
|
| 457 |
+
main()
|
orin-nano-gpu-int8/src/calib/act_amax.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
orin-nano-gpu-int8/src/cudart.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Minimal ctypes binding to the CUDA runtime (the Jetson image has no pycuda / cuda-python)."""
|
| 2 |
+
import ctypes
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
_lib = None
|
| 6 |
+
for _p in ("libcudart.so.12", "/usr/local/cuda/lib64/libcudart.so.12", "libcudart.so"):
|
| 7 |
+
try:
|
| 8 |
+
_lib = ctypes.CDLL(_p)
|
| 9 |
+
break
|
| 10 |
+
except OSError:
|
| 11 |
+
continue
|
| 12 |
+
if _lib is None:
|
| 13 |
+
raise OSError("libcudart not found")
|
| 14 |
+
|
| 15 |
+
H2D, D2H = 1, 2
|
| 16 |
+
_vp = ctypes.c_void_p
|
| 17 |
+
_lib.cudaMalloc.argtypes = [ctypes.POINTER(_vp), ctypes.c_size_t]
|
| 18 |
+
_lib.cudaFree.argtypes = [_vp]
|
| 19 |
+
_lib.cudaMallocHost.argtypes = [ctypes.POINTER(_vp), ctypes.c_size_t]
|
| 20 |
+
_lib.cudaFreeHost.argtypes = [_vp]
|
| 21 |
+
_lib.cudaMemcpy.argtypes = [_vp, _vp, ctypes.c_size_t, ctypes.c_int]
|
| 22 |
+
_lib.cudaMemcpyAsync.argtypes = [_vp, _vp, ctypes.c_size_t, ctypes.c_int, _vp]
|
| 23 |
+
_lib.cudaStreamCreate.argtypes = [ctypes.POINTER(_vp)]
|
| 24 |
+
_lib.cudaStreamSynchronize.argtypes = [_vp]
|
| 25 |
+
_lib.cudaGetErrorString.restype = ctypes.c_char_p
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def _check(err, what):
|
| 29 |
+
if err != 0:
|
| 30 |
+
raise RuntimeError(f"{what}: CUDA error {err} {_lib.cudaGetErrorString(err).decode()}")
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def malloc(nbytes):
|
| 34 |
+
p = _vp()
|
| 35 |
+
_check(_lib.cudaMalloc(ctypes.byref(p), nbytes), "cudaMalloc")
|
| 36 |
+
return p.value
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def malloc_host(nbytes):
|
| 40 |
+
p = _vp()
|
| 41 |
+
_check(_lib.cudaMallocHost(ctypes.byref(p), nbytes), "cudaMallocHost")
|
| 42 |
+
return p.value
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def free(p):
|
| 46 |
+
_check(_lib.cudaFree(p), "cudaFree")
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def memcpy(dst, src, nbytes, kind):
|
| 50 |
+
_check(_lib.cudaMemcpy(dst, src, nbytes, kind), "cudaMemcpy")
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def memcpy_async(dst, src, nbytes, kind, stream):
|
| 54 |
+
_check(_lib.cudaMemcpyAsync(dst, src, nbytes, kind, stream), "cudaMemcpyAsync")
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def stream_create():
|
| 58 |
+
s = _vp()
|
| 59 |
+
_check(_lib.cudaStreamCreate(ctypes.byref(s)), "cudaStreamCreate")
|
| 60 |
+
return s.value
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def stream_sync(s):
|
| 64 |
+
_check(_lib.cudaStreamSynchronize(s), "cudaStreamSynchronize")
|
orin-nano-gpu-int8/src/export_weights.py
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Extract a YOLO11 checkpoint (ultralytics .pt) into a module-tree JSON + BN-fused fp32 weights (.npz).
|
| 2 |
+
|
| 3 |
+
Runs on the build host with only torch + numpy: ultralytics classes are unpickled into inert stand-ins
|
| 4 |
+
(no ultralytics import needed), and we read their attributes and child modules directly.
|
| 5 |
+
|
| 6 |
+
usage: python export_weights.py yolo11n.pt OUT_DIR
|
| 7 |
+
"""
|
| 8 |
+
import json, os, pickle, sys, types
|
| 9 |
+
|
| 10 |
+
import numpy as np
|
| 11 |
+
import torch
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class _Stub:
|
| 15 |
+
"""Inert stand-in for any non-torch class in the pickle (ultralytics modules, namespaces...)."""
|
| 16 |
+
|
| 17 |
+
def __init__(self, *a, **k):
|
| 18 |
+
pass
|
| 19 |
+
|
| 20 |
+
def __setstate__(self, state):
|
| 21 |
+
if isinstance(state, tuple) and len(state) == 2: # (dict, slots)
|
| 22 |
+
state = {**(state[0] or {}), **(state[1] or {})}
|
| 23 |
+
if isinstance(state, dict):
|
| 24 |
+
self.__dict__.update(state)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
_stub_types = {}
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
class _Unpickler(pickle.Unpickler):
|
| 31 |
+
def find_class(self, module, name):
|
| 32 |
+
if module.startswith(("torch", "collections", "numpy", "builtins", "copyreg", "_codecs")) or module in (
|
| 33 |
+
"__builtin__",
|
| 34 |
+
):
|
| 35 |
+
return super().find_class(module, name)
|
| 36 |
+
key = f"{module}.{name}"
|
| 37 |
+
if key not in _stub_types:
|
| 38 |
+
_stub_types[key] = type(name, (_Stub,), {"_qualname": key})
|
| 39 |
+
return _stub_types[key]
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
_pm = types.ModuleType("stub_pickle")
|
| 43 |
+
_pm.Unpickler = _Unpickler
|
| 44 |
+
_pm.load = lambda f, **kw: _Unpickler(f, **kw).load()
|
| 45 |
+
_pm.__name__ = "pickle"
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def tname(m):
|
| 49 |
+
return getattr(m, "_qualname", type(m).__module__ + "." + type(m).__name__).split(".")[-1]
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def children(m):
|
| 53 |
+
return m.__dict__.get("_modules", {}) or {}
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def params(m):
|
| 57 |
+
d = {}
|
| 58 |
+
for k, v in (m.__dict__.get("_parameters", {}) or {}).items():
|
| 59 |
+
if v is not None:
|
| 60 |
+
d[k] = v.detach().float()
|
| 61 |
+
for k, v in (m.__dict__.get("_buffers", {}) or {}).items():
|
| 62 |
+
if v is not None:
|
| 63 |
+
d[k] = v.detach().float()
|
| 64 |
+
return d
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
ATTRS = ("f", "i", "c", "add", "n", "num_heads", "head_dim", "key_dim", "scale", "nc", "nl", "reg_max", "no",
|
| 68 |
+
"c1", "d", "dimension", "scale_factor", "mode", "kernel_size", "stride", "padding", "dilation", "groups",
|
| 69 |
+
"in_channels", "out_channels", "eps", "end2end", "_end2end", "legacy", "xyxy")
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def jsonable(v):
|
| 73 |
+
if isinstance(v, torch.Tensor):
|
| 74 |
+
return v.tolist()
|
| 75 |
+
if isinstance(v, (list, tuple)):
|
| 76 |
+
return [jsonable(x) for x in v]
|
| 77 |
+
if isinstance(v, (bool, int, float, str)) or v is None:
|
| 78 |
+
return v
|
| 79 |
+
return None
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def walk(m, path, weights, used):
|
| 83 |
+
t = tname(m)
|
| 84 |
+
node = {"type": t, "path": path}
|
| 85 |
+
for a in ATTRS:
|
| 86 |
+
if a in m.__dict__:
|
| 87 |
+
node[a] = jsonable(m.__dict__[a])
|
| 88 |
+
ch = children(m)
|
| 89 |
+
if "conv" in ch and "bn" in ch: # Conv / DWConv: Conv2d + BatchNorm2d (+act): fold BN into conv (ultralytics fuse_conv_and_bn)
|
| 90 |
+
conv, bn = ch["conv"], ch["bn"]
|
| 91 |
+
p, q = params(conv), params(bn)
|
| 92 |
+
w = p["weight"]
|
| 93 |
+
std = torch.sqrt(q["running_var"] + bn.eps)
|
| 94 |
+
g = q["weight"] / std
|
| 95 |
+
wf = w * g.view(-1, 1, 1, 1)
|
| 96 |
+
bf = q["bias"] - q["running_mean"] * g + (p["bias"] * g if "bias" in p else 0)
|
| 97 |
+
weights[path + ".w"] = wf.numpy().astype(np.float32)
|
| 98 |
+
weights[path + ".b"] = bf.numpy().astype(np.float32)
|
| 99 |
+
used.update(f"{path}.conv.{k}" for k in p)
|
| 100 |
+
used.update(f"{path}.bn.{k}" for k in q)
|
| 101 |
+
node.update(k=list(conv.kernel_size), s=list(conv.stride), p=list(conv.padding), g=conv.groups,
|
| 102 |
+
cin=conv.in_channels, cout=conv.out_channels, act=tname(ch["act"]) if "act" in ch else "Identity")
|
| 103 |
+
return node
|
| 104 |
+
if t == "Conv2d":
|
| 105 |
+
p = params(m)
|
| 106 |
+
weights[path + ".w"] = p["weight"].numpy().astype(np.float32)
|
| 107 |
+
if "bias" in p:
|
| 108 |
+
weights[path + ".b"] = p["bias"].numpy().astype(np.float32)
|
| 109 |
+
used.update(f"{path}.{k}" for k in p)
|
| 110 |
+
node.update(k=list(m.kernel_size), s=list(m.stride), p=list(m.padding), g=m.groups,
|
| 111 |
+
cin=m.in_channels, cout=m.out_channels)
|
| 112 |
+
return node
|
| 113 |
+
for k, v in params(m).items(): # e.g. Detect.stride buffers are attributes, not params; record any stray tensors
|
| 114 |
+
weights[f"{path}.{k}"] = v.numpy()
|
| 115 |
+
used.add(f"{path}.{k}")
|
| 116 |
+
node["children"] = {k: walk(v, f"{path}.{k}", weights, used) for k, v in ch.items() if v is not None}
|
| 117 |
+
return node
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
def all_keys(m, path, out):
|
| 121 |
+
for k, v in params(m).items():
|
| 122 |
+
out[f"{path}.{k}"] = tuple(v.shape)
|
| 123 |
+
for k, v in children(m).items():
|
| 124 |
+
if v is not None:
|
| 125 |
+
all_keys(v, f"{path}.{k}", out)
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
def main():
|
| 129 |
+
src, out = sys.argv[1], sys.argv[2]
|
| 130 |
+
os.makedirs(out, exist_ok=True)
|
| 131 |
+
ckpt = torch.load(src, map_location="cpu", pickle_module=_pm, weights_only=False)
|
| 132 |
+
model = ckpt.get("ema") or ckpt["model"]
|
| 133 |
+
weights, used = {}, set()
|
| 134 |
+
top = children(model)["model"]
|
| 135 |
+
layers = [walk(l, f"model.{i}", weights, used) for i, l in children(top).items()]
|
| 136 |
+
det = model.__dict__
|
| 137 |
+
keys = {}
|
| 138 |
+
all_keys(top, "model", keys)
|
| 139 |
+
names = det.get("names")
|
| 140 |
+
meta = {
|
| 141 |
+
"layers": layers,
|
| 142 |
+
"stride": jsonable(det.get("stride")),
|
| 143 |
+
"names": {int(k): v for k, v in names.items()} if isinstance(names, dict) else names,
|
| 144 |
+
"yaml": det.get("yaml") if isinstance(det.get("yaml"), dict) else None,
|
| 145 |
+
"keys_total": len(keys),
|
| 146 |
+
"keys_used": len(used & set(keys)),
|
| 147 |
+
"keys_unused": sorted(set(keys) - used),
|
| 148 |
+
}
|
| 149 |
+
with open(os.path.join(out, "model.json"), "w") as f:
|
| 150 |
+
json.dump(meta, f, indent=1, default=lambda o: None)
|
| 151 |
+
np.savez(os.path.join(out, "weights.npz"), **weights)
|
| 152 |
+
with open(os.path.join(out, "keys.txt"), "w") as f:
|
| 153 |
+
for k, s in keys.items():
|
| 154 |
+
f.write(f"{k}\t{list(s)}\t{'used' if k in used else 'UNUSED'}\n")
|
| 155 |
+
print(f"keys: {len(keys)} total, {meta['keys_used']} used; unused: {meta['keys_unused'][:10]}")
|
| 156 |
+
print(f"fused tensors: {len(weights)}, params: {sum(v.size for v in weights.values())}")
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
if __name__ == "__main__":
|
| 160 |
+
main()
|
orin-nano-gpu-int8/src/port.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"contract": 1, "model_type": "vision_detection", "runtime": "TensorRT 10.3 (Python API) + CUDA 12.6, JetPack 6", "precision": "int8", "external_files": []}
|
orin-nano-gpu-int8/src/prepost.py
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Pre- and post-processing, ported from ultralytics (reference_code commit fc26c3d).
|
| 2 |
+
|
| 3 |
+
Golden outputs match a square 640x640 letterbox (LetterBox(auto=False)), conf 0.25, IoU 0.7, max_det 300,
|
| 4 |
+
class-aware NMS, best class only (multi_label=False). See NOTES.md for how this was established.
|
| 5 |
+
"""
|
| 6 |
+
import cv2
|
| 7 |
+
import numpy as np
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
# ultralytics/data/augment.py LetterBox.get_params / apply_image (auto=False, scaleup=True, center=True, 114 pad):
|
| 11 |
+
# r = min(new_shape[0] / shape[0], new_shape[1] / shape[1])
|
| 12 |
+
# new_unpad = round(shape[1] * r), round(shape[0] * r)
|
| 13 |
+
# dw, dh = new_shape[1] - new_unpad[0], new_shape[0] - new_unpad[1]
|
| 14 |
+
# dw /= 2; dh /= 2
|
| 15 |
+
# top, bottom = round(dh - 0.1), round(dh + 0.1); left, right = round(dw - 0.1), round(dw + 0.1)
|
| 16 |
+
# img = cv2.resize(img, new_unpad, interpolation=cv2.INTER_LINEAR)
|
| 17 |
+
# img = cv2.copyMakeBorder(img, top, bottom, left, right, cv2.BORDER_CONSTANT, value=(114,) * 3)
|
| 18 |
+
def letterbox(img, new_shape=(640, 640), out=None):
|
| 19 |
+
shape = img.shape[:2]
|
| 20 |
+
r = min(new_shape[0] / shape[0], new_shape[1] / shape[1])
|
| 21 |
+
new_unpad = round(shape[1] * r), round(shape[0] * r)
|
| 22 |
+
dw, dh = (new_shape[1] - new_unpad[0]) / 2, (new_shape[0] - new_unpad[1]) / 2
|
| 23 |
+
top, bottom = round(dh - 0.1), round(dh + 0.1)
|
| 24 |
+
left, right = round(dw - 0.1), round(dw + 0.1)
|
| 25 |
+
if out is None:
|
| 26 |
+
out = np.empty((new_shape[0], new_shape[1], 3), np.uint8)
|
| 27 |
+
# same pixels as resize + copyMakeBorder, written straight into the (pinned) input buffer
|
| 28 |
+
out[:top] = 114
|
| 29 |
+
out[top + new_unpad[1]:] = 114
|
| 30 |
+
out[top:top + new_unpad[1], :left] = 114
|
| 31 |
+
out[top:top + new_unpad[1], left + new_unpad[0]:] = 114
|
| 32 |
+
dst = out[top:top + new_unpad[1], left:left + new_unpad[0]]
|
| 33 |
+
if shape[::-1] != new_unpad:
|
| 34 |
+
dst[...] = cv2.resize(img, new_unpad, interpolation=cv2.INTER_LINEAR)
|
| 35 |
+
else:
|
| 36 |
+
dst[...] = img
|
| 37 |
+
return out
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
# ultralytics/utils/nms.py non_max_suppression (multi_label=False, agnostic=False, max_wh=7680, max_nms=30000):
|
| 41 |
+
# xc = prediction[:, 4:mi].amax(1) > conf_thres
|
| 42 |
+
# conf, j = cls.max(1, keepdim=True); x = torch.cat((box, conf, j.float(), mask), 1)[conf.view(-1) > conf_thres]
|
| 43 |
+
# if n > max_nms: x = x[x[:, 4].argsort(descending=True)[:max_nms]]
|
| 44 |
+
# c = x[:, 5:6] * max_wh; boxes = x[:, :4] + c; i = torchvision.ops.nms(boxes, scores, iou_thres)[:max_det]
|
| 45 |
+
# The engine already gives, per anchor, xyxy box, max class score (sigmoid) and its class id.
|
| 46 |
+
def nms(pred, conf_thres=0.25, iou_thres=0.7, max_det=300, max_nms=30000, max_wh=7680):
|
| 47 |
+
"""pred: [6, A] float32 rows x1, y1, x2, y2, conf, cls. Returns [n, 6] rows (x1, y1, x2, y2, conf, cls)."""
|
| 48 |
+
keep = pred[4] > conf_thres
|
| 49 |
+
x = pred[:, keep].T.astype(np.float32)
|
| 50 |
+
if not len(x):
|
| 51 |
+
return np.zeros((0, 6), np.float32)
|
| 52 |
+
order = np.argsort(-x[:, 4], kind="stable")
|
| 53 |
+
if len(order) > max_nms:
|
| 54 |
+
order = order[:max_nms]
|
| 55 |
+
x = x[order]
|
| 56 |
+
b = x[:, :4] + x[:, 5:6] * max_wh
|
| 57 |
+
areas = (b[:, 2] - b[:, 0]) * (b[:, 3] - b[:, 1])
|
| 58 |
+
# torchvision.ops.nms: greedy in descending score order, drop boxes with IoU > iou_thres
|
| 59 |
+
n = len(b)
|
| 60 |
+
suppressed = np.zeros(n, bool)
|
| 61 |
+
kept = []
|
| 62 |
+
for i in range(n):
|
| 63 |
+
if suppressed[i]:
|
| 64 |
+
continue
|
| 65 |
+
kept.append(i)
|
| 66 |
+
if len(kept) >= max_det:
|
| 67 |
+
break
|
| 68 |
+
rest = np.arange(i + 1, n)
|
| 69 |
+
rest = rest[~suppressed[rest]]
|
| 70 |
+
if not len(rest):
|
| 71 |
+
break
|
| 72 |
+
xx1 = np.maximum(b[i, 0], b[rest, 0])
|
| 73 |
+
yy1 = np.maximum(b[i, 1], b[rest, 1])
|
| 74 |
+
xx2 = np.minimum(b[i, 2], b[rest, 2])
|
| 75 |
+
yy2 = np.minimum(b[i, 3], b[rest, 3])
|
| 76 |
+
inter = np.clip(xx2 - xx1, 0, None) * np.clip(yy2 - yy1, 0, None)
|
| 77 |
+
iou = inter / (areas[i] + areas[rest] - inter)
|
| 78 |
+
suppressed[rest[iou > iou_thres]] = True
|
| 79 |
+
return x[kept]
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
# ultralytics/utils/ops.py scale_boxes (ratio_pad=None, padding=True, xywh=False) + clip_boxes:
|
| 83 |
+
# gain = min(img1_shape[0] / img0_shape[0], img1_shape[1] / img0_shape[1])
|
| 84 |
+
# new_h, new_w = round(img0_shape[0] * gain), round(img0_shape[1] * gain)
|
| 85 |
+
# gain_y, gain_x = new_h / img0_shape[0], new_w / img0_shape[1]
|
| 86 |
+
# pad_x, pad_y = round((img1_shape[1] - new_w) / 2 - 0.1), round((img1_shape[0] - new_h) / 2 - 0.1)
|
| 87 |
+
# boxes[..., [0, 2]] -= pad_x; boxes[..., [1, 3]] -= pad_y; boxes[..., [0, 2]] /= gain_x; boxes[..., [1, 3]] /= gain_y
|
| 88 |
+
# boxes[..., [0, 2]] = boxes[..., [0, 2]].clip(0, w); boxes[..., [1, 3]] = boxes[..., [1, 3]].clip(0, h)
|
| 89 |
+
def scale_boxes(img1_shape, boxes, img0_shape):
|
| 90 |
+
gain = min(img1_shape[0] / img0_shape[0], img1_shape[1] / img0_shape[1])
|
| 91 |
+
new_h, new_w = round(img0_shape[0] * gain), round(img0_shape[1] * gain)
|
| 92 |
+
gain_y, gain_x = new_h / img0_shape[0], new_w / img0_shape[1]
|
| 93 |
+
pad_x, pad_y = round((img1_shape[1] - new_w) / 2 - 0.1), round((img1_shape[0] - new_h) / 2 - 0.1)
|
| 94 |
+
boxes = boxes.astype(np.float32).copy()
|
| 95 |
+
boxes[:, [0, 2]] -= pad_x
|
| 96 |
+
boxes[:, [1, 3]] -= pad_y
|
| 97 |
+
boxes[:, [0, 2]] /= gain_x
|
| 98 |
+
boxes[:, [1, 3]] /= gain_y
|
| 99 |
+
boxes[:, [0, 2]] = boxes[:, [0, 2]].clip(0, img0_shape[1])
|
| 100 |
+
boxes[:, [1, 3]] = boxes[:, [1, 3]].clip(0, img0_shape[0])
|
| 101 |
+
return boxes
|
orin-nano-gpu-int8/src/run.py
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""YOLO11 detection on TensorRT (port of ultralytics YOLO.predict with default settings).
|
| 2 |
+
|
| 3 |
+
sh run.sh --image IN.jpg [--image IN2.jpg ...] [--repeat R] --out OUT.json --metrics M.json
|
| 4 |
+
"""
|
| 5 |
+
import time
|
| 6 |
+
|
| 7 |
+
T0 = time.monotonic()
|
| 8 |
+
|
| 9 |
+
import argparse
|
| 10 |
+
import json
|
| 11 |
+
import os
|
| 12 |
+
import resource
|
| 13 |
+
import sys
|
| 14 |
+
|
| 15 |
+
import cv2
|
| 16 |
+
import numpy as np
|
| 17 |
+
import tensorrt as trt
|
| 18 |
+
|
| 19 |
+
HERE = os.path.dirname(os.path.abspath(__file__))
|
| 20 |
+
sys.path.insert(0, HERE)
|
| 21 |
+
import cudart # noqa: E402
|
| 22 |
+
from prepost import letterbox, nms, scale_boxes # noqa: E402
|
| 23 |
+
|
| 24 |
+
CONF, IOU, MAX_DET = 0.25, 0.7, 300 # ultralytics predict defaults (cfg/default.yaml; conf defaults to 0.25)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class Detector:
|
| 28 |
+
def __init__(self, engine_path):
|
| 29 |
+
self.logger = trt.Logger(trt.Logger.WARNING)
|
| 30 |
+
self.runtime = trt.Runtime(self.logger)
|
| 31 |
+
with open(engine_path, "rb") as f:
|
| 32 |
+
self.engine = self.runtime.deserialize_cuda_engine(f.read())
|
| 33 |
+
self.ctx = self.engine.create_execution_context()
|
| 34 |
+
self.stream = cudart.stream_create()
|
| 35 |
+
self.in_shape = tuple(self.engine.get_tensor_shape("images")) # (1, 640, 640, 3) uint8
|
| 36 |
+
self.out_shape = tuple(self.engine.get_tensor_shape("output")) # (1, 6, A) float32
|
| 37 |
+
self.imgsz = self.in_shape[1:3]
|
| 38 |
+
n_in = int(np.prod(self.in_shape))
|
| 39 |
+
n_out = int(np.prod(self.out_shape)) * 4
|
| 40 |
+
self.d_in, self.d_out = cudart.malloc(n_in), cudart.malloc(n_out)
|
| 41 |
+
self.h_in_p, self.h_out_p = cudart.malloc_host(n_in), cudart.malloc_host(n_out)
|
| 42 |
+
self.h_in = np.ctypeslib.as_array((ctypes_u8 * n_in).from_address(self.h_in_p)).reshape(self.in_shape[1:])
|
| 43 |
+
self.h_out = np.ctypeslib.as_array((ctypes_f32 * (n_out // 4)).from_address(self.h_out_p)).reshape(
|
| 44 |
+
self.out_shape[1:])
|
| 45 |
+
self.ctx.set_tensor_address("images", self.d_in)
|
| 46 |
+
self.ctx.set_tensor_address("output", self.d_out)
|
| 47 |
+
|
| 48 |
+
def __call__(self, im0):
|
| 49 |
+
letterbox(im0, self.imgsz, out=self.h_in)
|
| 50 |
+
cudart.memcpy_async(self.d_in, self.h_in_p, self.h_in.nbytes, cudart.H2D, self.stream)
|
| 51 |
+
if not self.ctx.execute_async_v3(self.stream):
|
| 52 |
+
raise RuntimeError("TensorRT execution failed")
|
| 53 |
+
cudart.memcpy_async(self.h_out_p, self.d_out, self.h_out.nbytes, cudart.D2H, self.stream)
|
| 54 |
+
cudart.stream_sync(self.stream)
|
| 55 |
+
det = nms(self.h_out, CONF, IOU, MAX_DET)
|
| 56 |
+
boxes = scale_boxes(self.imgsz, det[:, :4], im0.shape)
|
| 57 |
+
return {"boxes": boxes.tolist(), "scores": det[:, 4].tolist(), "classes": det[:, 5].astype(int).tolist()}
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
import ctypes # noqa: E402
|
| 61 |
+
|
| 62 |
+
ctypes_u8, ctypes_f32 = ctypes.c_uint8, ctypes.c_float
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def main():
|
| 66 |
+
ap = argparse.ArgumentParser()
|
| 67 |
+
ap.add_argument("--image", action="append", required=True)
|
| 68 |
+
ap.add_argument("--repeat", type=int, default=1)
|
| 69 |
+
ap.add_argument("--out", required=True)
|
| 70 |
+
ap.add_argument("--metrics", required=True)
|
| 71 |
+
ap.add_argument("--engine", default=os.path.join(HERE, "model.engine"))
|
| 72 |
+
a = ap.parse_args()
|
| 73 |
+
|
| 74 |
+
det = Detector(a.engine)
|
| 75 |
+
imgs = []
|
| 76 |
+
for p in a.image: # decoding the JPEG counts as loading the input (ultralytics uses cv2.imread, BGR)
|
| 77 |
+
im = cv2.imread(p, cv2.IMREAD_COLOR)
|
| 78 |
+
if im is None:
|
| 79 |
+
raise SystemExit(f"cannot read image {p}")
|
| 80 |
+
imgs.append(im)
|
| 81 |
+
det(imgs[0]) # warm-up (lazy CUDA module loading), not reported as a request
|
| 82 |
+
load_ms = (time.monotonic() - T0) * 1000
|
| 83 |
+
|
| 84 |
+
runs, results = [], None
|
| 85 |
+
for _ in range(max(1, a.repeat)):
|
| 86 |
+
t = time.monotonic()
|
| 87 |
+
results = [det(im) for im in imgs]
|
| 88 |
+
runs.append({"total_ms": (time.monotonic() - t) * 1000})
|
| 89 |
+
|
| 90 |
+
out = results[0] if len(results) == 1 else {"images": results}
|
| 91 |
+
with open(a.out, "w") as f:
|
| 92 |
+
json.dump(out, f)
|
| 93 |
+
peak = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1024
|
| 94 |
+
with open(a.metrics, "w") as f:
|
| 95 |
+
json.dump({"load_ms": load_ms, "runs": runs, "peak_mem_mb": round(peak, 1)}, f)
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
if __name__ == "__main__":
|
| 99 |
+
main()
|
orin-nano-gpu-int8/src/run.sh
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Entry point (POSIX sh). sh ./run.sh --image IN.jpg [--repeat R] --out OUT.json --metrics M.json
|
| 2 |
+
cd "$(dirname "$0")" || exit 1
|
| 3 |
+
export LD_LIBRARY_PATH="/usr/local/cuda/lib64:/usr/lib/aarch64-linux-gnu${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
|
| 4 |
+
exec python3 run.py "$@"
|
orin-nano-gpu-int8/src/tools/calib_stats.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Collect activation ranges at every conv input of the reference model (for explicit INT8 Q/DQ).
|
| 2 |
+
|
| 3 |
+
Runs the customer's fused ultralytics model in fp32 on CPU over calibration images, letterboxed exactly like
|
| 4 |
+
inference, and records per image the max |x| of each conv's input. Output: JSON {module path: [amax per image]}.
|
| 5 |
+
Needs the reference code importable (ultralytics + its deps, e.g. opencv) and torch.
|
| 6 |
+
|
| 7 |
+
usage: python calib_stats.py WEIGHTS.pt IMAGE_DIR OUT.json
|
| 8 |
+
"""
|
| 9 |
+
import glob, json, os, sys
|
| 10 |
+
|
| 11 |
+
import cv2
|
| 12 |
+
import numpy as np
|
| 13 |
+
import torch
|
| 14 |
+
|
| 15 |
+
sys.path.insert(0, os.environ.get("ULTRALYTICS_SRC", "/work/inputs/reference_code"))
|
| 16 |
+
from ultralytics import YOLO # noqa: E402
|
| 17 |
+
from ultralytics.data.augment import LetterBox # noqa: E402
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def main():
|
| 21 |
+
w, d, out = sys.argv[1:4]
|
| 22 |
+
model = YOLO(w).model.float().fuse().eval()
|
| 23 |
+
stats, hooks = {}, []
|
| 24 |
+
for name, m in model.named_modules():
|
| 25 |
+
t = type(m).__name__
|
| 26 |
+
is_conv = t in ("Conv", "DWConv") or (t == "Conv2d" and not name.endswith(".conv"))
|
| 27 |
+
if is_conv and not name.endswith(".dfl.conv"):
|
| 28 |
+
stats[name] = []
|
| 29 |
+
hooks.append(m.register_forward_hook(
|
| 30 |
+
lambda mod, inp, outp, n=name: stats[n].append(float(inp[0].abs().amax()))))
|
| 31 |
+
files = sorted(glob.glob(os.path.join(d, "*.jpg")))
|
| 32 |
+
lb = LetterBox(640, auto=False)
|
| 33 |
+
with torch.no_grad():
|
| 34 |
+
for f in files:
|
| 35 |
+
im = lb(image=cv2.imread(f))
|
| 36 |
+
x = torch.from_numpy(im[..., ::-1].copy()).permute(2, 0, 1)[None].float() / 255
|
| 37 |
+
model(x)
|
| 38 |
+
with open(out, "w") as fh:
|
| 39 |
+
json.dump({"images": len(files), "amax": stats}, fh)
|
| 40 |
+
print(f"{len(stats)} conv inputs over {len(files)} images -> {out}")
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
if __name__ == "__main__":
|
| 44 |
+
main()
|
orin-nano-gpu-int8/src/tools/sensitivity.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Per-layer INT8 sensitivity with simulated quantization (fake-quant) of the reference model on CPU.
|
| 2 |
+
|
| 3 |
+
Same quantizer as the explicit-Q/DQ engine: per-tensor activation scale amax/127 at each conv input, per-output-channel
|
| 4 |
+
weight scale. Compares detections with the fp32 model's (recall at score>=0.3, mean IoU, mean score drift).
|
| 5 |
+
usage: python sensitivity.py WEIGHTS.pt act_amax.json EVAL_IMAGE_DIR [skip-set ...]
|
| 6 |
+
"""
|
| 7 |
+
import copy, glob, json, os, sys
|
| 8 |
+
|
| 9 |
+
import cv2
|
| 10 |
+
import numpy as np
|
| 11 |
+
import torch
|
| 12 |
+
|
| 13 |
+
sys.path.insert(0, os.environ.get("ULTRALYTICS_SRC", "/work/inputs/reference_code"))
|
| 14 |
+
from ultralytics import YOLO # noqa: E402
|
| 15 |
+
from ultralytics.data.augment import LetterBox # noqa: E402
|
| 16 |
+
from ultralytics.utils import nms # noqa: E402
|
| 17 |
+
|
| 18 |
+
torch.set_num_threads(12)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def fq(x, s):
|
| 22 |
+
return torch.clamp(torch.round(x / s), -127, 127) * s
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def quantize_model(base, amax, skip):
|
| 26 |
+
m = copy.deepcopy(base)
|
| 27 |
+
for name, mod in m.named_modules():
|
| 28 |
+
if name not in amax or any(name == k or name.startswith(k + ".") for k in skip):
|
| 29 |
+
continue
|
| 30 |
+
conv = mod.conv if hasattr(mod, "conv") else mod
|
| 31 |
+
w = conv.weight.data
|
| 32 |
+
ws = w.abs().reshape(w.shape[0], -1).amax(1).clamp(min=1e-8).view(-1, 1, 1, 1) / 127
|
| 33 |
+
conv.weight.data = fq(w, ws)
|
| 34 |
+
s = max(amax[name], 1e-6) / 127
|
| 35 |
+
mod.register_forward_pre_hook(lambda md, inp, s=s: (fq(inp[0], s),))
|
| 36 |
+
return m
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def detect(m, xs):
|
| 40 |
+
out = []
|
| 41 |
+
with torch.no_grad():
|
| 42 |
+
for x in xs:
|
| 43 |
+
out.append(nms.non_max_suppression(m(x)[0], 0.25, 0.7, max_det=300)[0].numpy())
|
| 44 |
+
return out
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def iou(a, b):
|
| 48 |
+
x1, y1 = np.maximum(a[0], b[:, 0]), np.maximum(a[1], b[:, 1])
|
| 49 |
+
x2, y2 = np.minimum(a[2], b[:, 2]), np.minimum(a[3], b[:, 3])
|
| 50 |
+
i = np.clip(x2 - x1, 0, None) * np.clip(y2 - y1, 0, None)
|
| 51 |
+
return i / ((a[2] - a[0]) * (a[3] - a[1]) + (b[:, 2] - b[:, 0]) * (b[:, 3] - b[:, 1]) - i)
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def score(ref, port, thr=0.3, margin=0.05):
|
| 55 |
+
found = tot = 0
|
| 56 |
+
ious, drift = [], []
|
| 57 |
+
pc = pt = 0
|
| 58 |
+
for r, p in zip(ref, port):
|
| 59 |
+
for side, other, count in ((r, p, True), (p, r, False)):
|
| 60 |
+
for d in side[side[:, 4] >= thr]:
|
| 61 |
+
cand = other[(other[:, 5] == d[5]) & (other[:, 4] >= thr - margin)]
|
| 62 |
+
ok = False
|
| 63 |
+
if len(cand):
|
| 64 |
+
v = iou(d[:4], cand[:, :4])
|
| 65 |
+
j = v.argmax()
|
| 66 |
+
if v[j] >= 0.5:
|
| 67 |
+
ok = True
|
| 68 |
+
if count:
|
| 69 |
+
ious.append(v[j]); drift.append(abs(cand[j, 4] - d[4]))
|
| 70 |
+
if count:
|
| 71 |
+
tot += 1; found += ok
|
| 72 |
+
else:
|
| 73 |
+
pt += 1; pc += ok
|
| 74 |
+
return found / max(tot, 1), pc / max(pt, 1), float(np.mean(ious)), float(np.mean(drift))
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def main():
|
| 78 |
+
w, amax_f, d = sys.argv[1:4]
|
| 79 |
+
st = json.load(open(amax_f))["amax"]
|
| 80 |
+
amax = {k: float(np.max(v)) for k, v in st.items()}
|
| 81 |
+
base_skip = ["model.0"] + [f"model.23.cv{b}.{i}.2" for b in (2, 3) for i in range(3)]
|
| 82 |
+
base = YOLO(w).model.float().fuse().eval()
|
| 83 |
+
lb = LetterBox(640, auto=False)
|
| 84 |
+
xs = [torch.from_numpy(lb(image=cv2.imread(f))[..., ::-1].copy()).permute(2, 0, 1)[None].float() / 255
|
| 85 |
+
for f in sorted(glob.glob(os.path.join(d, "*.jpg")))]
|
| 86 |
+
ref = detect(base, xs)
|
| 87 |
+
groups = sys.argv[4:] or ["all"] + [f"model.{i}" for i in range(1, 23)] + \
|
| 88 |
+
[f"model.23.cv2", "model.23.cv3"]
|
| 89 |
+
for g in groups:
|
| 90 |
+
skip = base_skip + ([] if g == "all" else g.split("+"))
|
| 91 |
+
r = score(ref, detect(quantize_model(base, amax, skip), xs))
|
| 92 |
+
print(f"fp16 {g:30s} recall {r[0]:.3f} precision {r[1]:.3f} iou {r[2]:.4f} drift {r[3]:.4f}", flush=True)
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
if __name__ == "__main__":
|
| 96 |
+
main()
|