From 3b04f445916e87dae6cfbbdd9d32ddb339df1491 Mon Sep 17 00:00:00 2001 From: "hongliang.yuan" Date: Mon, 15 Dec 2025 10:02:15 +0800 Subject: [PATCH] fix ixrt bindingIndex error --- .../object_detection/yolov10/ixrt/README.md | 5 - .../yolov10/ixrt/build_engine.py | 51 +++------- .../yolov10/ixrt/ci/prepare.sh | 2 +- .../yolov10/ixrt/inference.py | 2 +- .../object_detection/yolov11/ixrt/README.md | 5 - .../yolov11/ixrt/build_engine.py | 51 +++------- .../yolov11/ixrt/ci/prepare.sh | 9 -- .../yolov11/ixrt/inference.py | 2 +- .../yolov12/igie/ci/prepare.sh | 11 +-- .../yolov12/ixrt/build_engine.py | 51 +++------- .../yolov12/ixrt/ci/prepare.sh | 2 +- .../yolov12/ixrt/inference.py | 2 +- .../yolov13/ixrt/build_engine.py | 51 +++------- .../yolov13/ixrt/inference.py | 2 +- .../yolov6/ixrt/build_engine.py | 51 +++------- .../yolov6/ixrt/ci/prepare.sh | 9 -- .../cv/object_detection/yolov6/ixrt/deploy.py | 99 ------------------- .../object_detection/yolov6/ixrt/inference.py | 2 +- .../scripts/infer_yolov6_fp16_performance.sh | 12 --- .../cv/object_detection/yolov8/ixrt/README.md | 10 -- .../yolov8/ixrt/build_engine.py | 51 +++------- .../yolov8/ixrt/ci/prepare.sh | 9 -- .../object_detection/yolov8/ixrt/inference.py | 2 +- .../cv/object_detection/yolov9/ixrt/README.md | 10 -- .../yolov9/ixrt/build_engine.py | 51 +++------- .../yolov9/ixrt/ci/prepare.sh | 9 -- .../object_detection/yolov9/ixrt/inference.py | 2 +- .../object_detection/yolox/igie/ci/prepare.sh | 2 +- 28 files changed, 95 insertions(+), 470 deletions(-) delete mode 100644 models/cv/object_detection/yolov6/ixrt/deploy.py diff --git a/models/cv/object_detection/yolov10/ixrt/README.md b/models/cv/object_detection/yolov10/ixrt/README.md index daac6bd4..c94d1abf 100644 --- a/models/cv/object_detection/yolov10/ixrt/README.md +++ b/models/cv/object_detection/yolov10/ixrt/README.md @@ -48,13 +48,8 @@ coco ### Install Dependencies -Contact the Iluvatar administrator to get the missing packages: - -- mmcv-2.1.0+corex.4.3.0-cp310-cp310-linux_x86_64.whl - ```bash pip3 install -r requirements.txt -pip3 install mmcv-2.1.0+corex.4.3.0-cp310-cp310-linux_x86_64.whl ``` ## Model Conversion diff --git a/models/cv/object_detection/yolov10/ixrt/build_engine.py b/models/cv/object_detection/yolov10/ixrt/build_engine.py index e0839fc3..7422eea5 100644 --- a/models/cv/object_detection/yolov10/ixrt/build_engine.py +++ b/models/cv/object_detection/yolov10/ixrt/build_engine.py @@ -12,37 +12,11 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -import os -import cv2 import argparse -import numpy as np - -import torch import tensorrt from tensorrt import Dims - -def build_engine_trtapi_staticshape(config): - IXRT_LOGGER = tensorrt.Logger(tensorrt.Logger.WARNING) - builder = tensorrt.Builder(IXRT_LOGGER) - EXPLICIT_BATCH = 1 << (int)(tensorrt.NetworkDefinitionCreationFlag.EXPLICIT_BATCH) - network = builder.create_network(EXPLICIT_BATCH) - build_config = builder.create_builder_config() - parser = tensorrt.OnnxParser(network, IXRT_LOGGER) - parser.parse_from_file(config.model) - - precision = tensorrt.BuilderFlag.INT8 if config.precision == "int8" else tensorrt.BuilderFlag.FP16 - # print("precision : ", precision) - build_config.set_flag(precision) - - plan = builder.build_serialized_network(network, build_config) - engine_file_path = config.engine - with open(engine_file_path, "wb") as f: - f.write(plan) - print("Build static shape engine done!") - - -def build_engine_trtapi_dynamicshape(config): +def main(config): IXRT_LOGGER = tensorrt.Logger(tensorrt.Logger.WARNING) builder = tensorrt.Builder(IXRT_LOGGER) EXPLICIT_BATCH = 1 << (int)(tensorrt.NetworkDefinitionCreationFlag.EXPLICIT_BATCH) @@ -50,24 +24,26 @@ def build_engine_trtapi_dynamicshape(config): build_config = builder.create_builder_config() profile = builder.create_optimization_profile() - profile.set_shape("input", - Dims([1, 3, 608, 608]), - Dims([32, 3, 608, 608]), - Dims([64, 3, 608, 608]), + profile.set_shape("images", + Dims([1, 3, 640, 640]), + Dims([32, 3, 640, 640]), + Dims([64, 3, 640, 640]), ) build_config.add_optimization_profile(profile) parser = tensorrt.OnnxParser(network, IXRT_LOGGER) parser.parse_from_file(config.model) - precision = tensorrt.BuilderFlag.INT8 if config.precision == "int8" else tensorrt.BuilderFlag.FP16 - # print("precision : ", precision) - build_config.set_flag(precision) + if config.precision == "int8": + build_config.set_flag(tensorrt.BuilderFlag.FP16) + build_config.set_flag(tensorrt.BuilderFlag.INT8) + else: + build_config.set_flag(tensorrt.BuilderFlag.FP16) # set dynamic num_inputs = network.num_inputs for i in range(num_inputs): input_tensor = network.get_input(i) - input_tensor.shape = Dims([-1, 3, 608, 608]) + input_tensor.shape = Dims([32, 3, 640, 640]) plan = builder.build_serialized_network(network, build_config) engine_file_path = config.engine @@ -75,7 +51,6 @@ def build_engine_trtapi_dynamicshape(config): f.write(plan) print("Build dynamic shape engine done!") - def parse_args(): parser = argparse.ArgumentParser() parser.add_argument("--model", type=str) @@ -87,8 +62,6 @@ def parse_args(): args = parser.parse_args() return args - if __name__ == "__main__": args = parse_args() - build_engine_trtapi_staticshape(args) - # build_engine_trtapi_dynamicshape(args) + main(args) diff --git a/models/cv/object_detection/yolov10/ixrt/ci/prepare.sh b/models/cv/object_detection/yolov10/ixrt/ci/prepare.sh index 349298aa..bcc291a6 100644 --- a/models/cv/object_detection/yolov10/ixrt/ci/prepare.sh +++ b/models/cv/object_detection/yolov10/ixrt/ci/prepare.sh @@ -21,4 +21,4 @@ pip3 install -r requirements.txt mkdir checkpoints mv yolov10s.pt yolov10.pt python3 export.py --weight yolov10.pt --batch 32 -mv yolov10.onnx checkpoints/ +mv yolov10.onnx checkpoints/ \ No newline at end of file diff --git a/models/cv/object_detection/yolov10/ixrt/inference.py b/models/cv/object_detection/yolov10/ixrt/inference.py index 1ac908a7..3937087c 100644 --- a/models/cv/object_detection/yolov10/ixrt/inference.py +++ b/models/cv/object_detection/yolov10/ixrt/inference.py @@ -119,7 +119,7 @@ class IxRT_Validator(DetectionValidator): total_num = 0 - input_name = "input" + input_name = "images" host_mem = tensorrt.IHostMemory logger = tensorrt.Logger(tensorrt.Logger.ERROR) engine, context = create_engine_context(config.model_engine, logger) diff --git a/models/cv/object_detection/yolov11/ixrt/README.md b/models/cv/object_detection/yolov11/ixrt/README.md index 064763ca..d4b49417 100644 --- a/models/cv/object_detection/yolov11/ixrt/README.md +++ b/models/cv/object_detection/yolov11/ixrt/README.md @@ -48,13 +48,8 @@ coco ### Install Dependencies -Contact the Iluvatar administrator to get the missing packages: - -- mmcv-2.1.0+corex.4.3.0-cp310-cp310-linux_x86_64.whl - ```bash pip3 install -r requirements.txt -pip3 install mmcv-2.1.0+corex.4.3.0-cp310-cp310-linux_x86_64.whl ``` ## Model Conversion diff --git a/models/cv/object_detection/yolov11/ixrt/build_engine.py b/models/cv/object_detection/yolov11/ixrt/build_engine.py index e0839fc3..d486d187 100644 --- a/models/cv/object_detection/yolov11/ixrt/build_engine.py +++ b/models/cv/object_detection/yolov11/ixrt/build_engine.py @@ -12,37 +12,11 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -import os -import cv2 import argparse -import numpy as np - -import torch import tensorrt from tensorrt import Dims - -def build_engine_trtapi_staticshape(config): - IXRT_LOGGER = tensorrt.Logger(tensorrt.Logger.WARNING) - builder = tensorrt.Builder(IXRT_LOGGER) - EXPLICIT_BATCH = 1 << (int)(tensorrt.NetworkDefinitionCreationFlag.EXPLICIT_BATCH) - network = builder.create_network(EXPLICIT_BATCH) - build_config = builder.create_builder_config() - parser = tensorrt.OnnxParser(network, IXRT_LOGGER) - parser.parse_from_file(config.model) - - precision = tensorrt.BuilderFlag.INT8 if config.precision == "int8" else tensorrt.BuilderFlag.FP16 - # print("precision : ", precision) - build_config.set_flag(precision) - - plan = builder.build_serialized_network(network, build_config) - engine_file_path = config.engine - with open(engine_file_path, "wb") as f: - f.write(plan) - print("Build static shape engine done!") - - -def build_engine_trtapi_dynamicshape(config): +def main(config): IXRT_LOGGER = tensorrt.Logger(tensorrt.Logger.WARNING) builder = tensorrt.Builder(IXRT_LOGGER) EXPLICIT_BATCH = 1 << (int)(tensorrt.NetworkDefinitionCreationFlag.EXPLICIT_BATCH) @@ -50,24 +24,26 @@ def build_engine_trtapi_dynamicshape(config): build_config = builder.create_builder_config() profile = builder.create_optimization_profile() - profile.set_shape("input", - Dims([1, 3, 608, 608]), - Dims([32, 3, 608, 608]), - Dims([64, 3, 608, 608]), + profile.set_shape("images", + Dims([1, 3, 640, 640]), + Dims([32, 3, 640, 640]), + Dims([64, 3, 640, 640]), ) build_config.add_optimization_profile(profile) parser = tensorrt.OnnxParser(network, IXRT_LOGGER) parser.parse_from_file(config.model) - precision = tensorrt.BuilderFlag.INT8 if config.precision == "int8" else tensorrt.BuilderFlag.FP16 - # print("precision : ", precision) - build_config.set_flag(precision) + if config.precision == "int8": + build_config.set_flag(tensorrt.BuilderFlag.FP16) + build_config.set_flag(tensorrt.BuilderFlag.INT8) + else: + build_config.set_flag(tensorrt.BuilderFlag.FP16) # set dynamic num_inputs = network.num_inputs for i in range(num_inputs): input_tensor = network.get_input(i) - input_tensor.shape = Dims([-1, 3, 608, 608]) + input_tensor.shape = Dims([-1, 3, 640, 640]) plan = builder.build_serialized_network(network, build_config) engine_file_path = config.engine @@ -75,7 +51,6 @@ def build_engine_trtapi_dynamicshape(config): f.write(plan) print("Build dynamic shape engine done!") - def parse_args(): parser = argparse.ArgumentParser() parser.add_argument("--model", type=str) @@ -87,8 +62,6 @@ def parse_args(): args = parser.parse_args() return args - if __name__ == "__main__": args = parse_args() - build_engine_trtapi_staticshape(args) - # build_engine_trtapi_dynamicshape(args) + main(args) diff --git a/models/cv/object_detection/yolov11/ixrt/ci/prepare.sh b/models/cv/object_detection/yolov11/ixrt/ci/prepare.sh index a011f236..85c60f15 100644 --- a/models/cv/object_detection/yolov11/ixrt/ci/prepare.sh +++ b/models/cv/object_detection/yolov11/ixrt/ci/prepare.sh @@ -16,15 +16,6 @@ set -x -ID=$(grep -oP '(?<=^ID=).+' /etc/os-release | tr -d '"') -if [[ ${ID} == "ubuntu" ]]; then - apt install -y libgl1-mesa-glx -elif [[ ${ID} == "centos" ]]; then - yum install -y mesa-libGL -else - echo "Not Support Os" -fi - pip3 install -r requirements.txt mkdir checkpoints diff --git a/models/cv/object_detection/yolov11/ixrt/inference.py b/models/cv/object_detection/yolov11/ixrt/inference.py index 1ac908a7..3937087c 100644 --- a/models/cv/object_detection/yolov11/ixrt/inference.py +++ b/models/cv/object_detection/yolov11/ixrt/inference.py @@ -119,7 +119,7 @@ class IxRT_Validator(DetectionValidator): total_num = 0 - input_name = "input" + input_name = "images" host_mem = tensorrt.IHostMemory logger = tensorrt.Logger(tensorrt.Logger.ERROR) engine, context = create_engine_context(config.model_engine, logger) diff --git a/models/cv/object_detection/yolov12/igie/ci/prepare.sh b/models/cv/object_detection/yolov12/igie/ci/prepare.sh index 44a36b9a..bf5afa3a 100644 --- a/models/cv/object_detection/yolov12/igie/ci/prepare.sh +++ b/models/cv/object_detection/yolov12/igie/ci/prepare.sh @@ -16,18 +16,9 @@ set -x -ID=$(grep -oP '(?<=^ID=).+' /etc/os-release | tr -d '"') -if [[ ${ID} == "ubuntu" ]]; then - apt install -y libgl1-mesa-glx -elif [[ ${ID} == "centos" ]]; then - yum install -y mesa-libGL -else - echo "Not Support Os" -fi - pip3 install -r requirements.txt -git clone --depth 1 https://github.com/sunsmarterjie/yolov12.git +cp -r /mnt/deepspark/data/3rd_party/yolov12 ./ cd yolov12 pip3 install -e . diff --git a/models/cv/object_detection/yolov12/ixrt/build_engine.py b/models/cv/object_detection/yolov12/ixrt/build_engine.py index e0839fc3..d486d187 100644 --- a/models/cv/object_detection/yolov12/ixrt/build_engine.py +++ b/models/cv/object_detection/yolov12/ixrt/build_engine.py @@ -12,37 +12,11 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -import os -import cv2 import argparse -import numpy as np - -import torch import tensorrt from tensorrt import Dims - -def build_engine_trtapi_staticshape(config): - IXRT_LOGGER = tensorrt.Logger(tensorrt.Logger.WARNING) - builder = tensorrt.Builder(IXRT_LOGGER) - EXPLICIT_BATCH = 1 << (int)(tensorrt.NetworkDefinitionCreationFlag.EXPLICIT_BATCH) - network = builder.create_network(EXPLICIT_BATCH) - build_config = builder.create_builder_config() - parser = tensorrt.OnnxParser(network, IXRT_LOGGER) - parser.parse_from_file(config.model) - - precision = tensorrt.BuilderFlag.INT8 if config.precision == "int8" else tensorrt.BuilderFlag.FP16 - # print("precision : ", precision) - build_config.set_flag(precision) - - plan = builder.build_serialized_network(network, build_config) - engine_file_path = config.engine - with open(engine_file_path, "wb") as f: - f.write(plan) - print("Build static shape engine done!") - - -def build_engine_trtapi_dynamicshape(config): +def main(config): IXRT_LOGGER = tensorrt.Logger(tensorrt.Logger.WARNING) builder = tensorrt.Builder(IXRT_LOGGER) EXPLICIT_BATCH = 1 << (int)(tensorrt.NetworkDefinitionCreationFlag.EXPLICIT_BATCH) @@ -50,24 +24,26 @@ def build_engine_trtapi_dynamicshape(config): build_config = builder.create_builder_config() profile = builder.create_optimization_profile() - profile.set_shape("input", - Dims([1, 3, 608, 608]), - Dims([32, 3, 608, 608]), - Dims([64, 3, 608, 608]), + profile.set_shape("images", + Dims([1, 3, 640, 640]), + Dims([32, 3, 640, 640]), + Dims([64, 3, 640, 640]), ) build_config.add_optimization_profile(profile) parser = tensorrt.OnnxParser(network, IXRT_LOGGER) parser.parse_from_file(config.model) - precision = tensorrt.BuilderFlag.INT8 if config.precision == "int8" else tensorrt.BuilderFlag.FP16 - # print("precision : ", precision) - build_config.set_flag(precision) + if config.precision == "int8": + build_config.set_flag(tensorrt.BuilderFlag.FP16) + build_config.set_flag(tensorrt.BuilderFlag.INT8) + else: + build_config.set_flag(tensorrt.BuilderFlag.FP16) # set dynamic num_inputs = network.num_inputs for i in range(num_inputs): input_tensor = network.get_input(i) - input_tensor.shape = Dims([-1, 3, 608, 608]) + input_tensor.shape = Dims([-1, 3, 640, 640]) plan = builder.build_serialized_network(network, build_config) engine_file_path = config.engine @@ -75,7 +51,6 @@ def build_engine_trtapi_dynamicshape(config): f.write(plan) print("Build dynamic shape engine done!") - def parse_args(): parser = argparse.ArgumentParser() parser.add_argument("--model", type=str) @@ -87,8 +62,6 @@ def parse_args(): args = parser.parse_args() return args - if __name__ == "__main__": args = parse_args() - build_engine_trtapi_staticshape(args) - # build_engine_trtapi_dynamicshape(args) + main(args) diff --git a/models/cv/object_detection/yolov12/ixrt/ci/prepare.sh b/models/cv/object_detection/yolov12/ixrt/ci/prepare.sh index 502b3bf1..935d774f 100644 --- a/models/cv/object_detection/yolov12/ixrt/ci/prepare.sh +++ b/models/cv/object_detection/yolov12/ixrt/ci/prepare.sh @@ -17,7 +17,7 @@ set -x pip3 install -r requirements.txt -git clone --depth 1 https://github.com/sunsmarterjie/yolov12.git +cp -r /root/data/3rd_party/yolov12 ./ cd yolov12 pip3 install -e . cd .. diff --git a/models/cv/object_detection/yolov12/ixrt/inference.py b/models/cv/object_detection/yolov12/ixrt/inference.py index 1ac908a7..3937087c 100644 --- a/models/cv/object_detection/yolov12/ixrt/inference.py +++ b/models/cv/object_detection/yolov12/ixrt/inference.py @@ -119,7 +119,7 @@ class IxRT_Validator(DetectionValidator): total_num = 0 - input_name = "input" + input_name = "images" host_mem = tensorrt.IHostMemory logger = tensorrt.Logger(tensorrt.Logger.ERROR) engine, context = create_engine_context(config.model_engine, logger) diff --git a/models/cv/object_detection/yolov13/ixrt/build_engine.py b/models/cv/object_detection/yolov13/ixrt/build_engine.py index e0839fc3..d486d187 100644 --- a/models/cv/object_detection/yolov13/ixrt/build_engine.py +++ b/models/cv/object_detection/yolov13/ixrt/build_engine.py @@ -12,37 +12,11 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -import os -import cv2 import argparse -import numpy as np - -import torch import tensorrt from tensorrt import Dims - -def build_engine_trtapi_staticshape(config): - IXRT_LOGGER = tensorrt.Logger(tensorrt.Logger.WARNING) - builder = tensorrt.Builder(IXRT_LOGGER) - EXPLICIT_BATCH = 1 << (int)(tensorrt.NetworkDefinitionCreationFlag.EXPLICIT_BATCH) - network = builder.create_network(EXPLICIT_BATCH) - build_config = builder.create_builder_config() - parser = tensorrt.OnnxParser(network, IXRT_LOGGER) - parser.parse_from_file(config.model) - - precision = tensorrt.BuilderFlag.INT8 if config.precision == "int8" else tensorrt.BuilderFlag.FP16 - # print("precision : ", precision) - build_config.set_flag(precision) - - plan = builder.build_serialized_network(network, build_config) - engine_file_path = config.engine - with open(engine_file_path, "wb") as f: - f.write(plan) - print("Build static shape engine done!") - - -def build_engine_trtapi_dynamicshape(config): +def main(config): IXRT_LOGGER = tensorrt.Logger(tensorrt.Logger.WARNING) builder = tensorrt.Builder(IXRT_LOGGER) EXPLICIT_BATCH = 1 << (int)(tensorrt.NetworkDefinitionCreationFlag.EXPLICIT_BATCH) @@ -50,24 +24,26 @@ def build_engine_trtapi_dynamicshape(config): build_config = builder.create_builder_config() profile = builder.create_optimization_profile() - profile.set_shape("input", - Dims([1, 3, 608, 608]), - Dims([32, 3, 608, 608]), - Dims([64, 3, 608, 608]), + profile.set_shape("images", + Dims([1, 3, 640, 640]), + Dims([32, 3, 640, 640]), + Dims([64, 3, 640, 640]), ) build_config.add_optimization_profile(profile) parser = tensorrt.OnnxParser(network, IXRT_LOGGER) parser.parse_from_file(config.model) - precision = tensorrt.BuilderFlag.INT8 if config.precision == "int8" else tensorrt.BuilderFlag.FP16 - # print("precision : ", precision) - build_config.set_flag(precision) + if config.precision == "int8": + build_config.set_flag(tensorrt.BuilderFlag.FP16) + build_config.set_flag(tensorrt.BuilderFlag.INT8) + else: + build_config.set_flag(tensorrt.BuilderFlag.FP16) # set dynamic num_inputs = network.num_inputs for i in range(num_inputs): input_tensor = network.get_input(i) - input_tensor.shape = Dims([-1, 3, 608, 608]) + input_tensor.shape = Dims([-1, 3, 640, 640]) plan = builder.build_serialized_network(network, build_config) engine_file_path = config.engine @@ -75,7 +51,6 @@ def build_engine_trtapi_dynamicshape(config): f.write(plan) print("Build dynamic shape engine done!") - def parse_args(): parser = argparse.ArgumentParser() parser.add_argument("--model", type=str) @@ -87,8 +62,6 @@ def parse_args(): args = parser.parse_args() return args - if __name__ == "__main__": args = parse_args() - build_engine_trtapi_staticshape(args) - # build_engine_trtapi_dynamicshape(args) + main(args) diff --git a/models/cv/object_detection/yolov13/ixrt/inference.py b/models/cv/object_detection/yolov13/ixrt/inference.py index 1ac908a7..3937087c 100644 --- a/models/cv/object_detection/yolov13/ixrt/inference.py +++ b/models/cv/object_detection/yolov13/ixrt/inference.py @@ -119,7 +119,7 @@ class IxRT_Validator(DetectionValidator): total_num = 0 - input_name = "input" + input_name = "images" host_mem = tensorrt.IHostMemory logger = tensorrt.Logger(tensorrt.Logger.ERROR) engine, context = create_engine_context(config.model_engine, logger) diff --git a/models/cv/object_detection/yolov6/ixrt/build_engine.py b/models/cv/object_detection/yolov6/ixrt/build_engine.py index f5e1719a..48bdbf43 100644 --- a/models/cv/object_detection/yolov6/ixrt/build_engine.py +++ b/models/cv/object_detection/yolov6/ixrt/build_engine.py @@ -12,37 +12,11 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -import os -import cv2 import argparse -import numpy as np - -import torch import tensorrt from tensorrt import Dims - -def build_engine_trtapi_staticshape(config): - IXRT_LOGGER = tensorrt.Logger(tensorrt.Logger.WARNING) - builder = tensorrt.Builder(IXRT_LOGGER) - EXPLICIT_BATCH = 1 << (int)(tensorrt.NetworkDefinitionCreationFlag.EXPLICIT_BATCH) - network = builder.create_network(EXPLICIT_BATCH) - build_config = builder.create_builder_config() - parser = tensorrt.OnnxParser(network, IXRT_LOGGER) - parser.parse_from_file(config.model) - - precision = tensorrt.BuilderFlag.INT8 if config.precision == "int8" else tensorrt.BuilderFlag.FP16 - # print("precision : ", precision) - build_config.set_flag(precision) - - plan = builder.build_serialized_network(network, build_config) - engine_file_path = config.engine - with open(engine_file_path, "wb") as f: - f.write(plan) - print("Build static shape engine done!") - - -def build_engine_trtapi_dynamicshape(config): +def main(config): IXRT_LOGGER = tensorrt.Logger(tensorrt.Logger.WARNING) builder = tensorrt.Builder(IXRT_LOGGER) EXPLICIT_BATCH = 1 << (int)(tensorrt.NetworkDefinitionCreationFlag.EXPLICIT_BATCH) @@ -50,24 +24,26 @@ def build_engine_trtapi_dynamicshape(config): build_config = builder.create_builder_config() profile = builder.create_optimization_profile() - profile.set_shape("input", - Dims([1, 3, 608, 608]), - Dims([32, 3, 608, 608]), - Dims([64, 3, 608, 608]), + profile.set_shape("images", + Dims([1, 3, 640, 640]), + Dims([32, 3, 640, 640]), + Dims([64, 3, 640, 640]), ) build_config.add_optimization_profile(profile) parser = tensorrt.OnnxParser(network, IXRT_LOGGER) parser.parse_from_file(config.model) - precision = tensorrt.BuilderFlag.INT8 if config.precision == "int8" else tensorrt.BuilderFlag.FP16 - # print("precision : ", precision) - build_config.set_flag(precision) + if config.precision == "int8": + build_config.set_flag(tensorrt.BuilderFlag.FP16) + build_config.set_flag(tensorrt.BuilderFlag.INT8) + else: + build_config.set_flag(tensorrt.BuilderFlag.FP16) # set dynamic num_inputs = network.num_inputs for i in range(num_inputs): input_tensor = network.get_input(i) - input_tensor.shape = Dims([-1, 3, 608, 608]) + input_tensor.shape = Dims([-1, 3, 640, 640]) plan = builder.build_serialized_network(network, build_config) engine_file_path = config.engine @@ -75,7 +51,6 @@ def build_engine_trtapi_dynamicshape(config): f.write(plan) print("Build dynamic shape engine done!") - def parse_args(): parser = argparse.ArgumentParser() parser.add_argument("--model", type=str) @@ -87,8 +62,6 @@ def parse_args(): args = parser.parse_args() return args - if __name__ == "__main__": args = parse_args() - build_engine_trtapi_staticshape(args) - # build_engine_trtapi_dynamicshape(args) + main(args) diff --git a/models/cv/object_detection/yolov6/ixrt/ci/prepare.sh b/models/cv/object_detection/yolov6/ixrt/ci/prepare.sh index 3aa607e3..cbeabe5e 100644 --- a/models/cv/object_detection/yolov6/ixrt/ci/prepare.sh +++ b/models/cv/object_detection/yolov6/ixrt/ci/prepare.sh @@ -16,15 +16,6 @@ set -x -ID=$(grep -oP '(?<=^ID=).+' /etc/os-release | tr -d '"') -if [[ ${ID} == "ubuntu" ]]; then - apt install -y libgl1-mesa-glx -elif [[ ${ID} == "centos" ]]; then - yum install -y mesa-libGL -else - echo "Not Support Os" -fi - pip3 install -r requirements.txt mkdir -p data/ cp -r /root/data/3rd_party/YOLOv6 ./ diff --git a/models/cv/object_detection/yolov6/ixrt/deploy.py b/models/cv/object_detection/yolov6/ixrt/deploy.py deleted file mode 100644 index f73d14b2..00000000 --- a/models/cv/object_detection/yolov6/ixrt/deploy.py +++ /dev/null @@ -1,99 +0,0 @@ -# !/usr/bin/env python -# -*- coding: utf-8 -*- -# Copyright (c) 2024, Shanghai Iluvatar CoreX Semiconductor Co., Ltd. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -import argparse -import copy - -from typing import Union, Callable, List - -from tensorrt.deploy.api import * -from tensorrt.deploy.backend.onnx.converter import default_converter -from tensorrt.deploy.backend.torch.executor.operators._operators import to_py_type -from tensorrt.deploy.ir.operator_attr import BaseOperatorAttr, EmptyAttr -from tensorrt.deploy.ir.operator_type import OperatorType as OP -from tensorrt.deploy.ir import operator_attr as attr, Operator, generate_operator_name -from tensorrt.deploy.fusion import BasePass, PatternGraph, build_sequence_graph, GraphMatcher, PassSequence -from tensorrt.deploy.ir import Graph -from tensorrt.deploy.quantizer.quant_operator.base import quant_single_input_operator -from tensorrt.deploy.backend.onnx.converter import convert_onnx_operator -from tensorrt.deploy.api import GraphTransform, create_source, create_target - -class FuseSiLUPass(BasePass): - def process(self, graph: Graph) -> Graph: - pattern = build_sequence_graph([OP.SIGMOID, OP.MUL]) - - matcher = GraphMatcher(pattern, strict=False) - self.transform = GraphTransform(graph) - matcher.findall(graph, self.fuse_mish) - return graph - - def fuse_mish(self, graph: Graph, pattern_graph: PatternGraph): - sigmoid = pattern_graph.nodes[0].operator - mul = pattern_graph.nodes[-1].operator - - if not self.can_fused(graph, pattern_graph): - return - - self.transform.delete_operators_between_op_op(sigmoid, mul) - - silu_op = Operator( - name=generate_operator_name(graph, pattern="SiLU_{idx}"), - op_type=OP.SILU, - inputs=copy.copy(sigmoid.inputs), - outputs=copy.copy(mul.outputs), - ) - silu_op.is_quant_operator = sigmoid.is_quant_operator and mul.is_quant_operator - graph.add_operator(silu_op) - - def can_fused(self, graph: Graph, pattern_graph: PatternGraph): - sigmoid = pattern_graph.nodes[0].operator - mul = pattern_graph.nodes[-1].operator - - # 如果 sigmoid 的结果 被多个 OP 使用,则不能融合 - if len(self.transform.get_next_operators(sigmoid)) > 1: - return False - - # 检查 mul 的输入是不是和 sigmoid 是同源的 - softplus_prev_op = graph.get_previous_operators(sigmoid) - if len(softplus_prev_op) != 1: - return False - - mul_prev_op = graph.get_previous_operators(mul) - if len(mul_prev_op) != 2: - return False - - for op in mul_prev_op: - if op is softplus_prev_op[0]: - return True - - return False - - -def parse_args(): - parser = argparse.ArgumentParser() - parser.add_argument("--src", type=str) - parser.add_argument("--dst", type=str) - args = parser.parse_args() - return args - - -if __name__ == "__main__": - - args = parse_args() - graph = create_source(args.src)() - graph = FuseSiLUPass().process(graph) - create_target(saved_path=args.dst).export(graph) - print("Surged onnx lies on", args.dst) diff --git a/models/cv/object_detection/yolov6/ixrt/inference.py b/models/cv/object_detection/yolov6/ixrt/inference.py index 1a4f151f..984dd851 100644 --- a/models/cv/object_detection/yolov6/ixrt/inference.py +++ b/models/cv/object_detection/yolov6/ixrt/inference.py @@ -64,7 +64,7 @@ class EvalerIXRT(Evaler): dataloader = init_data(None,'val') pred_results = [] - input_name = "input" + input_name = "images" host_mem = tensorrt.IHostMemory logger = tensorrt.Logger(tensorrt.Logger.ERROR) engine, context = create_engine_context(args.model_engine, logger) diff --git a/models/cv/object_detection/yolov6/ixrt/scripts/infer_yolov6_fp16_performance.sh b/models/cv/object_detection/yolov6/ixrt/scripts/infer_yolov6_fp16_performance.sh index 5de30b1c..d5eb5a2c 100644 --- a/models/cv/object_detection/yolov6/ixrt/scripts/infer_yolov6_fp16_performance.sh +++ b/models/cv/object_detection/yolov6/ixrt/scripts/infer_yolov6_fp16_performance.sh @@ -40,18 +40,6 @@ echo Onnx Path : ${ORIGINE_MODEL} BATCH_SIZE=32 CURRENT_MODEL=${CHECKPOINTS_DIR}/yolov6s.onnx -# fuse silu -# FINAL_MODEL=${CHECKPOINTS_DIR}/yolov6_bs${BATCH_SIZE}_fused.onnx -# if [ -f $FINAL_MODEL ];then -# echo " "Fuse silu Skip, $FINAL_MODEL has been existed -# else -# python3 ${RUN_DIR}/deploy.py \ -# --src ${CURRENT_MODEL} \ -# --dst ${FINAL_MODEL} -# echo " "Generate ${FINAL_MODEL} -# fi -# CURRENT_MODEL=${FINAL_MODEL} - # Build Engine echo Build Engine ENGINE_FILE=${CHECKPOINTS_DIR}/yolov6s_fp16.engine diff --git a/models/cv/object_detection/yolov8/ixrt/README.md b/models/cv/object_detection/yolov8/ixrt/README.md index 069e4716..6301827f 100644 --- a/models/cv/object_detection/yolov8/ixrt/README.md +++ b/models/cv/object_detection/yolov8/ixrt/README.md @@ -48,17 +48,7 @@ coco ### Install Dependencies -Contact the Iluvatar administrator to get the missing packages: - -- mmcv-2.1.0+corex.4.3.0-cp310-cp310-linux_x86_64.whl - ```bash -# Install libGL -## CentOS -yum install -y mesa-libGL -## Ubuntu -apt install -y libgl1-mesa-glx - pip3 install -r requirements.txt ``` diff --git a/models/cv/object_detection/yolov8/ixrt/build_engine.py b/models/cv/object_detection/yolov8/ixrt/build_engine.py index f5e1719a..48bdbf43 100644 --- a/models/cv/object_detection/yolov8/ixrt/build_engine.py +++ b/models/cv/object_detection/yolov8/ixrt/build_engine.py @@ -12,37 +12,11 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -import os -import cv2 import argparse -import numpy as np - -import torch import tensorrt from tensorrt import Dims - -def build_engine_trtapi_staticshape(config): - IXRT_LOGGER = tensorrt.Logger(tensorrt.Logger.WARNING) - builder = tensorrt.Builder(IXRT_LOGGER) - EXPLICIT_BATCH = 1 << (int)(tensorrt.NetworkDefinitionCreationFlag.EXPLICIT_BATCH) - network = builder.create_network(EXPLICIT_BATCH) - build_config = builder.create_builder_config() - parser = tensorrt.OnnxParser(network, IXRT_LOGGER) - parser.parse_from_file(config.model) - - precision = tensorrt.BuilderFlag.INT8 if config.precision == "int8" else tensorrt.BuilderFlag.FP16 - # print("precision : ", precision) - build_config.set_flag(precision) - - plan = builder.build_serialized_network(network, build_config) - engine_file_path = config.engine - with open(engine_file_path, "wb") as f: - f.write(plan) - print("Build static shape engine done!") - - -def build_engine_trtapi_dynamicshape(config): +def main(config): IXRT_LOGGER = tensorrt.Logger(tensorrt.Logger.WARNING) builder = tensorrt.Builder(IXRT_LOGGER) EXPLICIT_BATCH = 1 << (int)(tensorrt.NetworkDefinitionCreationFlag.EXPLICIT_BATCH) @@ -50,24 +24,26 @@ def build_engine_trtapi_dynamicshape(config): build_config = builder.create_builder_config() profile = builder.create_optimization_profile() - profile.set_shape("input", - Dims([1, 3, 608, 608]), - Dims([32, 3, 608, 608]), - Dims([64, 3, 608, 608]), + profile.set_shape("images", + Dims([1, 3, 640, 640]), + Dims([32, 3, 640, 640]), + Dims([64, 3, 640, 640]), ) build_config.add_optimization_profile(profile) parser = tensorrt.OnnxParser(network, IXRT_LOGGER) parser.parse_from_file(config.model) - precision = tensorrt.BuilderFlag.INT8 if config.precision == "int8" else tensorrt.BuilderFlag.FP16 - # print("precision : ", precision) - build_config.set_flag(precision) + if config.precision == "int8": + build_config.set_flag(tensorrt.BuilderFlag.FP16) + build_config.set_flag(tensorrt.BuilderFlag.INT8) + else: + build_config.set_flag(tensorrt.BuilderFlag.FP16) # set dynamic num_inputs = network.num_inputs for i in range(num_inputs): input_tensor = network.get_input(i) - input_tensor.shape = Dims([-1, 3, 608, 608]) + input_tensor.shape = Dims([-1, 3, 640, 640]) plan = builder.build_serialized_network(network, build_config) engine_file_path = config.engine @@ -75,7 +51,6 @@ def build_engine_trtapi_dynamicshape(config): f.write(plan) print("Build dynamic shape engine done!") - def parse_args(): parser = argparse.ArgumentParser() parser.add_argument("--model", type=str) @@ -87,8 +62,6 @@ def parse_args(): args = parser.parse_args() return args - if __name__ == "__main__": args = parse_args() - build_engine_trtapi_staticshape(args) - # build_engine_trtapi_dynamicshape(args) + main(args) diff --git a/models/cv/object_detection/yolov8/ixrt/ci/prepare.sh b/models/cv/object_detection/yolov8/ixrt/ci/prepare.sh index 58d524a6..63103ee9 100644 --- a/models/cv/object_detection/yolov8/ixrt/ci/prepare.sh +++ b/models/cv/object_detection/yolov8/ixrt/ci/prepare.sh @@ -16,15 +16,6 @@ set -x -ID=$(grep -oP '(?<=^ID=).+' /etc/os-release | tr -d '"') -if [[ ${ID} == "ubuntu" ]]; then - apt install -y libgl1-mesa-glx -elif [[ ${ID} == "centos" ]]; then - yum install -y mesa-libGL -else - echo "Not Support Os" -fi - pip install -r requirements.txt mkdir -p checkpoints ln -s /root/data/checkpoints/yolov8.pt yolov8.pt diff --git a/models/cv/object_detection/yolov8/ixrt/inference.py b/models/cv/object_detection/yolov8/ixrt/inference.py index 9bd4674e..81725723 100644 --- a/models/cv/object_detection/yolov8/ixrt/inference.py +++ b/models/cv/object_detection/yolov8/ixrt/inference.py @@ -119,7 +119,7 @@ class IxRT_Validator(DetectionValidator): total_num = 0 - input_name = "input" + input_name = "images" host_mem = tensorrt.IHostMemory logger = tensorrt.Logger(tensorrt.Logger.ERROR) engine, context = create_engine_context(config.model_engine, logger) diff --git a/models/cv/object_detection/yolov9/ixrt/README.md b/models/cv/object_detection/yolov9/ixrt/README.md index dff4c589..c0b1f476 100644 --- a/models/cv/object_detection/yolov9/ixrt/README.md +++ b/models/cv/object_detection/yolov9/ixrt/README.md @@ -48,17 +48,7 @@ coco ### Install Dependencies -Contact the Iluvatar administrator to get the missing packages: - -- mmcv-2.1.0+corex.4.3.0-cp310-cp310-linux_x86_64.whl - ```bash -# Install libGL -## CentOS -yum install -y mesa-libGL -## Ubuntu -apt install -y libgl1-mesa-glx - pip3 install -r requirements.txt ``` diff --git a/models/cv/object_detection/yolov9/ixrt/build_engine.py b/models/cv/object_detection/yolov9/ixrt/build_engine.py index e0839fc3..d486d187 100644 --- a/models/cv/object_detection/yolov9/ixrt/build_engine.py +++ b/models/cv/object_detection/yolov9/ixrt/build_engine.py @@ -12,37 +12,11 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -import os -import cv2 import argparse -import numpy as np - -import torch import tensorrt from tensorrt import Dims - -def build_engine_trtapi_staticshape(config): - IXRT_LOGGER = tensorrt.Logger(tensorrt.Logger.WARNING) - builder = tensorrt.Builder(IXRT_LOGGER) - EXPLICIT_BATCH = 1 << (int)(tensorrt.NetworkDefinitionCreationFlag.EXPLICIT_BATCH) - network = builder.create_network(EXPLICIT_BATCH) - build_config = builder.create_builder_config() - parser = tensorrt.OnnxParser(network, IXRT_LOGGER) - parser.parse_from_file(config.model) - - precision = tensorrt.BuilderFlag.INT8 if config.precision == "int8" else tensorrt.BuilderFlag.FP16 - # print("precision : ", precision) - build_config.set_flag(precision) - - plan = builder.build_serialized_network(network, build_config) - engine_file_path = config.engine - with open(engine_file_path, "wb") as f: - f.write(plan) - print("Build static shape engine done!") - - -def build_engine_trtapi_dynamicshape(config): +def main(config): IXRT_LOGGER = tensorrt.Logger(tensorrt.Logger.WARNING) builder = tensorrt.Builder(IXRT_LOGGER) EXPLICIT_BATCH = 1 << (int)(tensorrt.NetworkDefinitionCreationFlag.EXPLICIT_BATCH) @@ -50,24 +24,26 @@ def build_engine_trtapi_dynamicshape(config): build_config = builder.create_builder_config() profile = builder.create_optimization_profile() - profile.set_shape("input", - Dims([1, 3, 608, 608]), - Dims([32, 3, 608, 608]), - Dims([64, 3, 608, 608]), + profile.set_shape("images", + Dims([1, 3, 640, 640]), + Dims([32, 3, 640, 640]), + Dims([64, 3, 640, 640]), ) build_config.add_optimization_profile(profile) parser = tensorrt.OnnxParser(network, IXRT_LOGGER) parser.parse_from_file(config.model) - precision = tensorrt.BuilderFlag.INT8 if config.precision == "int8" else tensorrt.BuilderFlag.FP16 - # print("precision : ", precision) - build_config.set_flag(precision) + if config.precision == "int8": + build_config.set_flag(tensorrt.BuilderFlag.FP16) + build_config.set_flag(tensorrt.BuilderFlag.INT8) + else: + build_config.set_flag(tensorrt.BuilderFlag.FP16) # set dynamic num_inputs = network.num_inputs for i in range(num_inputs): input_tensor = network.get_input(i) - input_tensor.shape = Dims([-1, 3, 608, 608]) + input_tensor.shape = Dims([-1, 3, 640, 640]) plan = builder.build_serialized_network(network, build_config) engine_file_path = config.engine @@ -75,7 +51,6 @@ def build_engine_trtapi_dynamicshape(config): f.write(plan) print("Build dynamic shape engine done!") - def parse_args(): parser = argparse.ArgumentParser() parser.add_argument("--model", type=str) @@ -87,8 +62,6 @@ def parse_args(): args = parser.parse_args() return args - if __name__ == "__main__": args = parse_args() - build_engine_trtapi_staticshape(args) - # build_engine_trtapi_dynamicshape(args) + main(args) diff --git a/models/cv/object_detection/yolov9/ixrt/ci/prepare.sh b/models/cv/object_detection/yolov9/ixrt/ci/prepare.sh index 4a36a555..6f77f115 100644 --- a/models/cv/object_detection/yolov9/ixrt/ci/prepare.sh +++ b/models/cv/object_detection/yolov9/ixrt/ci/prepare.sh @@ -16,15 +16,6 @@ set -x -ID=$(grep -oP '(?<=^ID=).+' /etc/os-release | tr -d '"') -if [[ ${ID} == "ubuntu" ]]; then - apt install -y libgl1-mesa-glx -elif [[ ${ID} == "centos" ]]; then - yum install -y mesa-libGL -else - echo "Not Support Os" -fi - pip3 install -r requirements.txt mkdir -p checkpoints/ diff --git a/models/cv/object_detection/yolov9/ixrt/inference.py b/models/cv/object_detection/yolov9/ixrt/inference.py index 1ac908a7..3937087c 100644 --- a/models/cv/object_detection/yolov9/ixrt/inference.py +++ b/models/cv/object_detection/yolov9/ixrt/inference.py @@ -119,7 +119,7 @@ class IxRT_Validator(DetectionValidator): total_num = 0 - input_name = "input" + input_name = "images" host_mem = tensorrt.IHostMemory logger = tensorrt.Logger(tensorrt.Logger.ERROR) engine, context = create_engine_context(config.model_engine, logger) diff --git a/models/cv/object_detection/yolox/igie/ci/prepare.sh b/models/cv/object_detection/yolox/igie/ci/prepare.sh index f21f8760..2031bb8b 100644 --- a/models/cv/object_detection/yolox/igie/ci/prepare.sh +++ b/models/cv/object_detection/yolox/igie/ci/prepare.sh @@ -31,7 +31,7 @@ pip3 install -r requirements.txt source /opt/rh/devtoolset-7/enable # install yolox -git clone --depth 1 https://github.com/Megvii-BaseDetection/YOLOX.git +unzip -q /mnt/deepspark/data/repos/yolox-f00a798c8bf59f43ab557a2f3d566afa831c8887.zip -d ./ cd YOLOX python3 setup.py develop -- Gitee