From 2002d8b5a2d43c040da4527ada2aad3c75acb577 Mon Sep 17 00:00:00 2001 From: YoungPeng Date: Fri, 11 Jul 2025 15:16:58 +0800 Subject: [PATCH 01/15] Add: Efficientnet_b6 inference script. --- .../efficientnet_b6/igie/README.md | 52 +++++ .../efficientnet_b6/igie/build_engine.py | 73 +++++++ .../efficientnet_b6/igie/ci/prepare.sh | 20 ++ .../efficientnet_b6/igie/export.py | 61 ++++++ .../efficientnet_b6/igie/inference.py | 186 ++++++++++++++++++ .../efficientnet_b6/igie/requirements.txt | 2 + .../infer_efficientnet_b6_fp16_accuracy.sh | 35 ++++ .../infer_efficientnet_b6_fp16_performance.sh | 36 ++++ 8 files changed, 465 insertions(+) create mode 100644 models/cv/classification/efficientnet_b6/igie/README.md create mode 100644 models/cv/classification/efficientnet_b6/igie/build_engine.py create mode 100644 models/cv/classification/efficientnet_b6/igie/ci/prepare.sh create mode 100644 models/cv/classification/efficientnet_b6/igie/export.py create mode 100644 models/cv/classification/efficientnet_b6/igie/inference.py create mode 100644 models/cv/classification/efficientnet_b6/igie/requirements.txt create mode 100644 models/cv/classification/efficientnet_b6/igie/scripts/infer_efficientnet_b6_fp16_accuracy.sh create mode 100644 models/cv/classification/efficientnet_b6/igie/scripts/infer_efficientnet_b6_fp16_performance.sh diff --git a/models/cv/classification/efficientnet_b6/igie/README.md b/models/cv/classification/efficientnet_b6/igie/README.md new file mode 100644 index 00000000..41a38bf8 --- /dev/null +++ b/models/cv/classification/efficientnet_b6/igie/README.md @@ -0,0 +1,52 @@ +# EfficientNet B6 (IGIE) + +## Model Description + +EfficientNet B6 is a high-performance convolutional neural network model developed by Google, utilizing Compound Scaling to balance the scaling of depth, width, and resolution. It incorporates Inverted Residual Blocks, Squeeze-and-Excitation (SE) modules, and the Swish activation function. EfficientNet-B6 excels in tasks like image classification and object detection. While it requires significant computational resources, its precision and efficiency make it an ideal choice for complex vision tasks. + +## Supported Environments + +| GPU | [IXUCA SDK](https://gitee.com/deep-spark/deepspark#%E5%A4%A9%E6%95%B0%E6%99%BA%E7%AE%97%E8%BD%AF%E4%BB%B6%E6%A0%88-ixuca) | Release | +|--------|-----------|---------| +| MR-V100| 4.2.0 | 25.06 | + +## Model Preparation + +### Prepare Resources + +Pretrained model: + +Dataset: to download the validation dataset. + +### Install Dependencies + +```bash +pip3 install -r requirements.txt +``` + +### Model Conversion + +```bash +python3 export.py --weight efficientnet_b6_lukemelas-24a108a5.pth --output efficientnet_b6.onnx +``` + +## Model Inference + +```bash +export DATASETS_DIR=/Path/to/imagenet_val/ +``` + +### FP16 + +```bash +# Accuracy +bash scripts/infer_efficientnet_b6_fp16_accuracy.sh +# Performance +bash scripts/infer_efficientnet_b6_fp16_performance.sh +``` + +## Model Results + +| Model | BatchSize | Precision | FPS | Top-1(%) | Top-5(%) | +| --------------- | --------- | --------- | -------- | -------- | -------- | +| Efficientnet_b6 | 32 | FP16 | 523.225 | 74.388 | 91.835 | diff --git a/models/cv/classification/efficientnet_b6/igie/build_engine.py b/models/cv/classification/efficientnet_b6/igie/build_engine.py new file mode 100644 index 00000000..54aa8847 --- /dev/null +++ b/models/cv/classification/efficientnet_b6/igie/build_engine.py @@ -0,0 +1,73 @@ +# Copyright (c) 2025, 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 tvm +import argparse +from tvm import relay +from tvm.relay.import_model import import_model_to_igie + +def parse_args(): + parser = argparse.ArgumentParser() + + parser.add_argument("--model_path", + type=str, + required=True, + help="original model path.") + + parser.add_argument("--engine_path", + type=str, + required=True, + help="igie export engine path.") + + parser.add_argument("--input", + type=str, + required=True, + help=""" + input info of the model, format should be: + input_name:input_shape + eg: --input input:1,3,224,224. + """) + + parser.add_argument("--precision", + type=str, + choices=["fp32", "fp16", "int8"], + required=True, + help="model inference precision.") + + args = parser.parse_args() + + return args + +def main(): + args = parse_args() + + # get input valueinfo + input_name, input_shape = args.input.split(":") + shape = tuple([int(s) for s in input_shape.split(",")]) + input_dict = {input_name: shape} + + target = tvm.target.iluvatar(model="MR", options="-libs=cudnn,cublas,ixinfer") + + mod, params = import_model_to_igie(args.model_path, input_dict, backend="igie") + + # build engine + lib = tvm.relay.build(mod, target=target, params=params, precision=args.precision) + + # export engine + lib.export_library(args.engine_path) + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/models/cv/classification/efficientnet_b6/igie/ci/prepare.sh b/models/cv/classification/efficientnet_b6/igie/ci/prepare.sh new file mode 100644 index 00000000..2788c927 --- /dev/null +++ b/models/cv/classification/efficientnet_b6/igie/ci/prepare.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# Copyright (c) 2025, 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. + +set -x + +pip3 install -r requirements.txt +python3 export.py --weight efficientnet_b6_lukemelas-24a108a5.pth --output efficientnet_b6.onnx diff --git a/models/cv/classification/efficientnet_b6/igie/export.py b/models/cv/classification/efficientnet_b6/igie/export.py new file mode 100644 index 00000000..1b5a64e8 --- /dev/null +++ b/models/cv/classification/efficientnet_b6/igie/export.py @@ -0,0 +1,61 @@ +# Copyright (c) 2025, 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 torch +import torchvision +import argparse + +def parse_args(): + parser = argparse.ArgumentParser() + + parser.add_argument("--weight", + type=str, + required=True, + help="pytorch model weight.") + + parser.add_argument("--output", + type=str, + required=True, + help="export onnx model path.") + + args = parser.parse_args() + return args + +def main(): + args = parse_args() + + model = torchvision.models.efficientnet_b6() + model.load_state_dict(torch.load(args.weight)) + model.eval() + + input_names = ['input'] + output_names = ['output'] + dynamic_axes = {'input': {0: '-1'}, 'output': {0: '-1'}} + dummy_input = torch.randn(1, 3, 224, 224) + + torch.onnx.export( + model, + dummy_input, + args.output, + input_names = input_names, + dynamic_axes = dynamic_axes, + output_names = output_names, + opset_version=13 + ) + + print("Export onnx model successfully! ") + +if __name__ == "__main__": + main() diff --git a/models/cv/classification/efficientnet_b6/igie/inference.py b/models/cv/classification/efficientnet_b6/igie/inference.py new file mode 100644 index 00000000..0563f72e --- /dev/null +++ b/models/cv/classification/efficientnet_b6/igie/inference.py @@ -0,0 +1,186 @@ +# Copyright (c) 2025, 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 sys +import argparse +import tvm +import torch +import torchvision +import numpy as np +from tvm import relay +from tqdm import tqdm +from torchvision import transforms +from torchvision.transforms.functional import InterpolationMode + +def parse_args(): + parser = argparse.ArgumentParser() + + parser.add_argument("--engine", + type=str, + required=True, + help="igie engine path.") + + parser.add_argument("--batchsize", + type=int, + required=True, + help="inference batch size.") + + parser.add_argument("--datasets", + type=str, + required=True, + help="datasets path.") + + parser.add_argument("--input_name", + type=str, + required=True, + help="input name of the model.") + + parser.add_argument("--warmup", + type=int, + default=3, + help="number of warmup before test.") + + parser.add_argument("--num_workers", + type=int, + default=16, + help="number of workers used in pytorch dataloader.") + + parser.add_argument("--acc_target", + type=float, + default=None, + help="Model inference Accuracy target.") + + parser.add_argument("--fps_target", + type=float, + default=None, + help="Model inference FPS target.") + + parser.add_argument("--perf_only", + type=bool, + default=False, + help="Run performance test only") + + args = parser.parse_args() + + return args + +def get_dataloader(data_path, batch_size, num_workers): + dataset = torchvision.datasets.ImageFolder( + data_path, + transforms.Compose( + [ + transforms.Resize(256, interpolation=InterpolationMode.BILINEAR), + transforms.CenterCrop(224), + transforms.PILToTensor(), + transforms.ConvertImageDtype(torch.float), + transforms.Normalize( + mean=(0.485, 0.456, 0.406), + std=(0.229, 0.224, 0.225) + ) + ] + ) + ) + + dataloader = torch.utils.data.DataLoader(dataset, batch_size, num_workers=num_workers) + + return dataloader + +def get_topk_accuracy(pred, label): + if isinstance(pred, np.ndarray): + pred = torch.from_numpy(pred) + + if isinstance(label, np.ndarray): + label = torch.from_numpy(label) + + top1_acc = 0 + top5_acc = 0 + for idx in range(len(label)): + label_value = label[idx] + if label_value == torch.topk(pred[idx].float(), 1).indices.data: + top1_acc += 1 + top5_acc += 1 + + elif label_value in torch.topk(pred[idx].float(), 5).indices.data: + top5_acc += 1 + + return top1_acc, top5_acc + +def main(): + args = parse_args() + + batch_size = args.batchsize + + # create iluvatar target & device + target = tvm.target.iluvatar(model="MR", options="-libs=cudnn,cublas,ixinfer") + device = tvm.device(target.kind.name, 0) + + # load engine + lib = tvm.runtime.load_module(args.engine) + + # create runtime from engine + module = tvm.contrib.graph_executor.GraphModule(lib["default"](device)) + + # just run perf test + if args.perf_only: + ftimer = module.module.time_evaluator("run", device, number=100, repeat=1) + prof_res = np.array(ftimer().results) * 1000 + fps = batch_size * 1000 / np.mean(prof_res) + print(f"\n* Mean inference time: {np.mean(prof_res):.3f} ms, Mean fps: {fps:.3f}") + else: + # warm up + for _ in range(args.warmup): + module.run() + + # get dataloader + dataloader = get_dataloader(args.datasets, batch_size, args.num_workers) + + top1_acc = 0 + top5_acc = 0 + total_num = 0 + + for image, label in tqdm(dataloader): + + # pad the last batch + pad_batch = len(image) != batch_size + + if pad_batch: + origin_size = len(image) + image = np.resize(image, (batch_size, *image.shape[1:])) + + module.set_input(args.input_name, tvm.nd.array(image, device)) + + # run inference + module.run() + + pred = module.get_output(0).asnumpy() + + if pad_batch: + pred = pred[:origin_size] + + # get batch accuracy + batch_top1_acc, batch_top5_acc = get_topk_accuracy(pred, label) + + top1_acc += batch_top1_acc + top5_acc += batch_top5_acc + total_num += batch_size + + result_stat = {} + result_stat["acc@1"] = round(top1_acc / total_num * 100.0, 3) + result_stat["acc@5"] = round(top5_acc / total_num * 100.0, 3) + + print(f"\n* Top1 acc: {result_stat['acc@1']} %, Top5 acc: {result_stat['acc@5']} %") + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/models/cv/classification/efficientnet_b6/igie/requirements.txt b/models/cv/classification/efficientnet_b6/igie/requirements.txt new file mode 100644 index 00000000..9e811126 --- /dev/null +++ b/models/cv/classification/efficientnet_b6/igie/requirements.txt @@ -0,0 +1,2 @@ +onnx +tqdm diff --git a/models/cv/classification/efficientnet_b6/igie/scripts/infer_efficientnet_b6_fp16_accuracy.sh b/models/cv/classification/efficientnet_b6/igie/scripts/infer_efficientnet_b6_fp16_accuracy.sh new file mode 100644 index 00000000..18c5a89c --- /dev/null +++ b/models/cv/classification/efficientnet_b6/igie/scripts/infer_efficientnet_b6_fp16_accuracy.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Copyright (c) 2025, 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. + +batchsize=32 +model_path="efficientnet_b6.onnx" +datasets_path=${DATASETS_DIR} + +# build engine +python3 build_engine.py \ + --model_path ${model_path} \ + --input input:${batchsize},3,224,224 \ + --precision fp16 \ + --engine_path efficientnet_b6_bs_${batchsize}_fp16.so + + +# inference +python3 inference.py \ + --engine efficientnet_b6_bs_${batchsize}_fp16.so \ + --batchsize ${batchsize} \ + --input_name input \ + --datasets ${datasets_path} \ No newline at end of file diff --git a/models/cv/classification/efficientnet_b6/igie/scripts/infer_efficientnet_b6_fp16_performance.sh b/models/cv/classification/efficientnet_b6/igie/scripts/infer_efficientnet_b6_fp16_performance.sh new file mode 100644 index 00000000..f52281f0 --- /dev/null +++ b/models/cv/classification/efficientnet_b6/igie/scripts/infer_efficientnet_b6_fp16_performance.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# Copyright (c) 2025, 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. + +batchsize=32 +model_path="efficientnet_b6.onnx" +datasets_path=${DATASETS_DIR} + +# build engine +python3 build_engine.py \ + --model_path ${model_path} \ + --input input:${batchsize},3,224,224 \ + --precision fp16 \ + --engine_path efficientnet_b6_bs_${batchsize}_fp16.so + + +# inference +python3 inference.py \ + --engine efficientnet_b6_bs_${batchsize}_fp16.so \ + --batchsize ${batchsize} \ + --input_name input \ + --datasets ${datasets_path} \ + --perf_only True \ No newline at end of file -- Gitee From c8a69209eeb449d1fc11184e96ef564d9d5734f0 Mon Sep 17 00:00:00 2001 From: YoungPeng Date: Fri, 11 Jul 2025 16:15:24 +0800 Subject: [PATCH 02/15] Update: Refactor efficientnet_b6 script use igie_common. --- .../efficientnet_b6/igie/README.md | 5 +- .../efficientnet_b6/igie/build_engine.py | 73 ------- .../efficientnet_b6/igie/ci/prepare.sh | 4 +- .../efficientnet_b6/igie/export.py | 61 ------ .../efficientnet_b6/igie/inference.py | 186 ------------------ .../infer_efficientnet_b6_fp16_accuracy.sh | 4 +- .../infer_efficientnet_b6_fp16_performance.sh | 4 +- 7 files changed, 9 insertions(+), 328 deletions(-) delete mode 100644 models/cv/classification/efficientnet_b6/igie/build_engine.py delete mode 100644 models/cv/classification/efficientnet_b6/igie/export.py delete mode 100644 models/cv/classification/efficientnet_b6/igie/inference.py diff --git a/models/cv/classification/efficientnet_b6/igie/README.md b/models/cv/classification/efficientnet_b6/igie/README.md index 41a38bf8..5d4a0045 100644 --- a/models/cv/classification/efficientnet_b6/igie/README.md +++ b/models/cv/classification/efficientnet_b6/igie/README.md @@ -21,19 +21,20 @@ Dataset: to download the validation dat ### Install Dependencies ```bash -pip3 install -r requirements.txt +pip3 install -r ../../igie_common/requirements.txt ``` ### Model Conversion ```bash -python3 export.py --weight efficientnet_b6_lukemelas-24a108a5.pth --output efficientnet_b6.onnx +python3 ../../igie_common/export.py --model-name efficientnet_b6 --weight efficientnet_b6_lukemelas-24a108a5.pth --output efficientnet_b6.onnx ``` ## Model Inference ```bash export DATASETS_DIR=/Path/to/imagenet_val/ +export RUN_DIR=../../igie_common/ ``` ### FP16 diff --git a/models/cv/classification/efficientnet_b6/igie/build_engine.py b/models/cv/classification/efficientnet_b6/igie/build_engine.py deleted file mode 100644 index 54aa8847..00000000 --- a/models/cv/classification/efficientnet_b6/igie/build_engine.py +++ /dev/null @@ -1,73 +0,0 @@ -# Copyright (c) 2025, 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 tvm -import argparse -from tvm import relay -from tvm.relay.import_model import import_model_to_igie - -def parse_args(): - parser = argparse.ArgumentParser() - - parser.add_argument("--model_path", - type=str, - required=True, - help="original model path.") - - parser.add_argument("--engine_path", - type=str, - required=True, - help="igie export engine path.") - - parser.add_argument("--input", - type=str, - required=True, - help=""" - input info of the model, format should be: - input_name:input_shape - eg: --input input:1,3,224,224. - """) - - parser.add_argument("--precision", - type=str, - choices=["fp32", "fp16", "int8"], - required=True, - help="model inference precision.") - - args = parser.parse_args() - - return args - -def main(): - args = parse_args() - - # get input valueinfo - input_name, input_shape = args.input.split(":") - shape = tuple([int(s) for s in input_shape.split(",")]) - input_dict = {input_name: shape} - - target = tvm.target.iluvatar(model="MR", options="-libs=cudnn,cublas,ixinfer") - - mod, params = import_model_to_igie(args.model_path, input_dict, backend="igie") - - # build engine - lib = tvm.relay.build(mod, target=target, params=params, precision=args.precision) - - # export engine - lib.export_library(args.engine_path) - - -if __name__ == "__main__": - main() \ No newline at end of file diff --git a/models/cv/classification/efficientnet_b6/igie/ci/prepare.sh b/models/cv/classification/efficientnet_b6/igie/ci/prepare.sh index 2788c927..475490fb 100644 --- a/models/cv/classification/efficientnet_b6/igie/ci/prepare.sh +++ b/models/cv/classification/efficientnet_b6/igie/ci/prepare.sh @@ -16,5 +16,5 @@ set -x -pip3 install -r requirements.txt -python3 export.py --weight efficientnet_b6_lukemelas-24a108a5.pth --output efficientnet_b6.onnx +pip3 install -r ../../igie_common/requirements.txt +python3 ../../igie_common/export.py --model-name efficientnet_b6 --weight efficientnet_b6_lukemelas-24a108a5.pth --output efficientnet_b6.onnx diff --git a/models/cv/classification/efficientnet_b6/igie/export.py b/models/cv/classification/efficientnet_b6/igie/export.py deleted file mode 100644 index 1b5a64e8..00000000 --- a/models/cv/classification/efficientnet_b6/igie/export.py +++ /dev/null @@ -1,61 +0,0 @@ -# Copyright (c) 2025, 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 torch -import torchvision -import argparse - -def parse_args(): - parser = argparse.ArgumentParser() - - parser.add_argument("--weight", - type=str, - required=True, - help="pytorch model weight.") - - parser.add_argument("--output", - type=str, - required=True, - help="export onnx model path.") - - args = parser.parse_args() - return args - -def main(): - args = parse_args() - - model = torchvision.models.efficientnet_b6() - model.load_state_dict(torch.load(args.weight)) - model.eval() - - input_names = ['input'] - output_names = ['output'] - dynamic_axes = {'input': {0: '-1'}, 'output': {0: '-1'}} - dummy_input = torch.randn(1, 3, 224, 224) - - torch.onnx.export( - model, - dummy_input, - args.output, - input_names = input_names, - dynamic_axes = dynamic_axes, - output_names = output_names, - opset_version=13 - ) - - print("Export onnx model successfully! ") - -if __name__ == "__main__": - main() diff --git a/models/cv/classification/efficientnet_b6/igie/inference.py b/models/cv/classification/efficientnet_b6/igie/inference.py deleted file mode 100644 index 0563f72e..00000000 --- a/models/cv/classification/efficientnet_b6/igie/inference.py +++ /dev/null @@ -1,186 +0,0 @@ -# Copyright (c) 2025, 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 sys -import argparse -import tvm -import torch -import torchvision -import numpy as np -from tvm import relay -from tqdm import tqdm -from torchvision import transforms -from torchvision.transforms.functional import InterpolationMode - -def parse_args(): - parser = argparse.ArgumentParser() - - parser.add_argument("--engine", - type=str, - required=True, - help="igie engine path.") - - parser.add_argument("--batchsize", - type=int, - required=True, - help="inference batch size.") - - parser.add_argument("--datasets", - type=str, - required=True, - help="datasets path.") - - parser.add_argument("--input_name", - type=str, - required=True, - help="input name of the model.") - - parser.add_argument("--warmup", - type=int, - default=3, - help="number of warmup before test.") - - parser.add_argument("--num_workers", - type=int, - default=16, - help="number of workers used in pytorch dataloader.") - - parser.add_argument("--acc_target", - type=float, - default=None, - help="Model inference Accuracy target.") - - parser.add_argument("--fps_target", - type=float, - default=None, - help="Model inference FPS target.") - - parser.add_argument("--perf_only", - type=bool, - default=False, - help="Run performance test only") - - args = parser.parse_args() - - return args - -def get_dataloader(data_path, batch_size, num_workers): - dataset = torchvision.datasets.ImageFolder( - data_path, - transforms.Compose( - [ - transforms.Resize(256, interpolation=InterpolationMode.BILINEAR), - transforms.CenterCrop(224), - transforms.PILToTensor(), - transforms.ConvertImageDtype(torch.float), - transforms.Normalize( - mean=(0.485, 0.456, 0.406), - std=(0.229, 0.224, 0.225) - ) - ] - ) - ) - - dataloader = torch.utils.data.DataLoader(dataset, batch_size, num_workers=num_workers) - - return dataloader - -def get_topk_accuracy(pred, label): - if isinstance(pred, np.ndarray): - pred = torch.from_numpy(pred) - - if isinstance(label, np.ndarray): - label = torch.from_numpy(label) - - top1_acc = 0 - top5_acc = 0 - for idx in range(len(label)): - label_value = label[idx] - if label_value == torch.topk(pred[idx].float(), 1).indices.data: - top1_acc += 1 - top5_acc += 1 - - elif label_value in torch.topk(pred[idx].float(), 5).indices.data: - top5_acc += 1 - - return top1_acc, top5_acc - -def main(): - args = parse_args() - - batch_size = args.batchsize - - # create iluvatar target & device - target = tvm.target.iluvatar(model="MR", options="-libs=cudnn,cublas,ixinfer") - device = tvm.device(target.kind.name, 0) - - # load engine - lib = tvm.runtime.load_module(args.engine) - - # create runtime from engine - module = tvm.contrib.graph_executor.GraphModule(lib["default"](device)) - - # just run perf test - if args.perf_only: - ftimer = module.module.time_evaluator("run", device, number=100, repeat=1) - prof_res = np.array(ftimer().results) * 1000 - fps = batch_size * 1000 / np.mean(prof_res) - print(f"\n* Mean inference time: {np.mean(prof_res):.3f} ms, Mean fps: {fps:.3f}") - else: - # warm up - for _ in range(args.warmup): - module.run() - - # get dataloader - dataloader = get_dataloader(args.datasets, batch_size, args.num_workers) - - top1_acc = 0 - top5_acc = 0 - total_num = 0 - - for image, label in tqdm(dataloader): - - # pad the last batch - pad_batch = len(image) != batch_size - - if pad_batch: - origin_size = len(image) - image = np.resize(image, (batch_size, *image.shape[1:])) - - module.set_input(args.input_name, tvm.nd.array(image, device)) - - # run inference - module.run() - - pred = module.get_output(0).asnumpy() - - if pad_batch: - pred = pred[:origin_size] - - # get batch accuracy - batch_top1_acc, batch_top5_acc = get_topk_accuracy(pred, label) - - top1_acc += batch_top1_acc - top5_acc += batch_top5_acc - total_num += batch_size - - result_stat = {} - result_stat["acc@1"] = round(top1_acc / total_num * 100.0, 3) - result_stat["acc@5"] = round(top5_acc / total_num * 100.0, 3) - - print(f"\n* Top1 acc: {result_stat['acc@1']} %, Top5 acc: {result_stat['acc@5']} %") - -if __name__ == "__main__": - main() \ No newline at end of file diff --git a/models/cv/classification/efficientnet_b6/igie/scripts/infer_efficientnet_b6_fp16_accuracy.sh b/models/cv/classification/efficientnet_b6/igie/scripts/infer_efficientnet_b6_fp16_accuracy.sh index 18c5a89c..1cfd2f54 100644 --- a/models/cv/classification/efficientnet_b6/igie/scripts/infer_efficientnet_b6_fp16_accuracy.sh +++ b/models/cv/classification/efficientnet_b6/igie/scripts/infer_efficientnet_b6_fp16_accuracy.sh @@ -20,7 +20,7 @@ model_path="efficientnet_b6.onnx" datasets_path=${DATASETS_DIR} # build engine -python3 build_engine.py \ +python3 ${RUN_DIR}build_engine.py \ --model_path ${model_path} \ --input input:${batchsize},3,224,224 \ --precision fp16 \ @@ -28,7 +28,7 @@ python3 build_engine.py \ # inference -python3 inference.py \ +python3 ${RUN_DIR}inference.py \ --engine efficientnet_b6_bs_${batchsize}_fp16.so \ --batchsize ${batchsize} \ --input_name input \ diff --git a/models/cv/classification/efficientnet_b6/igie/scripts/infer_efficientnet_b6_fp16_performance.sh b/models/cv/classification/efficientnet_b6/igie/scripts/infer_efficientnet_b6_fp16_performance.sh index f52281f0..c4912ab4 100644 --- a/models/cv/classification/efficientnet_b6/igie/scripts/infer_efficientnet_b6_fp16_performance.sh +++ b/models/cv/classification/efficientnet_b6/igie/scripts/infer_efficientnet_b6_fp16_performance.sh @@ -20,7 +20,7 @@ model_path="efficientnet_b6.onnx" datasets_path=${DATASETS_DIR} # build engine -python3 build_engine.py \ +python3 ${RUN_DIR}build_engine.py \ --model_path ${model_path} \ --input input:${batchsize},3,224,224 \ --precision fp16 \ @@ -28,7 +28,7 @@ python3 build_engine.py \ # inference -python3 inference.py \ +python3 ${RUN_DIR}inference.py \ --engine efficientnet_b6_bs_${batchsize}_fp16.so \ --batchsize ${batchsize} \ --input_name input \ -- Gitee From d29c551d1c434f1da06012737af01b7164ad710d Mon Sep 17 00:00:00 2001 From: YoungPeng Date: Fri, 11 Jul 2025 17:20:41 +0800 Subject: [PATCH 03/15] Add: vgg13 inference script. --- models/cv/classification/vgg13/igie/README.md | 53 +++++++++++++++++++ .../classification/vgg13/igie/ci/prepare.sh | 20 +++++++ .../igie/scripts/infer_vgg13_fp16_accuracy.sh | 35 ++++++++++++ .../scripts/infer_vgg13_fp16_performance.sh | 36 +++++++++++++ 4 files changed, 144 insertions(+) create mode 100644 models/cv/classification/vgg13/igie/README.md create mode 100644 models/cv/classification/vgg13/igie/ci/prepare.sh create mode 100644 models/cv/classification/vgg13/igie/scripts/infer_vgg13_fp16_accuracy.sh create mode 100644 models/cv/classification/vgg13/igie/scripts/infer_vgg13_fp16_performance.sh diff --git a/models/cv/classification/vgg13/igie/README.md b/models/cv/classification/vgg13/igie/README.md new file mode 100644 index 00000000..fb0916eb --- /dev/null +++ b/models/cv/classification/vgg13/igie/README.md @@ -0,0 +1,53 @@ +# VGG13 (IGIE) + +## Model Description + +VGG13 is a classic deep convolutional neural network model consisting of 13 convolutional layers and multiple pooling layers. It utilizes 3×3 small convolution kernels to extract image features and completes classification through fully connected layers. Known for its simple structure and high performance, it is well-suited for image classification tasks but requires significant computational resources due to its large parameter size. + +## Supported Environments + +| GPU | [IXUCA SDK](https://gitee.com/deep-spark/deepspark#%E5%A4%A9%E6%95%B0%E6%99%BA%E7%AE%97%E8%BD%AF%E4%BB%B6%E6%A0%88-ixuca) | Release | +| :----: | :----: | :----: | +| MR-V100 | 4.2.0 | 25.03 | + +## Model Preparation + +### Prepare Resources + +Pretrained model: + +Dataset: to download the validation dataset. + +### Install Dependencies + +```bash +pip3 install -r ../../igie_common/requirements.txt +``` + +### Model Conversion + +```bash +python3 ../../igie_common/export.py --model-name vgg13 --weight vgg13-19584684.pth --output vgg13.onnx +``` + +## Model Inference + +```bash +export DATASETS_DIR=/Path/to/imagenet_val/ +export RUN_DIR=../../igie_common/ +``` + +### FP16 + +```bash +# Accuracy +bash scripts/infer_vgg13_fp16_accuracy.sh +# Performance +bash scripts/infer_vgg13_fp16_performance.sh +``` + +## Model Results + +| Model | BatchSize | Precision | FPS | Top-1(%) | Top-5(%) | +| :----: | :-------: | :-------: | :-----: | :------: | :------: | +| VGG13 | 32 | FP16 | 2598.51 | 69.894 | 89.233 | diff --git a/models/cv/classification/vgg13/igie/ci/prepare.sh b/models/cv/classification/vgg13/igie/ci/prepare.sh new file mode 100644 index 00000000..81385dd3 --- /dev/null +++ b/models/cv/classification/vgg13/igie/ci/prepare.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# 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. + +set -x + +pip3 install -r ../../igie_common/requirements.txt +python3 ../../igie_common/export.py --model-name vgg13 --weight vgg13-19584684.pth --output vgg13.onnx \ No newline at end of file diff --git a/models/cv/classification/vgg13/igie/scripts/infer_vgg13_fp16_accuracy.sh b/models/cv/classification/vgg13/igie/scripts/infer_vgg13_fp16_accuracy.sh new file mode 100644 index 00000000..ae196542 --- /dev/null +++ b/models/cv/classification/vgg13/igie/scripts/infer_vgg13_fp16_accuracy.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# 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. + +batchsize=32 +model_path="vgg13.onnx" +datasets_path=${DATASETS_DIR} + +# build engine +python3 ${RUN_DIR}build_engine.py \ + --model_path ${model_path} \ + --input input:${batchsize},3,224,224 \ + --precision fp16 \ + --engine_path vgg13_bs_${batchsize}_fp16.so + + +# inference +python3 ${RUN_DIR}inference.py \ + --engine vgg13_bs_${batchsize}_fp16.so \ + --batchsize ${batchsize} \ + --input_name input \ + --datasets ${datasets_path} \ No newline at end of file diff --git a/models/cv/classification/vgg13/igie/scripts/infer_vgg13_fp16_performance.sh b/models/cv/classification/vgg13/igie/scripts/infer_vgg13_fp16_performance.sh new file mode 100644 index 00000000..c5337250 --- /dev/null +++ b/models/cv/classification/vgg13/igie/scripts/infer_vgg13_fp16_performance.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# 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. + +batchsize=32 +model_path="vgg13.onnx" +datasets_path=${DATASETS_DIR} + +# build engine +python3 ${RUN_DIR}build_engine.py \ + --model_path ${model_path} \ + --input input:${batchsize},3,224,224 \ + --precision fp16 \ + --engine_path vgg13_bs_${batchsize}_fp16.so + + +# inference +python3 ${RUN_DIR}inference.py \ + --engine vgg13_bs_${batchsize}_fp16.so \ + --batchsize ${batchsize} \ + --input_name input \ + --datasets ${datasets_path} \ + --perf_only True \ No newline at end of file -- Gitee From 17ed0e97a96d877c235ac2404aef1462cf3b87f4 Mon Sep 17 00:00:00 2001 From: YoungPeng Date: Fri, 11 Jul 2025 17:44:35 +0800 Subject: [PATCH 04/15] Add: vgg13_bn inference script. --- .../cv/classification/vgg13_bn/igie/README.md | 53 +++++++++++++++++++ .../vgg13_bn/igie/ci/prepare.sh | 20 +++++++ .../scripts/infer_vgg13_bn_fp16_accuracy.sh | 35 ++++++++++++ .../infer_vgg13_bn_fp16_performance.sh | 36 +++++++++++++ 4 files changed, 144 insertions(+) create mode 100644 models/cv/classification/vgg13_bn/igie/README.md create mode 100644 models/cv/classification/vgg13_bn/igie/ci/prepare.sh create mode 100644 models/cv/classification/vgg13_bn/igie/scripts/infer_vgg13_bn_fp16_accuracy.sh create mode 100644 models/cv/classification/vgg13_bn/igie/scripts/infer_vgg13_bn_fp16_performance.sh diff --git a/models/cv/classification/vgg13_bn/igie/README.md b/models/cv/classification/vgg13_bn/igie/README.md new file mode 100644 index 00000000..b1f07611 --- /dev/null +++ b/models/cv/classification/vgg13_bn/igie/README.md @@ -0,0 +1,53 @@ +# VGG13_BN (IGIE) + +## Model Description + +VGG13_BN is an improved version of VGG13, utilizing 3×3 small convolution kernels for feature extraction and adding Batch Normalization layers after each convolutional and fully connected layer. This significantly enhances training stability and convergence speed. With a simple structure and excellent performance, it is ideal for image classification tasks but requires substantial computational resources. + +## Supported Environments + +| GPU | [IXUCA SDK](https://gitee.com/deep-spark/deepspark#%E5%A4%A9%E6%95%B0%E6%99%BA%E7%AE%97%E8%BD%AF%E4%BB%B6%E6%A0%88-ixuca) | Release | +| :----: | :----: | :----: | +| MR-V100 | 4.2.0 | 25.03 | + +## Model Preparation + +### Prepare Resources + +Pretrained model: + +Dataset: to download the validation dataset. + +### Install Dependencies + +```bash +pip3 install -r ../../igie_common/requirements.txt +``` + +### Model Conversion + +```bash +python3 ../../igie_common/export.py --model-name vgg13_bn --weight vgg13_bn-abd245e5.pth --output vgg13_bn.onnx +``` + +## Model Inference + +```bash +export DATASETS_DIR=/Path/to/imagenet_val/ +export RUN_DIR=../../igie_common/ +``` + +### FP16 + +```bash +# Accuracy +bash scripts/infer_vgg13_bn_fp16_accuracy.sh +# Performance +bash scripts/infer_vgg13_bn_fp16_performance.sh +``` + +## Model Results + +| Model | BatchSize | Precision | FPS | Top-1(%) | Top-5(%) | +| :-------: | :-------: | :-------: | :-----: | :------: | :------: | +| VGG13_BN | 32 | FP16 | 2597.53 | 71.539 | 90.347 | diff --git a/models/cv/classification/vgg13_bn/igie/ci/prepare.sh b/models/cv/classification/vgg13_bn/igie/ci/prepare.sh new file mode 100644 index 00000000..6029b6c5 --- /dev/null +++ b/models/cv/classification/vgg13_bn/igie/ci/prepare.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# 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. + +set -x + +pip3 install -r ../../igie_common/requirements.txt +python3 ../../igie_common/export.py --model-name vgg13_bn --weight vgg13_bn-abd245e5.pth --output vgg13_bn.onnx \ No newline at end of file diff --git a/models/cv/classification/vgg13_bn/igie/scripts/infer_vgg13_bn_fp16_accuracy.sh b/models/cv/classification/vgg13_bn/igie/scripts/infer_vgg13_bn_fp16_accuracy.sh new file mode 100644 index 00000000..04d2fd10 --- /dev/null +++ b/models/cv/classification/vgg13_bn/igie/scripts/infer_vgg13_bn_fp16_accuracy.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# 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. + +batchsize=32 +model_path="vgg13_bn.onnx" +datasets_path=${DATASETS_DIR} + +# build engine +python3 ${RUN_DIR}build_engine.py \ + --model_path ${model_path} \ + --input input:${batchsize},3,224,224 \ + --precision fp16 \ + --engine_path vgg13_bn_bs_${batchsize}_fp16.so + + +# inference +python3 ${RUN_DIR}inference.py \ + --engine vgg13_bn_bs_${batchsize}_fp16.so \ + --batchsize ${batchsize} \ + --input_name input \ + --datasets ${datasets_path} \ No newline at end of file diff --git a/models/cv/classification/vgg13_bn/igie/scripts/infer_vgg13_bn_fp16_performance.sh b/models/cv/classification/vgg13_bn/igie/scripts/infer_vgg13_bn_fp16_performance.sh new file mode 100644 index 00000000..33c8777f --- /dev/null +++ b/models/cv/classification/vgg13_bn/igie/scripts/infer_vgg13_bn_fp16_performance.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# 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. + +batchsize=32 +model_path="vgg13_bn.onnx" +datasets_path=${DATASETS_DIR} + +# build engine +python3 ${RUN_DIR}build_engine.py \ + --model_path ${model_path} \ + --input input:${batchsize},3,224,224 \ + --precision fp16 \ + --engine_path vgg13_bn_bs_${batchsize}_fp16.so + + +# inference +python3 ${RUN_DIR}inference.py \ + --engine vgg13_bn_bs_${batchsize}_fp16.so \ + --batchsize ${batchsize} \ + --input_name input \ + --datasets ${datasets_path} \ + --perf_only True \ No newline at end of file -- Gitee From 5715030b7572607cef7db12dc0e20526afd5de57 Mon Sep 17 00:00:00 2001 From: YoungPeng Date: Mon, 14 Jul 2025 10:30:36 +0800 Subject: [PATCH 05/15] Add: mnasnet1_3 inference script. --- .../classification/mnasnet1_3/igie/README.md | 53 +++++++++++++++++++ .../mnasnet1_3/igie/ci/prepare.sh | 20 +++++++ .../scripts/infer_mnasnet1_3_fp16_accuracy.sh | 35 ++++++++++++ .../infer_mnasnet1_3_fp16_performance.sh | 36 +++++++++++++ 4 files changed, 144 insertions(+) create mode 100644 models/cv/classification/mnasnet1_3/igie/README.md create mode 100644 models/cv/classification/mnasnet1_3/igie/ci/prepare.sh create mode 100644 models/cv/classification/mnasnet1_3/igie/scripts/infer_mnasnet1_3_fp16_accuracy.sh create mode 100644 models/cv/classification/mnasnet1_3/igie/scripts/infer_mnasnet1_3_fp16_performance.sh diff --git a/models/cv/classification/mnasnet1_3/igie/README.md b/models/cv/classification/mnasnet1_3/igie/README.md new file mode 100644 index 00000000..c84be8ee --- /dev/null +++ b/models/cv/classification/mnasnet1_3/igie/README.md @@ -0,0 +1,53 @@ +# MNASNet1_3 (IGIE) + +## Model Description + +MNASNet1_3 is a lightweight deep learning model optimized through neural architecture search (NAS). It uses Inverted Residual Blocks and a width multiplier of 1.3, balancing efficiency and accuracy. With a simple structure and excellent performance, it is particularly suited for mobile devices and resource-constrained environments. + +## Supported Environments + +| GPU | [IXUCA SDK](https://gitee.com/deep-spark/deepspark#%E5%A4%A9%E6%95%B0%E6%99%BA%E7%AE%97%E8%BD%AF%E4%BB%B6%E6%A0%88-ixuca) | Release | +| :----: | :----: | :----: | +| MR-V100 | 4.2.0 | 25.03 | + +## Model Preparation + +### Prepare Resources + +Pretrained model: + +Dataset: to download the validation dataset. + +### Install Dependencies + +```bash +pip3 install -r ../../igie_common/requirements.txt +``` + +### Model Conversion + +```bash +python3 ../../igie_common/export.py --model-name mnasnet1_3 --weight mnasnet1_3-a4c69d6f.pth --output mnasnet1_3.onnx +``` + +## Model Inference + +```bash +export DATASETS_DIR=/Path/to/imagenet_val/ +export RUN_DIR=../../igie_common/ +``` + +### FP16 + +```bash +# Accuracy +bash scripts/infer_mnasnet1_3_fp16_accuracy.sh +# Performance +bash scripts/infer_mnasnet1_3_fp16_performance.sh +``` + +## Model Results + +| Model | BatchSize | Precision | FPS | Top-1(%) | Top-5(%) | +| ----------------- | --------- | --------- | -------- | -------- | -------- | +| MnasNet1_3 | 32 | FP16 | 4282.213 | 76.054 | 93.244 | diff --git a/models/cv/classification/mnasnet1_3/igie/ci/prepare.sh b/models/cv/classification/mnasnet1_3/igie/ci/prepare.sh new file mode 100644 index 00000000..68c05a60 --- /dev/null +++ b/models/cv/classification/mnasnet1_3/igie/ci/prepare.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# 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. + +set -x + +pip3 install -r ../../igie_common/requirements.txt +python3 ../../igie_common/export.py --model-name mnasnet1_3 --weight mnasnet1_3-a4c69d6f.pth --output mnasnet1_3.onnx \ No newline at end of file diff --git a/models/cv/classification/mnasnet1_3/igie/scripts/infer_mnasnet1_3_fp16_accuracy.sh b/models/cv/classification/mnasnet1_3/igie/scripts/infer_mnasnet1_3_fp16_accuracy.sh new file mode 100644 index 00000000..f1aff9ed --- /dev/null +++ b/models/cv/classification/mnasnet1_3/igie/scripts/infer_mnasnet1_3_fp16_accuracy.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# 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. + +batchsize=32 +model_path="mnasnet1_3.onnx" +datasets_path=${DATASETS_DIR} + +# build engine +python3 ${RUN_DIR}build_engine.py \ + --model_path ${model_path} \ + --input input:${batchsize},3,224,224 \ + --precision fp16 \ + --engine_path mnasnet1_3_bs_${batchsize}_fp16.so + + +# inference +python3 ${RUN_DIR}inference.py \ + --engine mnasnet1_3_bs_${batchsize}_fp16.so \ + --batchsize ${batchsize} \ + --input_name input \ + --datasets ${datasets_path} \ No newline at end of file diff --git a/models/cv/classification/mnasnet1_3/igie/scripts/infer_mnasnet1_3_fp16_performance.sh b/models/cv/classification/mnasnet1_3/igie/scripts/infer_mnasnet1_3_fp16_performance.sh new file mode 100644 index 00000000..e8c82cdd --- /dev/null +++ b/models/cv/classification/mnasnet1_3/igie/scripts/infer_mnasnet1_3_fp16_performance.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# 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. + +batchsize=32 +model_path="mnasnet1_3.onnx" +datasets_path=${DATASETS_DIR} + +# build engine +python3 ${RUN_DIR}build_engine.py \ + --model_path ${model_path} \ + --input input:${batchsize},3,224,224 \ + --precision fp16 \ + --engine_path mnasnet1_3_bs_${batchsize}_fp16.so + + +# inference +python3 ${RUN_DIR}inference.py \ + --engine mnasnet1_3_bs_${batchsize}_fp16.so \ + --batchsize ${batchsize} \ + --input_name input \ + --datasets ${datasets_path} \ + --perf_only True \ No newline at end of file -- Gitee From a2c321a98123e64936a8d6543fcb5618512057d9 Mon Sep 17 00:00:00 2001 From: YoungPeng Date: Mon, 14 Jul 2025 11:07:08 +0800 Subject: [PATCH 06/15] Add: regnet_x_32gf inference script. --- .../regnet_x_32gf/igie/README.md | 53 +++++++++++++++++++ .../regnet_x_32gf/igie/ci/prepare.sh | 20 +++++++ .../infer_regnet_x_32gf_fp16_accuracy.sh | 35 ++++++++++++ .../infer_regnet_x_32gf_fp16_performance.sh | 36 +++++++++++++ 4 files changed, 144 insertions(+) create mode 100644 models/cv/classification/regnet_x_32gf/igie/README.md create mode 100644 models/cv/classification/regnet_x_32gf/igie/ci/prepare.sh create mode 100644 models/cv/classification/regnet_x_32gf/igie/scripts/infer_regnet_x_32gf_fp16_accuracy.sh create mode 100644 models/cv/classification/regnet_x_32gf/igie/scripts/infer_regnet_x_32gf_fp16_performance.sh diff --git a/models/cv/classification/regnet_x_32gf/igie/README.md b/models/cv/classification/regnet_x_32gf/igie/README.md new file mode 100644 index 00000000..616c7c84 --- /dev/null +++ b/models/cv/classification/regnet_x_32gf/igie/README.md @@ -0,0 +1,53 @@ +# RegNet_x_32gf (IGIE) + +## Model Description + +RegNet_x_32gf is an efficient convolutional neural network model from Facebook AI's RegNet series, designed to provide flexible and efficient deep learning solutions through a regularized network architecture. The core idea of RegNet is to optimize network performance by designing the distribution rules for network width and depth, replacing traditional manual design. RegNet_x_32gf is a large variant with a computational complexity of 32 GFLOPs, making it suitable for high-performance image classification tasks. + +## Supported Environments + +| GPU | [IXUCA SDK](https://gitee.com/deep-spark/deepspark#%E5%A4%A9%E6%95%B0%E6%99%BA%E7%AE%97%E8%BD%AF%E4%BB%B6%E6%A0%88-ixuca) | Release | +| :----: | :----: | :----: | +| MR-V100 | 4.2.0 | 25.06 | + +## Model Preparation + +### Prepare Resources + +Pretrained model: + +Dataset: to download the validation dataset. + +### Install Dependencies + +```bash +pip3 install -r ../../igie_common/requirements.txt +``` + +### Model Conversion + +```bash +python3 ../../igie_common/export.py --model-name regnet_x_32gf --weight regnet_x_32gf-9d47f8d0.pth --output regnet_x_32gf.onnx +``` + +## Model Inference + +```bash +export DATASETS_DIR=/Path/to/imagenet_val/ +export RUN_DIR=../../igie_common/ +``` + +### FP16 + +```bash +# Accuracy +bash scripts/infer_regnet_x_32gf_fp16_accuracy.sh +# Performance +bash scripts/infer_regnet_x_32gf_fp16_performance.sh +``` + +## Model Results + +| Model | BatchSize | Precision | FPS | Top-1(%) | Top-5(%) | +| :------------: | :-------: | :-------: | :-----: | :------: | :------: | +| RegNet_x_32gf | 32 | FP16 | 449.752 | 80.594 | 95.216 | diff --git a/models/cv/classification/regnet_x_32gf/igie/ci/prepare.sh b/models/cv/classification/regnet_x_32gf/igie/ci/prepare.sh new file mode 100644 index 00000000..728b3d0e --- /dev/null +++ b/models/cv/classification/regnet_x_32gf/igie/ci/prepare.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# Copyright (c) 2025, 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. + +set -x + +pip3 install -r ../../igie_common/requirements.txt +python3 ../../igie_common/export.py --model-name regnet_x_32gf --weight regnet_x_32gf-9d47f8d0.pth --output regnet_x_32gf.onnx diff --git a/models/cv/classification/regnet_x_32gf/igie/scripts/infer_regnet_x_32gf_fp16_accuracy.sh b/models/cv/classification/regnet_x_32gf/igie/scripts/infer_regnet_x_32gf_fp16_accuracy.sh new file mode 100644 index 00000000..5516f47c --- /dev/null +++ b/models/cv/classification/regnet_x_32gf/igie/scripts/infer_regnet_x_32gf_fp16_accuracy.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Copyright (c) 2025, 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. + +batchsize=32 +model_path="regnet_x_32gf.onnx" +datasets_path=${DATASETS_DIR} + +# build engine +python3 ${RUN_DIR}build_engine.py \ + --model_path ${model_path} \ + --input input:${batchsize},3,224,224 \ + --precision fp16 \ + --engine_path regnet_x_32gf_bs_${batchsize}_fp16.so + + +# inference +python3 ${RUN_DIR}inference.py \ + --engine regnet_x_32gf_bs_${batchsize}_fp16.so \ + --batchsize ${batchsize} \ + --input_name input \ + --datasets ${datasets_path} \ No newline at end of file diff --git a/models/cv/classification/regnet_x_32gf/igie/scripts/infer_regnet_x_32gf_fp16_performance.sh b/models/cv/classification/regnet_x_32gf/igie/scripts/infer_regnet_x_32gf_fp16_performance.sh new file mode 100644 index 00000000..3dc5fe63 --- /dev/null +++ b/models/cv/classification/regnet_x_32gf/igie/scripts/infer_regnet_x_32gf_fp16_performance.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# Copyright (c) 2025, 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. + +batchsize=32 +model_path="regnet_x_32gf.onnx" +datasets_path=${DATASETS_DIR} + +# build engine +python3 ${RUN_DIR}build_engine.py \ + --model_path ${model_path} \ + --input input:${batchsize},3,224,224 \ + --precision fp16 \ + --engine_path regnet_x_32gf_bs_${batchsize}_fp16.so + + +# inference +python3 ${RUN_DIR}inference.py \ + --engine regnet_x_32gf_bs_${batchsize}_fp16.so \ + --batchsize ${batchsize} \ + --input_name input \ + --datasets ${datasets_path} \ + --perf_only True \ No newline at end of file -- Gitee From f409cad1c2e1b2f6e0e5f09960512c8d25b7aebc Mon Sep 17 00:00:00 2001 From: YoungPeng Date: Mon, 14 Jul 2025 13:43:22 +0800 Subject: [PATCH 07/15] Add: regnet_y_32gf inference script. --- .../regnet_y_32gf/igie/README.md | 53 +++++++++++++++++++ .../regnet_y_32gf/igie/ci/prepare.sh | 20 +++++++ .../infer_regnet_y_32gf_fp16_accuracy.sh | 35 ++++++++++++ .../infer_regnet_y_32gf_fp16_performance.sh | 36 +++++++++++++ 4 files changed, 144 insertions(+) create mode 100644 models/cv/classification/regnet_y_32gf/igie/README.md create mode 100644 models/cv/classification/regnet_y_32gf/igie/ci/prepare.sh create mode 100644 models/cv/classification/regnet_y_32gf/igie/scripts/infer_regnet_y_32gf_fp16_accuracy.sh create mode 100644 models/cv/classification/regnet_y_32gf/igie/scripts/infer_regnet_y_32gf_fp16_performance.sh diff --git a/models/cv/classification/regnet_y_32gf/igie/README.md b/models/cv/classification/regnet_y_32gf/igie/README.md new file mode 100644 index 00000000..3b04c93d --- /dev/null +++ b/models/cv/classification/regnet_y_32gf/igie/README.md @@ -0,0 +1,53 @@ +# RegNet_y_32gf (IGIE) + +## Model Description + +RegNet_y_32gf is a variant from Facebook AI's RegNet series, belonging to the RegNet_y sub-series. Compared to the RegNet_x series, the RegNet_y series introduces SE (Squeeze-and-Excitation) modules into the network architecture, further enhancing feature representation capabilities. + +## Supported Environments + +| GPU | [IXUCA SDK](https://gitee.com/deep-spark/deepspark#%E5%A4%A9%E6%95%B0%E6%99%BA%E7%AE%97%E8%BD%AF%E4%BB%B6%E6%A0%88-ixuca) | Release | +| :----: | :----: | :----: | +| MR-V100 | 4.2.0 | 25.06 | + +## Model Preparation + +### Prepare Resources + +Pretrained model: + +Dataset: to download the validation dataset. + +### Install Dependencies + +```bash +pip3 install -r ../../igie_common/requirements.txt +``` + +### Model Conversion + +```bash +python3 ../../igie_common/export.py --model-name regnet_y_32gf --weight regnet_y_32gf-4dee3f7a.pth --output regnet_y_32gf.onnx +``` + +## Model Inference + +```bash +export DATASETS_DIR=/Path/to/imagenet_val/ +export RUN_DIR=../../igie_common/ +``` + +### FP16 + +```bash +# Accuracy +bash scripts/infer_regnet_y_32gf_fp16_accuracy.sh +# Performance +bash scripts/infer_regnet_y_32gf_fp16_performance.sh +``` + +## Model Results + +| Model | BatchSize | Precision | FPS | Top-1(%) | Top-5(%) | +| :------------: | :-------: | :-------: | :-----: | :------: | :------: | +| RegNet_y_32gf | 32 | FP16 | 413.726 | 80.832 | 95.321 | diff --git a/models/cv/classification/regnet_y_32gf/igie/ci/prepare.sh b/models/cv/classification/regnet_y_32gf/igie/ci/prepare.sh new file mode 100644 index 00000000..098fabc9 --- /dev/null +++ b/models/cv/classification/regnet_y_32gf/igie/ci/prepare.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# Copyright (c) 2025, 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. + +set -x + +pip3 install -r ../../igie_common/requirements.txt +python3 ../../igie_common/export.py --model-name regnet_y_32gf --weight regnet_y_32gf-4dee3f7a.pth --output regnet_y_32gf.onnx diff --git a/models/cv/classification/regnet_y_32gf/igie/scripts/infer_regnet_y_32gf_fp16_accuracy.sh b/models/cv/classification/regnet_y_32gf/igie/scripts/infer_regnet_y_32gf_fp16_accuracy.sh new file mode 100644 index 00000000..18a6fc9d --- /dev/null +++ b/models/cv/classification/regnet_y_32gf/igie/scripts/infer_regnet_y_32gf_fp16_accuracy.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Copyright (c) 2025, 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. + +batchsize=32 +model_path="regnet_y_32gf.onnx" +datasets_path=${DATASETS_DIR} + +# build engine +python3 ${RUN_DIR}build_engine.py \ + --model_path ${model_path} \ + --input input:${batchsize},3,224,224 \ + --precision fp16 \ + --engine_path regnet_y_32gf_bs_${batchsize}_fp16.so + + +# inference +python3 ${RUN_DIR}inference.py \ + --engine regnet_y_32gf_bs_${batchsize}_fp16.so \ + --batchsize ${batchsize} \ + --input_name input \ + --datasets ${datasets_path} \ No newline at end of file diff --git a/models/cv/classification/regnet_y_32gf/igie/scripts/infer_regnet_y_32gf_fp16_performance.sh b/models/cv/classification/regnet_y_32gf/igie/scripts/infer_regnet_y_32gf_fp16_performance.sh new file mode 100644 index 00000000..b1d69f46 --- /dev/null +++ b/models/cv/classification/regnet_y_32gf/igie/scripts/infer_regnet_y_32gf_fp16_performance.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# Copyright (c) 2025, 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. + +batchsize=32 +model_path="regnet_y_32gf.onnx" +datasets_path=${DATASETS_DIR} + +# build engine +python3 ${RUN_DIR}build_engine.py \ + --model_path ${model_path} \ + --input input:${batchsize},3,224,224 \ + --precision fp16 \ + --engine_path regnet_y_32gf_bs_${batchsize}_fp16.so + + +# inference +python3 ${RUN_DIR}inference.py \ + --engine regnet_y_32gf_bs_${batchsize}_fp16.so \ + --batchsize ${batchsize} \ + --input_name input \ + --datasets ${datasets_path} \ + --perf_only True \ No newline at end of file -- Gitee From c56fa1693e0319a50809f3e13193543ccd495218 Mon Sep 17 00:00:00 2001 From: YoungPeng Date: Mon, 14 Jul 2025 14:05:13 +0800 Subject: [PATCH 08/15] Add: regnet_y_3_2gf inference script. --- .../regnet_y_3_2gf/igie/README.md | 53 +++++++++++++++++++ .../regnet_y_3_2gf/igie/ci/prepare.sh | 20 +++++++ .../infer_regnet_y_3_2gf_fp16_accuracy.sh | 35 ++++++++++++ .../infer_regnet_y_3_2gf_fp16_performance.sh | 36 +++++++++++++ 4 files changed, 144 insertions(+) create mode 100644 models/cv/classification/regnet_y_3_2gf/igie/README.md create mode 100644 models/cv/classification/regnet_y_3_2gf/igie/ci/prepare.sh create mode 100644 models/cv/classification/regnet_y_3_2gf/igie/scripts/infer_regnet_y_3_2gf_fp16_accuracy.sh create mode 100644 models/cv/classification/regnet_y_3_2gf/igie/scripts/infer_regnet_y_3_2gf_fp16_performance.sh diff --git a/models/cv/classification/regnet_y_3_2gf/igie/README.md b/models/cv/classification/regnet_y_3_2gf/igie/README.md new file mode 100644 index 00000000..4aea910a --- /dev/null +++ b/models/cv/classification/regnet_y_3_2gf/igie/README.md @@ -0,0 +1,53 @@ +# RegNet_y_3_2gf (IGIE) + +## Model Description + +RegNet_y_3_2gf is a lightweight deep learning model designed with a regularized architecture, integrating Bottleneck Blocks and SE modules to enhance feature representation. With lower computational complexity, it is well-suited for mid-performance image classification tasks in resource-constrained environments. + +## Supported Environments + +| GPU | [IXUCA SDK](https://gitee.com/deep-spark/deepspark#%E5%A4%A9%E6%95%B0%E6%99%BA%E7%AE%97%E8%BD%AF%E4%BB%B6%E6%A0%88-ixuca) | Release | +| :----: | :----: | :----: | +| MR-V100 | 4.2.0 | 25.06 | + +## Model Preparation + +### Prepare Resources + +Pretrained model: + +Dataset: to download the validation dataset. + +### Install Dependencies + +```bash +pip3 install -r ../../igie_common/requirements.txt +``` + +### Model Conversion + +```bash +python3 ../../igie_common/export.py --model-name regnet_y_3_2gf --weight regnet_y_3_2gf-b5a9779c.pth --output regnet_y_3_2gf.onnx +``` + +## Model Inference + +```bash +export DATASETS_DIR=/Path/to/imagenet_val/ +export RUN_DIR=../../igie_common/ +``` + +### FP16 + +```bash +# Accuracy +bash scripts/infer_regnet_y_3_2gf_fp16_accuracy.sh +# Performance +bash scripts/infer_regnet_y_3_2gf_fp16_performance.sh +``` + +## Model Results + +| Model | BatchSize | Precision | FPS | Top-1(%) | Top-5(%) | +| :----: | :----: | :----: | :----: | :----: | :----: | +| RegNet_y_3_2gf | 32 | FP16 | 1548.577| 78.913 | 94.542 | diff --git a/models/cv/classification/regnet_y_3_2gf/igie/ci/prepare.sh b/models/cv/classification/regnet_y_3_2gf/igie/ci/prepare.sh new file mode 100644 index 00000000..6c075268 --- /dev/null +++ b/models/cv/classification/regnet_y_3_2gf/igie/ci/prepare.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# Copyright (c) 2025, 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. + +set -x + +pip3 install -r ../../igie_common/requirements.txt +python3 ../../igie_common/export.py --model-name regnet_y_3_2gf --weight regnet_y_3_2gf-b5a9779c.pth --output regnet_y_3_2gf.onnx \ No newline at end of file diff --git a/models/cv/classification/regnet_y_3_2gf/igie/scripts/infer_regnet_y_3_2gf_fp16_accuracy.sh b/models/cv/classification/regnet_y_3_2gf/igie/scripts/infer_regnet_y_3_2gf_fp16_accuracy.sh new file mode 100644 index 00000000..692fb92d --- /dev/null +++ b/models/cv/classification/regnet_y_3_2gf/igie/scripts/infer_regnet_y_3_2gf_fp16_accuracy.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Copyright (c) 2025, 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. + +batchsize=32 +model_path="regnet_y_3_2gf.onnx" +datasets_path=${DATASETS_DIR} + +# build engine +python3 ${RUN_DIR}build_engine.py \ + --model_path ${model_path} \ + --input input:${batchsize},3,224,224 \ + --precision fp16 \ + --engine_path regnet_y_3_2gf_bs_${batchsize}_fp16.so + + +# inference +python3 ${RUN_DIR}inference.py \ + --engine regnet_y_3_2gf_bs_${batchsize}_fp16.so \ + --batchsize ${batchsize} \ + --input_name input \ + --datasets ${datasets_path} \ No newline at end of file diff --git a/models/cv/classification/regnet_y_3_2gf/igie/scripts/infer_regnet_y_3_2gf_fp16_performance.sh b/models/cv/classification/regnet_y_3_2gf/igie/scripts/infer_regnet_y_3_2gf_fp16_performance.sh new file mode 100644 index 00000000..0d3905ff --- /dev/null +++ b/models/cv/classification/regnet_y_3_2gf/igie/scripts/infer_regnet_y_3_2gf_fp16_performance.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# Copyright (c) 2025, 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. + +batchsize=32 +model_path="regnet_y_3_2gf.onnx" +datasets_path=${DATASETS_DIR} + +# build engine +python3 ${RUN_DIR}build_engine.py \ + --model_path ${model_path} \ + --input input:${batchsize},3,224,224 \ + --precision fp16 \ + --engine_path regnet_y_3_2gf_bs_${batchsize}_fp16.so + + +# inference +python3 ${RUN_DIR}inference.py \ + --engine regnet_y_3_2gf_bs_${batchsize}_fp16.so \ + --batchsize ${batchsize} \ + --input_name input \ + --datasets ${datasets_path} \ + --perf_only True \ No newline at end of file -- Gitee From ea99fe1d2e2483460e5d2214f9368a48c757fd29 Mon Sep 17 00:00:00 2001 From: YoungPeng Date: Mon, 14 Jul 2025 14:26:14 +0800 Subject: [PATCH 09/15] Add: regnet_x_400mf inference script. --- .../regnet_x_400mf/igie/README.md | 53 +++++++++++++++++++ .../regnet_x_400mf/igie/ci/prepare.sh | 20 +++++++ .../infer_regnet_x_400mf_fp16_accuracy.sh | 35 ++++++++++++ .../infer_regnet_x_400mf_fp16_performance.sh | 36 +++++++++++++ 4 files changed, 144 insertions(+) create mode 100644 models/cv/classification/regnet_x_400mf/igie/README.md create mode 100644 models/cv/classification/regnet_x_400mf/igie/ci/prepare.sh create mode 100644 models/cv/classification/regnet_x_400mf/igie/scripts/infer_regnet_x_400mf_fp16_accuracy.sh create mode 100644 models/cv/classification/regnet_x_400mf/igie/scripts/infer_regnet_x_400mf_fp16_performance.sh diff --git a/models/cv/classification/regnet_x_400mf/igie/README.md b/models/cv/classification/regnet_x_400mf/igie/README.md new file mode 100644 index 00000000..f1dee331 --- /dev/null +++ b/models/cv/classification/regnet_x_400mf/igie/README.md @@ -0,0 +1,53 @@ +# RegNet_x_400mf (IGIE) + +## Model Description + +RegNet_x_400mf is a lightweight deep learning model designed with a regularized architecture, utilizing Bottleneck Blocks for efficient feature extraction. With lower computational complexity, it is well-suited for mid-scale image classification tasks in resource-constrained environments. + +## Supported Environments + +| GPU | [IXUCA SDK](https://gitee.com/deep-spark/deepspark#%E5%A4%A9%E6%95%B0%E6%99%BA%E7%AE%97%E8%BD%AF%E4%BB%B6%E6%A0%88-ixuca) | Release | +| :----: | :----: | :----: | +| MR-V100 | 4.2.0 | 25.06 | + +## Model Preparation + +### Prepare Resources + +Pretrained model: + +Dataset: to download the validation dataset. + +### Install Dependencies + +```bash +pip3 install -r ../../igie_common/requirements.txt +``` + +### Model Conversion + +```bash +python3 ../../igie_common/export.py --model-name regnet_x_400mf --weight regnet_x_400mf-adf1edd5.pth --output regnet_x_400mf.onnx +``` + +## Model Inference + +```bash +export DATASETS_DIR=/Path/to/imagenet_val/ +export RUN_DIR=../../igie_common/ +``` + +### FP16 + +```bash +# Accuracy +bash scripts/infer_regnet_x_400mf_fp16_accuracy.sh +# Performance +bash scripts/infer_regnet_x_400mf_fp16_performance.sh +``` + +## Model Results + +| Model | BatchSize | Precision | FPS | Top-1(%) | Top-5(%) | +| :----: | :----: | :----: | :----: | :----: | :----: | +| RegNet_x_400mf | 32 | FP16 | 7951.452| 72.799 | 90.933 | diff --git a/models/cv/classification/regnet_x_400mf/igie/ci/prepare.sh b/models/cv/classification/regnet_x_400mf/igie/ci/prepare.sh new file mode 100644 index 00000000..b02971d2 --- /dev/null +++ b/models/cv/classification/regnet_x_400mf/igie/ci/prepare.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# Copyright (c) 2025, 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. + +set -x + +pip3 install -r ../../igie_common/requirements.txt +python3 ../../igie_common/export.py --model-name regnet_x_400mf --weight regnet_x_400mf-adf1edd5.pth --output regnet_x_400mf.onnx \ No newline at end of file diff --git a/models/cv/classification/regnet_x_400mf/igie/scripts/infer_regnet_x_400mf_fp16_accuracy.sh b/models/cv/classification/regnet_x_400mf/igie/scripts/infer_regnet_x_400mf_fp16_accuracy.sh new file mode 100644 index 00000000..8ae3eae6 --- /dev/null +++ b/models/cv/classification/regnet_x_400mf/igie/scripts/infer_regnet_x_400mf_fp16_accuracy.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Copyright (c) 2025, 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. + +batchsize=32 +model_path="regnet_x_400mf.onnx" +datasets_path=${DATASETS_DIR} + +# build engine +python3 ${RUN_DIR}build_engine.py \ + --model_path ${model_path} \ + --input input:${batchsize},3,224,224 \ + --precision fp16 \ + --engine_path regnet_x_400mf_bs_${batchsize}_fp16.so + + +# inference +python3 ${RUN_DIR}inference.py \ + --engine regnet_x_400mf_bs_${batchsize}_fp16.so \ + --batchsize ${batchsize} \ + --input_name input \ + --datasets ${datasets_path} \ No newline at end of file diff --git a/models/cv/classification/regnet_x_400mf/igie/scripts/infer_regnet_x_400mf_fp16_performance.sh b/models/cv/classification/regnet_x_400mf/igie/scripts/infer_regnet_x_400mf_fp16_performance.sh new file mode 100644 index 00000000..0682f981 --- /dev/null +++ b/models/cv/classification/regnet_x_400mf/igie/scripts/infer_regnet_x_400mf_fp16_performance.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# Copyright (c) 2025, 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. + +batchsize=32 +model_path="regnet_x_400mf.onnx" +datasets_path=${DATASETS_DIR} + +# build engine +python3 ${RUN_DIR}build_engine.py \ + --model_path ${model_path} \ + --input input:${batchsize},3,224,224 \ + --precision fp16 \ + --engine_path regnet_x_400mf_bs_${batchsize}_fp16.so + + +# inference +python3 ${RUN_DIR}inference.py \ + --engine regnet_x_400mf_bs_${batchsize}_fp16.so \ + --batchsize ${batchsize} \ + --input_name input \ + --datasets ${datasets_path} \ + --perf_only True \ No newline at end of file -- Gitee From 7d418e77cf4414d9ef76d92c6a2f27e523fcaac1 Mon Sep 17 00:00:00 2001 From: YoungPeng Date: Mon, 14 Jul 2025 14:43:42 +0800 Subject: [PATCH 10/15] Add: regnet_y_400mf inference script. --- .../regnet_y_400mf/igie/README.md | 53 +++++++++++++++++++ .../regnet_y_400mf/igie/ci/prepare.sh | 20 +++++++ .../infer_regnet_y_400mf_fp16_accuracy.sh | 35 ++++++++++++ .../infer_regnet_y_400mf_fp16_performance.sh | 36 +++++++++++++ 4 files changed, 144 insertions(+) create mode 100644 models/cv/classification/regnet_y_400mf/igie/README.md create mode 100644 models/cv/classification/regnet_y_400mf/igie/ci/prepare.sh create mode 100644 models/cv/classification/regnet_y_400mf/igie/scripts/infer_regnet_y_400mf_fp16_accuracy.sh create mode 100644 models/cv/classification/regnet_y_400mf/igie/scripts/infer_regnet_y_400mf_fp16_performance.sh diff --git a/models/cv/classification/regnet_y_400mf/igie/README.md b/models/cv/classification/regnet_y_400mf/igie/README.md new file mode 100644 index 00000000..0b993462 --- /dev/null +++ b/models/cv/classification/regnet_y_400mf/igie/README.md @@ -0,0 +1,53 @@ +# RegNet_y_400mf (IGIE) + +## Model Description + +RegNet_y_400mf is a lightweight deep learning model designed with a regularized architecture, integrating Bottleneck Blocks and SE modules to enhance feature representation. With lower computational complexity, it is well-suited for mid-scale image classification tasks in resource-constrained environments. + +## Supported Environments + +| GPU | [IXUCA SDK](https://gitee.com/deep-spark/deepspark#%E5%A4%A9%E6%95%B0%E6%99%BA%E7%AE%97%E8%BD%AF%E4%BB%B6%E6%A0%88-ixuca) | Release | +| :----: | :----: | :----: | +| MR-V100 | 4.2.0 | 25.06 | + +## Model Preparation + +### Prepare Resources + +Pretrained model: + +Dataset: to download the validation dataset. + +### Install Dependencies + +```bash +pip3 install -r ../../igie_common/requirements.txt +``` + +### Model Conversion + +```bash +python3 ../../igie_common/export.py --model-name regnet_y_400mf --weight regnet_y_400mf-c65dace8.pth --output regnet_y_400mf.onnx +``` + +## Model Inference + +```bash +export DATASETS_DIR=/Path/to/imagenet_val/ +export RUN_DIR=../../igie_common/ +``` + +### FP16 + +```bash +# Accuracy +bash scripts/infer_regnet_y_400mf_fp16_accuracy.sh +# Performance +bash scripts/infer_regnet_y_400mf_fp16_performance.sh +``` + +## Model Results + +| Model | BatchSize | Precision | FPS | Top-1(%) | Top-5(%) | +| :----: | :----: | :----: | :----: | :----: | :----: | +| RegNet_y_400mf | 32 | FP16 | 4111.783| 73.992 | 91.693 | diff --git a/models/cv/classification/regnet_y_400mf/igie/ci/prepare.sh b/models/cv/classification/regnet_y_400mf/igie/ci/prepare.sh new file mode 100644 index 00000000..ac79cef0 --- /dev/null +++ b/models/cv/classification/regnet_y_400mf/igie/ci/prepare.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# Copyright (c) 2025, 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. + +set -x + +pip3 install -r ../../igie_common/requirements.txt +python3 ../../igie_common/export.py --model-name regnet_y_400mf --weight regnet_y_400mf-c65dace8.pth --output regnet_y_400mf.onnx diff --git a/models/cv/classification/regnet_y_400mf/igie/scripts/infer_regnet_y_400mf_fp16_accuracy.sh b/models/cv/classification/regnet_y_400mf/igie/scripts/infer_regnet_y_400mf_fp16_accuracy.sh new file mode 100644 index 00000000..f943ae6f --- /dev/null +++ b/models/cv/classification/regnet_y_400mf/igie/scripts/infer_regnet_y_400mf_fp16_accuracy.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Copyright (c) 2025, 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. + +batchsize=32 +model_path="regnet_y_400mf.onnx" +datasets_path=${DATASETS_DIR} + +# build engine +python3 ${RUN_DIR}build_engine.py \ + --model_path ${model_path} \ + --input input:${batchsize},3,224,224 \ + --precision fp16 \ + --engine_path regnet_y_400mf_bs_${batchsize}_fp16.so + + +# inference +python3 ${RUN_DIR}inference.py \ + --engine regnet_y_400mf_bs_${batchsize}_fp16.so \ + --batchsize ${batchsize} \ + --input_name input \ + --datasets ${datasets_path} \ No newline at end of file diff --git a/models/cv/classification/regnet_y_400mf/igie/scripts/infer_regnet_y_400mf_fp16_performance.sh b/models/cv/classification/regnet_y_400mf/igie/scripts/infer_regnet_y_400mf_fp16_performance.sh new file mode 100644 index 00000000..0d25f86d --- /dev/null +++ b/models/cv/classification/regnet_y_400mf/igie/scripts/infer_regnet_y_400mf_fp16_performance.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# Copyright (c) 2025, 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. + +batchsize=32 +model_path="regnet_y_400mf.onnx" +datasets_path=${DATASETS_DIR} + +# build engine +python3 ${RUN_DIR}build_engine.py \ + --model_path ${model_path} \ + --input input:${batchsize},3,224,224 \ + --precision fp16 \ + --engine_path regnet_y_400mf_bs_${batchsize}_fp16.so + + +# inference +python3 ${RUN_DIR}inference.py \ + --engine regnet_y_400mf_bs_${batchsize}_fp16.so \ + --batchsize ${batchsize} \ + --input_name input \ + --datasets ${datasets_path} \ + --perf_only True \ No newline at end of file -- Gitee From 7a7f2093ea10f0a4a32a5f644f344675cae4d406 Mon Sep 17 00:00:00 2001 From: YoungPeng Date: Mon, 14 Jul 2025 15:48:48 +0800 Subject: [PATCH 11/15] Add: yolov13 inference script. --- .../object_detection/yolov13/igie/README.md | 59 ++++++++ .../yolov13/igie/build_engine.py | 73 +++++++++ .../yolov13/igie/ci/prepare.sh | 36 +++++ .../object_detection/yolov13/igie/export.py | 43 ++++++ .../yolov13/igie/inference.py | 140 ++++++++++++++++++ .../yolov13/igie/requirements.txt | 3 + .../scripts/infer_yolov13_fp16_accuracy.sh | 35 +++++ .../scripts/infer_yolov13_fp16_performance.sh | 36 +++++ .../yolov13/igie/validator.py | 89 +++++++++++ 9 files changed, 514 insertions(+) create mode 100644 models/cv/object_detection/yolov13/igie/README.md create mode 100644 models/cv/object_detection/yolov13/igie/build_engine.py create mode 100644 models/cv/object_detection/yolov13/igie/ci/prepare.sh create mode 100644 models/cv/object_detection/yolov13/igie/export.py create mode 100644 models/cv/object_detection/yolov13/igie/inference.py create mode 100644 models/cv/object_detection/yolov13/igie/requirements.txt create mode 100644 models/cv/object_detection/yolov13/igie/scripts/infer_yolov13_fp16_accuracy.sh create mode 100644 models/cv/object_detection/yolov13/igie/scripts/infer_yolov13_fp16_performance.sh create mode 100644 models/cv/object_detection/yolov13/igie/validator.py diff --git a/models/cv/object_detection/yolov13/igie/README.md b/models/cv/object_detection/yolov13/igie/README.md new file mode 100644 index 00000000..e93042ec --- /dev/null +++ b/models/cv/object_detection/yolov13/igie/README.md @@ -0,0 +1,59 @@ +# YOLOv13 (IGIE) + +## Model Description + +YOLOv13 addresses the detection performance bottlenecks of the traditional YOLO series in complex scenarios through innovative HyperACE and FullPAD mechanisms. Additionally, it incorporates lightweight design to significantly reduce computational complexity and parameter count, making it an accurate and efficient object detection model. + +## Supported Environments + +| GPU | [IXUCA SDK](https://gitee.com/deep-spark/deepspark#%E5%A4%A9%E6%95%B0%E6%99%BA%E7%AE%97%E8%BD%AF%E4%BB%B6%E6%A0%88-ixuca) | Release | +| :----: | :----: | :----: | +| MR-V100 | 4.3.0 | 25.09 | + +## Model Preparation + +### Prepare Resources + +Pretrained model: + +### Install Dependencies + +```bash +pip3 install -r requirements.txt +``` + +## Model Conversion + +```bash +git clone --depth 1 https://github.com/iMoonLab/yolov13.git +cd yolov13 +pip3 install -e . +cd .. + +python3 export.py --weight yolov13n.pt --batch 32 +``` + +## Model Inference + +```bash +export DATASETS_DIR=/Path/to/coco/ +``` + +### FP16 + +```bash +# Accuracy +bash scripts/infer_yolov13_fp16_accuracy.sh +# Performance +bash scripts/infer_yolov13_fp16_performance.sh +``` + +## Model Results + +| Model | BatchSize | Precision | FPS | IOU@0.5 | IOU@0.5:0.95 | +| ------- | --------- | --------- | ------- | ------- | ------------ | +| YOLOv13 | 32 | FP16 | 400.68 | 0.574 | 0.412 | + +## References + +- [YOLOv13](https://github.com/iMoonLab/yolov13) diff --git a/models/cv/object_detection/yolov13/igie/build_engine.py b/models/cv/object_detection/yolov13/igie/build_engine.py new file mode 100644 index 00000000..54aa8847 --- /dev/null +++ b/models/cv/object_detection/yolov13/igie/build_engine.py @@ -0,0 +1,73 @@ +# Copyright (c) 2025, 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 tvm +import argparse +from tvm import relay +from tvm.relay.import_model import import_model_to_igie + +def parse_args(): + parser = argparse.ArgumentParser() + + parser.add_argument("--model_path", + type=str, + required=True, + help="original model path.") + + parser.add_argument("--engine_path", + type=str, + required=True, + help="igie export engine path.") + + parser.add_argument("--input", + type=str, + required=True, + help=""" + input info of the model, format should be: + input_name:input_shape + eg: --input input:1,3,224,224. + """) + + parser.add_argument("--precision", + type=str, + choices=["fp32", "fp16", "int8"], + required=True, + help="model inference precision.") + + args = parser.parse_args() + + return args + +def main(): + args = parse_args() + + # get input valueinfo + input_name, input_shape = args.input.split(":") + shape = tuple([int(s) for s in input_shape.split(",")]) + input_dict = {input_name: shape} + + target = tvm.target.iluvatar(model="MR", options="-libs=cudnn,cublas,ixinfer") + + mod, params = import_model_to_igie(args.model_path, input_dict, backend="igie") + + # build engine + lib = tvm.relay.build(mod, target=target, params=params, precision=args.precision) + + # export engine + lib.export_library(args.engine_path) + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/models/cv/object_detection/yolov13/igie/ci/prepare.sh b/models/cv/object_detection/yolov13/igie/ci/prepare.sh new file mode 100644 index 00000000..0c535fcc --- /dev/null +++ b/models/cv/object_detection/yolov13/igie/ci/prepare.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# Copyright (c) 2025, 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. + +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/iMoonLab/yolov13.git + +cd yolov13 +pip3 install -e . +cd .. + +python3 export.py --weight yolov13n.pt --batch 32 diff --git a/models/cv/object_detection/yolov13/igie/export.py b/models/cv/object_detection/yolov13/igie/export.py new file mode 100644 index 00000000..780b9b2a --- /dev/null +++ b/models/cv/object_detection/yolov13/igie/export.py @@ -0,0 +1,43 @@ +# Copyright (c) 2025, 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 +from ultralytics import YOLO + +def parse_args(): + parser = argparse.ArgumentParser() + + parser.add_argument("--weight", + type=str, + required=True, + help="pytorch model weight.") + + parser.add_argument("--batch", + type=int, + required=True, + help="batchsize of the model.") + args = parser.parse_args() + + return args + +def main(): + args = parse_args() + + model = YOLO(args.weight).cpu() + + model.export(format='onnx', batch=args.batch, imgsz=(640, 640), optimize=True, simplify=True, opset=13) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/models/cv/object_detection/yolov13/igie/inference.py b/models/cv/object_detection/yolov13/igie/inference.py new file mode 100644 index 00000000..2286d11c --- /dev/null +++ b/models/cv/object_detection/yolov13/igie/inference.py @@ -0,0 +1,140 @@ +# Copyright (c) 2025, 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 os + +import tvm +from tvm import relay + +import numpy as np +from pathlib import Path +from ultralytics import YOLO +from ultralytics.cfg import get_cfg +from ultralytics.utils import DEFAULT_CFG +from validator import IGIE_Validator + + + +def parse_args(): + parser = argparse.ArgumentParser() + + parser.add_argument("--engine", + type=str, + required=True, + help="igie engine path.") + + parser.add_argument("--batchsize", + type=int, + required=True, + help="inference batch size.") + + parser.add_argument("--datasets", + type=str, + required=True, + help="datasets path.") + + parser.add_argument("--input_name", + type=str, + required=True, + help="input name of the model.") + + parser.add_argument("--warmup", + type=int, + default=3, + help="number of warmup before test.") + + parser.add_argument("--acc_target", + type=float, + default=None, + help="Model inference Accuracy target.") + + parser.add_argument("--fps_target", + type=float, + default=None, + help="Model inference FPS target.") + + parser.add_argument("--perf_only", + type=bool, + default=False, + help="Run performance test only") + + args = parser.parse_args() + + return args + +def main(): + args = parse_args() + + batch_size = args.batchsize + + # create iluvatar target & device + target = tvm.target.iluvatar(model="MR", options="-libs=cudnn,cublas,ixinfer") + device = tvm.device(target.kind.name, 0) + + # load engine + lib = tvm.runtime.load_module(args.engine) + + # create runtime from engine + module = tvm.contrib.graph_executor.GraphModule(lib["default"](device)) + + # just run perf test + if args.perf_only: + ftimer = module.module.time_evaluator("run", device, number=100, repeat=1) + prof_res = np.array(ftimer().results) * 1000 + fps = batch_size * 1000 / np.mean(prof_res) + print(f"\n* Mean inference time: {np.mean(prof_res):.3f} ms, Mean fps: {fps:.3f}") + else: + root_path = args.datasets + val_path = os.path.join(root_path, 'val2017.txt') + + overrides = {} + overrides['mode'] = 'val' + + cfg_args = get_cfg(cfg=DEFAULT_CFG, overrides=overrides) + + cfg_args.batch = args.batchsize + + cfg_args.data = { + 'path': Path(root_path), + 'val': val_path, + 'names': + { + 0: 'person', 1: 'bicycle', 2: 'car', 3: 'motorcycle', 4: 'airplane', 5: 'bus', + 6: 'train', 7: 'truck', 8: 'boat', 9: 'traffic light', 10: 'fire hydrant', + 11: 'stop sign', 12: 'parking meter', 13: 'bench', 14: 'bird', 15: 'cat', + 16: 'dog', 17: 'horse', 18: 'sheep', 19: 'cow', 20: 'elephant', 21: 'bear', + 22: 'zebra', 23: 'giraffe', 24: 'backpack', 25: 'umbrella', 26: 'handbag', + 27: 'tie', 28: 'suitcase', 29: 'frisbee', 30: 'skis', 31: 'snowboard', + 32: 'sports ball', 33: 'kite', 34: 'baseball bat', 35: 'baseball glove', + 36: 'skateboard', 37: 'surfboard', 38: 'tennis racket', 39: 'bottle', + 40: 'wine glass', 41: 'cup', 42: 'fork', 43: 'knife', 44: 'spoon', 45: 'bowl', + 46: 'banana', 47: 'apple', 48: 'sandwich', 49: 'orange', 50: 'broccoli', + 51: 'carrot', 52: 'hot dog', 53: 'pizza', 54: 'donut', 55: 'cake', 56: 'chair', + 57: 'couch', 58: 'potted plant', 59: 'bed', 60: 'dining table', 61: 'toilet', + 62: 'tv', 63: 'laptop', 64: 'mouse', 65: 'remote', 66: 'keyboard', 67: 'cell phone', + 68: 'microwave', 69: 'oven', 70: 'toaster', 71: 'sink', 72: 'refrigerator', 73: 'book', + 74: 'clock', 75: 'vase', 76: 'scissors', 77: 'teddy bear', 78: 'hair drier', 79: 'toothbrush' + }, + 'nc': 80} + cfg_args.save_json = True + + validator = IGIE_Validator(args=cfg_args, save_dir=Path('.')) + validator.stride = 32 + + stats = validator(module, device) + +if __name__ == "__main__": + main() diff --git a/models/cv/object_detection/yolov13/igie/requirements.txt b/models/cv/object_detection/yolov13/igie/requirements.txt new file mode 100644 index 00000000..355ab489 --- /dev/null +++ b/models/cv/object_detection/yolov13/igie/requirements.txt @@ -0,0 +1,3 @@ +tqdm +onnx==1.13.0 +huggingface_hub \ No newline at end of file diff --git a/models/cv/object_detection/yolov13/igie/scripts/infer_yolov13_fp16_accuracy.sh b/models/cv/object_detection/yolov13/igie/scripts/infer_yolov13_fp16_accuracy.sh new file mode 100644 index 00000000..cefdf94b --- /dev/null +++ b/models/cv/object_detection/yolov13/igie/scripts/infer_yolov13_fp16_accuracy.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Copyright (c) 2025, 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. + +batchsize=32 +model_path="yolov13n.onnx" +datasets_path=${DATASETS_DIR} + +# build engine +python3 build_engine.py \ + --model_path ${model_path} \ + --input images:${batchsize},3,640,640 \ + --precision fp16 \ + --engine_path yolov13n_bs_${batchsize}_fp16.so + + +# inference +python3 inference.py \ + --engine yolov13n_bs_${batchsize}_fp16.so \ + --batchsize ${batchsize} \ + --input_name images \ + --datasets ${datasets_path} \ No newline at end of file diff --git a/models/cv/object_detection/yolov13/igie/scripts/infer_yolov13_fp16_performance.sh b/models/cv/object_detection/yolov13/igie/scripts/infer_yolov13_fp16_performance.sh new file mode 100644 index 00000000..867d432f --- /dev/null +++ b/models/cv/object_detection/yolov13/igie/scripts/infer_yolov13_fp16_performance.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# Copyright (c) 2025, 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. + +batchsize=32 +model_path="yolov13n.onnx" +datasets_path=${DATASETS_DIR} + +# build engine +python3 build_engine.py \ + --model_path ${model_path} \ + --input images:${batchsize},3,640,640 \ + --precision fp16 \ + --engine_path yolov13n_bs_${batchsize}_fp16.so + + +# inference +python3 inference.py \ + --engine yolov13n_bs_${batchsize}_fp16.so \ + --batchsize ${batchsize} \ + --input_name images \ + --datasets ${datasets_path} \ + --perf_only True \ No newline at end of file diff --git a/models/cv/object_detection/yolov13/igie/validator.py b/models/cv/object_detection/yolov13/igie/validator.py new file mode 100644 index 00000000..113693da --- /dev/null +++ b/models/cv/object_detection/yolov13/igie/validator.py @@ -0,0 +1,89 @@ +# Copyright (c) 2025, 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 os +import tvm +import json +import torch +import numpy as np + +from tqdm import tqdm + +from ultralytics.models.yolo.detect import DetectionValidator +from ultralytics.data.utils import check_det_dataset +from ultralytics.utils.metrics import ConfusionMatrix +from ultralytics.data.converter import coco80_to_coco91_class + +class IGIE_Validator(DetectionValidator): + def __call__(self, engine, device): + self.data = self.args.data + self.dataloader = self.get_dataloader(self.data.get(self.args.split), self.args.batch) + self.init_metrics() + + self.stats = {'tp': [], 'conf': [], 'pred_cls': [], 'target_cls': [], 'target_img': []} + + # wram up + for _ in range(3): + engine.run() + + for batch in tqdm(self.dataloader): + batch = self.preprocess(batch) + + imgs = batch['img'] + pad_batch = len(imgs) != self.args.batch + if pad_batch: + origin_size = len(imgs) + imgs = np.resize(imgs, (self.args.batch, *imgs.shape[1:])) + + engine.set_input(0, tvm.nd.array(imgs, device)) + + engine.run() + + outputs = engine.get_output(0).asnumpy() + + if pad_batch: + outputs = outputs[:origin_size] + + outputs = torch.from_numpy(outputs) + + preds = self.postprocess([outputs]) + + self.update_metrics(preds, batch) + + stats = self.get_stats() + + if self.args.save_json and self.jdict: + with open(str(self.save_dir / 'predictions.json'), 'w') as f: + print(f'Saving {f.name} ...') + json.dump(self.jdict, f) # flatten and save + + stats = self.eval_json(stats) + + return stats + + def init_metrics(self): + """Initialize evaluation metrics for YOLO.""" + val = self.data.get(self.args.split, '') # validation path + self.is_coco = isinstance(val, str) and 'coco' in val and val.endswith(f'{os.sep}val2017.txt') # is COCO + self.class_map = coco80_to_coco91_class() if self.is_coco else list(range(1000)) + self.args.save_json |= self.is_coco and not self.training # run on final val if training COCO + self.names = self.data['names'] + self.nc = len(self.names) + self.metrics.names = self.names + self.confusion_matrix = ConfusionMatrix(nc=80) + self.seen = 0 + self.jdict = [] + self.stats = [] + -- Gitee From a2452e376c16d748f43a038a0ac92d6d7f90aaba Mon Sep 17 00:00:00 2001 From: YoungPeng Date: Mon, 14 Jul 2025 16:01:01 +0800 Subject: [PATCH 12/15] Update: cls model SDK version. --- models/cv/classification/efficientnet_b6/igie/README.md | 2 +- models/cv/classification/mnasnet1_3/igie/README.md | 2 +- models/cv/classification/regnet_x_32gf/igie/README.md | 2 +- models/cv/classification/regnet_x_400mf/igie/README.md | 2 +- models/cv/classification/regnet_y_32gf/igie/README.md | 2 +- models/cv/classification/regnet_y_3_2gf/igie/README.md | 2 +- models/cv/classification/regnet_y_400mf/igie/README.md | 2 +- models/cv/classification/vgg13/igie/README.md | 2 +- models/cv/classification/vgg13_bn/igie/README.md | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/models/cv/classification/efficientnet_b6/igie/README.md b/models/cv/classification/efficientnet_b6/igie/README.md index 5d4a0045..6c61c77a 100644 --- a/models/cv/classification/efficientnet_b6/igie/README.md +++ b/models/cv/classification/efficientnet_b6/igie/README.md @@ -8,7 +8,7 @@ EfficientNet B6 is a high-performance convolutional neural network model develop | GPU | [IXUCA SDK](https://gitee.com/deep-spark/deepspark#%E5%A4%A9%E6%95%B0%E6%99%BA%E7%AE%97%E8%BD%AF%E4%BB%B6%E6%A0%88-ixuca) | Release | |--------|-----------|---------| -| MR-V100| 4.2.0 | 25.06 | +| MR-V100| 4.3.0 | 25.09 | ## Model Preparation diff --git a/models/cv/classification/mnasnet1_3/igie/README.md b/models/cv/classification/mnasnet1_3/igie/README.md index c84be8ee..bdf2502c 100644 --- a/models/cv/classification/mnasnet1_3/igie/README.md +++ b/models/cv/classification/mnasnet1_3/igie/README.md @@ -8,7 +8,7 @@ MNASNet1_3 is a lightweight deep learning model optimized through neural archite | GPU | [IXUCA SDK](https://gitee.com/deep-spark/deepspark#%E5%A4%A9%E6%95%B0%E6%99%BA%E7%AE%97%E8%BD%AF%E4%BB%B6%E6%A0%88-ixuca) | Release | | :----: | :----: | :----: | -| MR-V100 | 4.2.0 | 25.03 | +| MR-V100 | 4.3.0 | 25.09 | ## Model Preparation diff --git a/models/cv/classification/regnet_x_32gf/igie/README.md b/models/cv/classification/regnet_x_32gf/igie/README.md index 616c7c84..bda1f6a1 100644 --- a/models/cv/classification/regnet_x_32gf/igie/README.md +++ b/models/cv/classification/regnet_x_32gf/igie/README.md @@ -8,7 +8,7 @@ RegNet_x_32gf is an efficient convolutional neural network model from Facebook A | GPU | [IXUCA SDK](https://gitee.com/deep-spark/deepspark#%E5%A4%A9%E6%95%B0%E6%99%BA%E7%AE%97%E8%BD%AF%E4%BB%B6%E6%A0%88-ixuca) | Release | | :----: | :----: | :----: | -| MR-V100 | 4.2.0 | 25.06 | +| MR-V100 | 4.3.0 | 25.09 | ## Model Preparation diff --git a/models/cv/classification/regnet_x_400mf/igie/README.md b/models/cv/classification/regnet_x_400mf/igie/README.md index f1dee331..0963ee6d 100644 --- a/models/cv/classification/regnet_x_400mf/igie/README.md +++ b/models/cv/classification/regnet_x_400mf/igie/README.md @@ -8,7 +8,7 @@ RegNet_x_400mf is a lightweight deep learning model designed with a regularized | GPU | [IXUCA SDK](https://gitee.com/deep-spark/deepspark#%E5%A4%A9%E6%95%B0%E6%99%BA%E7%AE%97%E8%BD%AF%E4%BB%B6%E6%A0%88-ixuca) | Release | | :----: | :----: | :----: | -| MR-V100 | 4.2.0 | 25.06 | +| MR-V100 | 4.3.0 | 25.09 | ## Model Preparation diff --git a/models/cv/classification/regnet_y_32gf/igie/README.md b/models/cv/classification/regnet_y_32gf/igie/README.md index 3b04c93d..0a236b46 100644 --- a/models/cv/classification/regnet_y_32gf/igie/README.md +++ b/models/cv/classification/regnet_y_32gf/igie/README.md @@ -8,7 +8,7 @@ RegNet_y_32gf is a variant from Facebook AI's RegNet series, belonging to the Re | GPU | [IXUCA SDK](https://gitee.com/deep-spark/deepspark#%E5%A4%A9%E6%95%B0%E6%99%BA%E7%AE%97%E8%BD%AF%E4%BB%B6%E6%A0%88-ixuca) | Release | | :----: | :----: | :----: | -| MR-V100 | 4.2.0 | 25.06 | +| MR-V100 | 4.3.0 | 25.09 | ## Model Preparation diff --git a/models/cv/classification/regnet_y_3_2gf/igie/README.md b/models/cv/classification/regnet_y_3_2gf/igie/README.md index 4aea910a..ce6fde6a 100644 --- a/models/cv/classification/regnet_y_3_2gf/igie/README.md +++ b/models/cv/classification/regnet_y_3_2gf/igie/README.md @@ -8,7 +8,7 @@ RegNet_y_3_2gf is a lightweight deep learning model designed with a regularized | GPU | [IXUCA SDK](https://gitee.com/deep-spark/deepspark#%E5%A4%A9%E6%95%B0%E6%99%BA%E7%AE%97%E8%BD%AF%E4%BB%B6%E6%A0%88-ixuca) | Release | | :----: | :----: | :----: | -| MR-V100 | 4.2.0 | 25.06 | +| MR-V100 | 4.3.0 | 25.09 | ## Model Preparation diff --git a/models/cv/classification/regnet_y_400mf/igie/README.md b/models/cv/classification/regnet_y_400mf/igie/README.md index 0b993462..02bf9c2e 100644 --- a/models/cv/classification/regnet_y_400mf/igie/README.md +++ b/models/cv/classification/regnet_y_400mf/igie/README.md @@ -8,7 +8,7 @@ RegNet_y_400mf is a lightweight deep learning model designed with a regularized | GPU | [IXUCA SDK](https://gitee.com/deep-spark/deepspark#%E5%A4%A9%E6%95%B0%E6%99%BA%E7%AE%97%E8%BD%AF%E4%BB%B6%E6%A0%88-ixuca) | Release | | :----: | :----: | :----: | -| MR-V100 | 4.2.0 | 25.06 | +| MR-V100 | 4.3.0 | 25.09 | ## Model Preparation diff --git a/models/cv/classification/vgg13/igie/README.md b/models/cv/classification/vgg13/igie/README.md index fb0916eb..700e0aef 100644 --- a/models/cv/classification/vgg13/igie/README.md +++ b/models/cv/classification/vgg13/igie/README.md @@ -8,7 +8,7 @@ VGG13 is a classic deep convolutional neural network model consisting of 13 conv | GPU | [IXUCA SDK](https://gitee.com/deep-spark/deepspark#%E5%A4%A9%E6%95%B0%E6%99%BA%E7%AE%97%E8%BD%AF%E4%BB%B6%E6%A0%88-ixuca) | Release | | :----: | :----: | :----: | -| MR-V100 | 4.2.0 | 25.03 | +| MR-V100 | 4.3.0 | 25.09 | ## Model Preparation diff --git a/models/cv/classification/vgg13_bn/igie/README.md b/models/cv/classification/vgg13_bn/igie/README.md index b1f07611..81af36df 100644 --- a/models/cv/classification/vgg13_bn/igie/README.md +++ b/models/cv/classification/vgg13_bn/igie/README.md @@ -8,7 +8,7 @@ VGG13_BN is an improved version of VGG13, utilizing 3×3 small convolution kerne | GPU | [IXUCA SDK](https://gitee.com/deep-spark/deepspark#%E5%A4%A9%E6%95%B0%E6%99%BA%E7%AE%97%E8%BD%AF%E4%BB%B6%E6%A0%88-ixuca) | Release | | :----: | :----: | :----: | -| MR-V100 | 4.2.0 | 25.03 | +| MR-V100 | 4.3.0 | 25.09 | ## Model Preparation -- Gitee From 7261ccac8bb66df56dc79133e776d8bfdaea4cc2 Mon Sep 17 00:00:00 2001 From: YoungPeng Date: Mon, 14 Jul 2025 19:49:04 +0800 Subject: [PATCH 13/15] Add: ssd inference script. --- models/cv/object_detection/ssd/igie/README.md | 66 +++ .../object_detection/ssd/igie/build_engine.py | 73 ++++ .../object_detection/ssd/igie/ci/prepare.sh | 34 ++ .../ssd/igie/deploy_default.py | 41 ++ models/cv/object_detection/ssd/igie/export.py | 72 ++++ .../cv/object_detection/ssd/igie/inference.py | 158 +++++++ .../ssd/igie/requirements.txt | 6 + .../igie/scripts/infer_ssd_fp16_accuracy.sh | 35 ++ .../scripts/infer_ssd_fp16_performance.sh | 36 ++ .../object_detection/ssd/igie/ssd300_coco.py | 392 ++++++++++++++++++ 10 files changed, 913 insertions(+) create mode 100644 models/cv/object_detection/ssd/igie/README.md create mode 100644 models/cv/object_detection/ssd/igie/build_engine.py create mode 100644 models/cv/object_detection/ssd/igie/ci/prepare.sh create mode 100644 models/cv/object_detection/ssd/igie/deploy_default.py create mode 100644 models/cv/object_detection/ssd/igie/export.py create mode 100644 models/cv/object_detection/ssd/igie/inference.py create mode 100644 models/cv/object_detection/ssd/igie/requirements.txt create mode 100644 models/cv/object_detection/ssd/igie/scripts/infer_ssd_fp16_accuracy.sh create mode 100644 models/cv/object_detection/ssd/igie/scripts/infer_ssd_fp16_performance.sh create mode 100644 models/cv/object_detection/ssd/igie/ssd300_coco.py diff --git a/models/cv/object_detection/ssd/igie/README.md b/models/cv/object_detection/ssd/igie/README.md new file mode 100644 index 00000000..38806444 --- /dev/null +++ b/models/cv/object_detection/ssd/igie/README.md @@ -0,0 +1,66 @@ +# SSD (IGIE) + +## Model Description + +SSD is a single convolutional neural network-based object detection model that utilizes multi-scale feature maps and default box designs to perform classification and regression simultaneously. With an efficient structure, it achieves real-time object detection and is suitable for handling objects of various sizes. + +## Supported Environments + +| GPU | [IXUCA SDK](https://gitee.com/deep-spark/deepspark#%E5%A4%A9%E6%95%B0%E6%99%BA%E7%AE%97%E8%BD%AF%E4%BB%B6%E6%A0%88-ixuca) | Release | +| :----: | :----: | :----: | +| MR-V100 | 4.3.0 | 25.09 | + +## Model Preparation + +### Prepare Resources + +Pretrained model: + +Dataset: to download the validation dataset. + +### Install Dependencies + +```bash +# Install libGL +## CentOS +yum install -y mesa-libGL +## Ubuntu +apt install -y libgl1-mesa-glx + +pip3 install -r requirements.txt +``` + +### Model Conversion + +```bash +# export onnx model +python3 export.py --weight ssd300_coco_20210803_015428-d231a06e.pth --cfg ssd300_coco.py --output ssd.onnx + +# use onnxsim optimize onnx model +onnxsim ssd.onnx ssd_opt.onnx +``` + +## Model Inference + +```bash +export DATASETS_DIR=/Path/to/coco/ +``` + +### FP16 + +```bash +# Accuracy +bash scripts/infer_ssd_fp16_accuracy.sh +# Performance +bash scripts/infer_ssd_fp16_performance.sh +``` + +## Model Results + +| Model | BatchSize | Precision | FPS | IOU@0.5 | IOU@0.5:0.95 | +| :----:| :-------: | :-------: | :----: | :-----: | :----------: | +| SSD | 32 | FP16 | 783.83 | 0.436 | 0.255 | + +## References + +- [mmdetection](https://github.com/open-mmlab/mmdetection.git) diff --git a/models/cv/object_detection/ssd/igie/build_engine.py b/models/cv/object_detection/ssd/igie/build_engine.py new file mode 100644 index 00000000..54aa8847 --- /dev/null +++ b/models/cv/object_detection/ssd/igie/build_engine.py @@ -0,0 +1,73 @@ +# Copyright (c) 2025, 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 tvm +import argparse +from tvm import relay +from tvm.relay.import_model import import_model_to_igie + +def parse_args(): + parser = argparse.ArgumentParser() + + parser.add_argument("--model_path", + type=str, + required=True, + help="original model path.") + + parser.add_argument("--engine_path", + type=str, + required=True, + help="igie export engine path.") + + parser.add_argument("--input", + type=str, + required=True, + help=""" + input info of the model, format should be: + input_name:input_shape + eg: --input input:1,3,224,224. + """) + + parser.add_argument("--precision", + type=str, + choices=["fp32", "fp16", "int8"], + required=True, + help="model inference precision.") + + args = parser.parse_args() + + return args + +def main(): + args = parse_args() + + # get input valueinfo + input_name, input_shape = args.input.split(":") + shape = tuple([int(s) for s in input_shape.split(",")]) + input_dict = {input_name: shape} + + target = tvm.target.iluvatar(model="MR", options="-libs=cudnn,cublas,ixinfer") + + mod, params = import_model_to_igie(args.model_path, input_dict, backend="igie") + + # build engine + lib = tvm.relay.build(mod, target=target, params=params, precision=args.precision) + + # export engine + lib.export_library(args.engine_path) + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/models/cv/object_detection/ssd/igie/ci/prepare.sh b/models/cv/object_detection/ssd/igie/ci/prepare.sh new file mode 100644 index 00000000..b2659a46 --- /dev/null +++ b/models/cv/object_detection/ssd/igie/ci/prepare.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# Copyright (c) 2025, 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. + +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 + +# export onnx model +python3 export.py --weight ssd300_coco_20210803_015428-d231a06e.pth --cfg ssd300_coco.py --output ssd.onnx + +# use onnxsim optimize onnx model +onnxsim ssd.onnx ssd_opt.onnx \ No newline at end of file diff --git a/models/cv/object_detection/ssd/igie/deploy_default.py b/models/cv/object_detection/ssd/igie/deploy_default.py new file mode 100644 index 00000000..e6c4d46a --- /dev/null +++ b/models/cv/object_detection/ssd/igie/deploy_default.py @@ -0,0 +1,41 @@ +# Copyright (c) 2025, 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. + +onnx_config = dict( + type='onnx', + export_params=True, + keep_initializers_as_inputs=False, + opset_version=11, + save_file='end2end.onnx', + input_names=['input'], + output_names=['output'], + input_shape=None, + optimize=True) + +codebase_config = dict( + type='mmdet', + task='ObjectDetection', + model_type='end2end', + post_processing=dict( + score_threshold=0.05, + confidence_threshold=0.005, + iou_threshold=0.5, + max_output_boxes_per_class=200, + pre_top_k=5000, + keep_top_k=100, + background_label_id=-1, + )) + +backend_config = dict(type='onnxruntime') \ No newline at end of file diff --git a/models/cv/object_detection/ssd/igie/export.py b/models/cv/object_detection/ssd/igie/export.py new file mode 100644 index 00000000..9235cbd5 --- /dev/null +++ b/models/cv/object_detection/ssd/igie/export.py @@ -0,0 +1,72 @@ +# Copyright (c) 2025, 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 torch +from mmdeploy.utils import load_config +from mmdeploy.apis import build_task_processor + +def parse_args(): + parser = argparse.ArgumentParser() + + parser.add_argument("--weight", + type=str, + required=True, + help="pytorch model weight.") + + parser.add_argument("--cfg", + type=str, + required=True, + help="model config file.") + + parser.add_argument("--output", + type=str, + required=True, + help="export onnx model path.") + + args = parser.parse_args() + return args + +def main(): + args = parse_args() + + deploy_cfg = 'deploy_default.py' + model_cfg = args.cfg + model_checkpoint = args.weight + + deploy_cfg, model_cfg = load_config(deploy_cfg, model_cfg) + + task_processor = build_task_processor(model_cfg, deploy_cfg, device='cpu') + + model = task_processor.build_pytorch_model(model_checkpoint) + + input_names = ['input'] + dynamic_axes = {'input': {0: '-1'}} + dummy_input = torch.randn(1, 3, 300, 300) + + torch.onnx.export( + model, + dummy_input, + args.output, + input_names = input_names, + dynamic_axes = dynamic_axes, + opset_version=13 + ) + + print("Export onnx model successfully! ") + +if __name__ == '__main__': + main() diff --git a/models/cv/object_detection/ssd/igie/inference.py b/models/cv/object_detection/ssd/igie/inference.py new file mode 100644 index 00000000..fde452d0 --- /dev/null +++ b/models/cv/object_detection/ssd/igie/inference.py @@ -0,0 +1,158 @@ +# Copyright (c) 2025, 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 os +import argparse +import tvm +import torch +import numpy as np +from tvm import relay +from tqdm import tqdm +from mmdet.registry import RUNNERS +from mmengine.config import Config + +def parse_args(): + parser = argparse.ArgumentParser() + + parser.add_argument("--engine", + type=str, + required=True, + help="igie engine path.") + + parser.add_argument("--batchsize", + type=int, + required=True, + help="inference batch size.") + + parser.add_argument("--datasets", + type=str, + required=True, + help="datasets path.") + + parser.add_argument("--input_name", + type=str, + required=True, + help="input name of the model.") + + parser.add_argument("--warmup", + type=int, + default=3, + help="number of warmup before test.") + + parser.add_argument("--acc_target", + type=float, + default=None, + help="Model inference Accuracy target.") + + parser.add_argument("--fps_target", + type=float, + default=None, + help="Model inference FPS target.") + + parser.add_argument("--perf_only", + type=bool, + default=False, + help="Run performance test only") + + args = parser.parse_args() + + return args + +def main(): + args = parse_args() + + batch_size = args.batchsize + + # create iluvatar target & device + target = tvm.target.iluvatar(model="MR", options="-libs=cudnn,cublas,ixinfer") + device = tvm.device(target.kind.name, 0) + + # load engine + lib = tvm.runtime.load_module(args.engine) + + # create runtime from engine + module = tvm.contrib.graph_executor.GraphModule(lib["default"](device)) + + # just run perf test + if args.perf_only: + ftimer = module.module.time_evaluator("run", device, number=100, repeat=1) + prof_res = np.array(ftimer().results) * 1000 + fps = batch_size * 1000 / np.mean(prof_res) + print(f"\n* Mean inference time: {np.mean(prof_res):.3f} ms, Mean fps: {fps:.3f}") + else: + # warm up + for _ in range(args.warmup): + module.run() + + # runner config + cfg = Config.fromfile("ssd300_coco.py") + + cfg.work_dir = "./workspace" + cfg['test_dataloader']['batch_size'] = batch_size + cfg['test_dataloader']['dataset']['data_root'] = args.datasets + cfg['test_dataloader']['dataset']['data_prefix']['img'] = 'images/val2017/' + cfg['test_evaluator']['ann_file'] = os.path.join(args.datasets, 'annotations/instances_val2017.json') + cfg['log_level'] = 'ERROR' + + # build runner + runner = RUNNERS.build(cfg) + setattr(runner.model.bbox_head, 'loss_cls', None) + + for data in tqdm(runner.test_dataloader): + cls_score = [] + box_reg = [] + + input_data = runner.model.data_preprocessor(data, False) + image = input_data['inputs'].cpu() + pad_batch = len(image) != batch_size + + if pad_batch: + origin_size = len(image) + image = np.resize(image, (batch_size, *image.shape[1:])) + + module.set_input("input", tvm.nd.array(image, device)) + + module.run() + + for i in range(module.get_num_outputs()): + output = module.get_output(i).asnumpy() + + if pad_batch: + output = output[:origin_size] + + output = torch.from_numpy(output) + + if i < module.get_num_outputs() / 2: + cls_score.append(output) + else: + box_reg.append(output) + + batch_img_metas = [ + data_samples.metainfo for data_samples in data['data_samples'] + ] + + preds = runner.model.bbox_head.predict_by_feat( + cls_score, box_reg, batch_img_metas=batch_img_metas, rescale=True + ) + + batch_data_samples = runner.model.add_pred_to_datasample(input_data['data_samples'], preds) + + runner.test_evaluator.process(data_samples=batch_data_samples, data_batch=data) + + metrics = runner.test_evaluator.evaluate(len(runner.test_dataloader.dataset)) + + +if __name__ == "__main__": + main() diff --git a/models/cv/object_detection/ssd/igie/requirements.txt b/models/cv/object_detection/ssd/igie/requirements.txt new file mode 100644 index 00000000..b6b3fff4 --- /dev/null +++ b/models/cv/object_detection/ssd/igie/requirements.txt @@ -0,0 +1,6 @@ +onnx +tqdm +onnxsim +mmdet==3.3.0 +mmdeploy==1.3.1 +mmengine==0.10.4 diff --git a/models/cv/object_detection/ssd/igie/scripts/infer_ssd_fp16_accuracy.sh b/models/cv/object_detection/ssd/igie/scripts/infer_ssd_fp16_accuracy.sh new file mode 100644 index 00000000..53390708 --- /dev/null +++ b/models/cv/object_detection/ssd/igie/scripts/infer_ssd_fp16_accuracy.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Copyright (c) 2025, 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. + +batchsize=32 +model_path="ssd_opt.onnx" +datasets_path=${DATASETS_DIR} + +# build engine +python3 build_engine.py \ + --model_path ${model_path} \ + --input input:${batchsize},3,300,300 \ + --precision fp16 \ + --engine_path ssd_opt_bs_${batchsize}_fp16.so + + +# inference +python3 inference.py \ + --engine ssd_opt_bs_${batchsize}_fp16.so \ + --batchsize ${batchsize} \ + --input_name input \ + --datasets ${datasets_path} diff --git a/models/cv/object_detection/ssd/igie/scripts/infer_ssd_fp16_performance.sh b/models/cv/object_detection/ssd/igie/scripts/infer_ssd_fp16_performance.sh new file mode 100644 index 00000000..1b9313da --- /dev/null +++ b/models/cv/object_detection/ssd/igie/scripts/infer_ssd_fp16_performance.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# Copyright (c) 2025, 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. + +batchsize=32 +model_path="ssd_opt.onnx" +datasets_path=${DATASETS_DIR} + +# build engine +python3 build_engine.py \ + --model_path ${model_path} \ + --input input:${batchsize},3,300,300 \ + --precision fp16 \ + --engine_path ssd_opt_bs_${batchsize}_fp16.so + + +# inference +python3 inference.py \ + --engine ssd_opt_bs_${batchsize}_fp16.so \ + --batchsize ${batchsize} \ + --input_name input \ + --datasets ${datasets_path} \ + --perf_only True diff --git a/models/cv/object_detection/ssd/igie/ssd300_coco.py b/models/cv/object_detection/ssd/igie/ssd300_coco.py new file mode 100644 index 00000000..c0226b67 --- /dev/null +++ b/models/cv/object_detection/ssd/igie/ssd300_coco.py @@ -0,0 +1,392 @@ +auto_scale_lr = dict(base_batch_size=64, enable=False) +backend_args = None +cudnn_benchmark = True +custom_hooks = [ + dict(type='NumClassCheckHook'), + dict(interval=50, priority='VERY_LOW', type='CheckInvalidLossHook'), +] +data_root = 'data/coco/' +dataset_type = 'CocoDataset' +default_hooks = dict( + checkpoint=dict(interval=1, type='CheckpointHook'), + logger=dict(interval=50, type='LoggerHook'), + param_scheduler=dict(type='ParamSchedulerHook'), + sampler_seed=dict(type='DistSamplerSeedHook'), + timer=dict(type='IterTimerHook'), + visualization=dict(type='DetVisualizationHook')) +default_scope = 'mmdet' +env_cfg = dict( + cudnn_benchmark=False, + dist_cfg=dict(backend='nccl'), + mp_cfg=dict(mp_start_method='fork', opencv_num_threads=0)) +input_size = 300 +load_from = None +log_level = 'ERROR' +log_processor = dict(by_epoch=True, type='LogProcessor', window_size=50) +model = dict( + backbone=dict( + ceil_mode=True, + depth=16, + init_cfg=dict( + checkpoint='open-mmlab://vgg16_caffe', type='Pretrained'), + out_feature_indices=( + 22, + 34, + ), + out_indices=( + 3, + 4, + ), + type='SSDVGG', + with_last_pool=False), + bbox_head=dict( + anchor_generator=dict( + basesize_ratio_range=( + 0.15, + 0.9, + ), + input_size=300, + ratios=[ + [ + 2, + ], + [ + 2, + 3, + ], + [ + 2, + 3, + ], + [ + 2, + 3, + ], + [ + 2, + ], + [ + 2, + ], + ], + scale_major=False, + strides=[ + 8, + 16, + 32, + 64, + 100, + 300, + ], + type='SSDAnchorGenerator'), + bbox_coder=dict( + target_means=[ + 0.0, + 0.0, + 0.0, + 0.0, + ], + target_stds=[ + 0.1, + 0.1, + 0.2, + 0.2, + ], + type='DeltaXYWHBBoxCoder'), + in_channels=( + 512, + 1024, + 512, + 256, + 256, + 256, + ), + num_classes=80, + type='SSDHead'), + data_preprocessor=dict( + bgr_to_rgb=True, + mean=[ + 123.675, + 116.28, + 103.53, + ], + pad_size_divisor=1, + std=[ + 1, + 1, + 1, + ], + type='DetDataPreprocessor'), + neck=dict( + in_channels=( + 512, + 1024, + ), + l2_norm_scale=20, + level_paddings=( + 1, + 1, + 0, + 0, + ), + level_strides=( + 2, + 2, + 1, + 1, + ), + out_channels=( + 512, + 1024, + 512, + 256, + 256, + 256, + ), + type='SSDNeck'), + test_cfg=dict( + max_per_img=200, + min_bbox_size=0, + nms=dict(iou_threshold=0.45, type='nms'), + nms_pre=1000, + score_thr=0.02), + train_cfg=dict( + allowed_border=-1, + assigner=dict( + gt_max_assign_all=False, + ignore_iof_thr=-1, + min_pos_iou=0.0, + neg_iou_thr=0.5, + pos_iou_thr=0.5, + type='MaxIoUAssigner'), + debug=False, + neg_pos_ratio=3, + pos_weight=-1, + sampler=dict(type='PseudoSampler'), + smoothl1_beta=1.0), + type='SingleStageDetector') +optim_wrapper = dict( + optimizer=dict(lr=0.002, momentum=0.9, type='SGD', weight_decay=0.0005), + type='OptimWrapper') +param_scheduler = [ + dict( + begin=0, by_epoch=False, end=500, start_factor=0.001, type='LinearLR'), + dict( + begin=0, + by_epoch=True, + end=24, + gamma=0.1, + milestones=[ + 16, + 22, + ], + type='MultiStepLR'), +] +resume = False +test_cfg = dict(type='TestLoop') +test_dataloader = dict( + batch_size=32, + dataset=dict( + ann_file='annotations/instances_val2017.json', + backend_args=None, + data_prefix=dict(img='images/val2017/'), + data_root='data/datasets/coco/', + pipeline=[ + dict(backend_args=None, type='LoadImageFromFile'), + dict(keep_ratio=False, scale=( + 300, + 300, + ), type='Resize'), + dict(type='LoadAnnotations', with_bbox=True), + dict( + meta_keys=( + 'img_id', + 'img_path', + 'ori_shape', + 'img_shape', + 'scale_factor', + ), + type='PackDetInputs'), + ], + test_mode=True, + type='CocoDataset'), + drop_last=False, + num_workers=2, + persistent_workers=True, + sampler=dict(shuffle=False, type='DefaultSampler')) +test_evaluator = dict( + ann_file= + 'data/datasets/coco/annotations/instances_val2017.json', + backend_args=None, + format_only=False, + metric='bbox', + type='CocoMetric') +test_pipeline = [ + dict(backend_args=None, type='LoadImageFromFile'), + dict(keep_ratio=False, scale=( + 300, + 300, + ), type='Resize'), + dict(type='LoadAnnotations', with_bbox=True), + dict( + meta_keys=( + 'img_id', + 'img_path', + 'ori_shape', + 'img_shape', + 'scale_factor', + ), + type='PackDetInputs'), +] +train_cfg = dict(max_epochs=24, type='EpochBasedTrainLoop', val_interval=1) +train_dataloader = dict( + batch_sampler=None, + batch_size=8, + dataset=dict( + dataset=dict( + ann_file='annotations/instances_train2017.json', + backend_args=None, + data_prefix=dict(img='train2017/'), + data_root='data/coco/', + filter_cfg=dict(filter_empty_gt=True, min_size=32), + pipeline=[ + dict(backend_args=None, type='LoadImageFromFile'), + dict(type='LoadAnnotations', with_bbox=True), + dict( + mean=[ + 123.675, + 116.28, + 103.53, + ], + ratio_range=( + 1, + 4, + ), + to_rgb=True, + type='Expand'), + dict( + min_crop_size=0.3, + min_ious=( + 0.1, + 0.3, + 0.5, + 0.7, + 0.9, + ), + type='MinIoURandomCrop'), + dict(keep_ratio=False, scale=( + 300, + 300, + ), type='Resize'), + dict(prob=0.5, type='RandomFlip'), + dict( + brightness_delta=32, + contrast_range=( + 0.5, + 1.5, + ), + hue_delta=18, + saturation_range=( + 0.5, + 1.5, + ), + type='PhotoMetricDistortion'), + dict(type='PackDetInputs'), + ], + type='CocoDataset'), + times=5, + type='RepeatDataset'), + num_workers=2, + persistent_workers=True, + sampler=dict(shuffle=True, type='DefaultSampler')) +train_pipeline = [ + dict(backend_args=None, type='LoadImageFromFile'), + dict(type='LoadAnnotations', with_bbox=True), + dict( + mean=[ + 123.675, + 116.28, + 103.53, + ], + ratio_range=( + 1, + 4, + ), + to_rgb=True, + type='Expand'), + dict( + min_crop_size=0.3, + min_ious=( + 0.1, + 0.3, + 0.5, + 0.7, + 0.9, + ), + type='MinIoURandomCrop'), + dict(keep_ratio=False, scale=( + 300, + 300, + ), type='Resize'), + dict(prob=0.5, type='RandomFlip'), + dict( + brightness_delta=32, + contrast_range=( + 0.5, + 1.5, + ), + hue_delta=18, + saturation_range=( + 0.5, + 1.5, + ), + type='PhotoMetricDistortion'), + dict(type='PackDetInputs'), +] +val_cfg = dict(type='ValLoop') +val_dataloader = dict( + batch_size=8, + dataset=dict( + ann_file='annotations/instances_val2017.json', + backend_args=None, + data_prefix=dict(img='val2017/'), + data_root='data/coco/', + pipeline=[ + dict(backend_args=None, type='LoadImageFromFile'), + dict(keep_ratio=False, scale=( + 300, + 300, + ), type='Resize'), + dict(type='LoadAnnotations', with_bbox=True), + dict( + meta_keys=( + 'img_id', + 'img_path', + 'ori_shape', + 'img_shape', + 'scale_factor', + ), + type='PackDetInputs'), + ], + test_mode=True, + type='CocoDataset'), + drop_last=False, + num_workers=2, + persistent_workers=True, + sampler=dict(shuffle=False, type='DefaultSampler')) +val_evaluator = dict( + ann_file='data/coco/annotations/instances_val2017.json', + backend_args=None, + format_only=False, + metric='bbox', + type='CocoMetric') +vis_backends = [ + dict(type='LocalVisBackend'), +] +visualizer = dict( + name='visualizer', + type='DetLocalVisualizer', + vis_backends=[ + dict(type='LocalVisBackend'), + ]) +work_dir = './workspace' -- Gitee From dddd3dce9a19e9464295df221973b3b109d7a211 Mon Sep 17 00:00:00 2001 From: YoungPeng Date: Tue, 15 Jul 2025 16:55:13 +0800 Subject: [PATCH 14/15] Add: yolof inference script. --- .../cv/object_detection/yolof/igie/README.md | 66 +++++ .../yolof/igie/build_engine.py | 73 +++++ .../object_detection/yolof/igie/ci/prepare.sh | 34 +++ .../yolof/igie/deploy_default.py | 41 +++ .../cv/object_detection/yolof/igie/export.py | 72 +++++ .../object_detection/yolof/igie/inference.py | 158 ++++++++++ .../yolof/igie/requirements.txt | 6 + .../igie/scripts/infer_yolof_fp16_accuracy.sh | 35 +++ .../scripts/infer_yolof_fp16_performance.sh | 36 +++ .../yolof/igie/yolof_r50-c5_8xb8-1x_coco.py | 276 ++++++++++++++++++ 10 files changed, 797 insertions(+) create mode 100644 models/cv/object_detection/yolof/igie/README.md create mode 100644 models/cv/object_detection/yolof/igie/build_engine.py create mode 100644 models/cv/object_detection/yolof/igie/ci/prepare.sh create mode 100644 models/cv/object_detection/yolof/igie/deploy_default.py create mode 100644 models/cv/object_detection/yolof/igie/export.py create mode 100644 models/cv/object_detection/yolof/igie/inference.py create mode 100644 models/cv/object_detection/yolof/igie/requirements.txt create mode 100644 models/cv/object_detection/yolof/igie/scripts/infer_yolof_fp16_accuracy.sh create mode 100644 models/cv/object_detection/yolof/igie/scripts/infer_yolof_fp16_performance.sh create mode 100644 models/cv/object_detection/yolof/igie/yolof_r50-c5_8xb8-1x_coco.py diff --git a/models/cv/object_detection/yolof/igie/README.md b/models/cv/object_detection/yolof/igie/README.md new file mode 100644 index 00000000..d07647ab --- /dev/null +++ b/models/cv/object_detection/yolof/igie/README.md @@ -0,0 +1,66 @@ +# YOLOF (IGIE) + +## Model Description + +YOLOF is a lightweight object detection model that focuses on single-level feature maps for detection and enhances feature representation using dilated convolution modules. With a simple and efficient structure, it is well-suited for real-time object detection tasks. + +## Supported Environments + +| GPU | [IXUCA SDK](https://gitee.com/deep-spark/deepspark#%E5%A4%A9%E6%95%B0%E6%99%BA%E7%AE%97%E8%BD%AF%E4%BB%B6%E6%A0%88-ixuca) | Release | +| :----: | :----: | :----: | +| MR-V100 | 4.3.0 | 25.09 | + +## Model Preparation + +### Prepare Resources + +Pretrained model: + +Dataset: to download the validation dataset. + +### Install Dependencies + +```bash +# Install libGL +## CentOS +yum install -y mesa-libGL +## Ubuntu +apt install -y libgl1-mesa-glx + +pip3 install -r requirements.txt +``` + +### Model Conversion + +```bash +# export onnx model +python3 export.py --weight yolof_r50_c5_8x8_1x_coco_20210425_024427-8e864411.pth --cfg yolof_r50-c5_8xb8-1x_coco.py --output yolof.onnx + +# use onnxsim optimize onnx model +onnxsim yolof.onnx yolof_opt.onnx +``` + +## Model Inference + +```bash +export DATASETS_DIR=/Path/to/coco/ +``` + +### FP16 + +```bash +# Accuracy +bash scripts/infer_yolof_fp16_accuracy.sh +# Performance +bash scripts/infer_yolof_fp16_performance.sh +``` + +## Model Results + +| Model | BatchSize | Precision | FPS | IOU@0.5 | IOU@0.5:0.95 | +| :----:| :-------: | :-------: | :----: | :-----: | :----------: | +| YOLOF | 32 | FP16 | 333.59 | 0.527 | 0.343 | + +## References + +- [mmdetection](https://github.com/open-mmlab/mmdetection.git) diff --git a/models/cv/object_detection/yolof/igie/build_engine.py b/models/cv/object_detection/yolof/igie/build_engine.py new file mode 100644 index 00000000..54aa8847 --- /dev/null +++ b/models/cv/object_detection/yolof/igie/build_engine.py @@ -0,0 +1,73 @@ +# Copyright (c) 2025, 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 tvm +import argparse +from tvm import relay +from tvm.relay.import_model import import_model_to_igie + +def parse_args(): + parser = argparse.ArgumentParser() + + parser.add_argument("--model_path", + type=str, + required=True, + help="original model path.") + + parser.add_argument("--engine_path", + type=str, + required=True, + help="igie export engine path.") + + parser.add_argument("--input", + type=str, + required=True, + help=""" + input info of the model, format should be: + input_name:input_shape + eg: --input input:1,3,224,224. + """) + + parser.add_argument("--precision", + type=str, + choices=["fp32", "fp16", "int8"], + required=True, + help="model inference precision.") + + args = parser.parse_args() + + return args + +def main(): + args = parse_args() + + # get input valueinfo + input_name, input_shape = args.input.split(":") + shape = tuple([int(s) for s in input_shape.split(",")]) + input_dict = {input_name: shape} + + target = tvm.target.iluvatar(model="MR", options="-libs=cudnn,cublas,ixinfer") + + mod, params = import_model_to_igie(args.model_path, input_dict, backend="igie") + + # build engine + lib = tvm.relay.build(mod, target=target, params=params, precision=args.precision) + + # export engine + lib.export_library(args.engine_path) + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/models/cv/object_detection/yolof/igie/ci/prepare.sh b/models/cv/object_detection/yolof/igie/ci/prepare.sh new file mode 100644 index 00000000..88a50dd4 --- /dev/null +++ b/models/cv/object_detection/yolof/igie/ci/prepare.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# Copyright (c) 2025, 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. + +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 + +# export onnx model +python3 export.py --weight yolof_r50_c5_8x8_1x_coco_20210425_024427-8e864411.pth --cfg yolof_r50-c5_8xb8-1x_coco.py --output yolof.onnx + +# use onnxsim optimize onnx model +onnxsim yolof.onnx yolof_opt.onnx \ No newline at end of file diff --git a/models/cv/object_detection/yolof/igie/deploy_default.py b/models/cv/object_detection/yolof/igie/deploy_default.py new file mode 100644 index 00000000..e6c4d46a --- /dev/null +++ b/models/cv/object_detection/yolof/igie/deploy_default.py @@ -0,0 +1,41 @@ +# Copyright (c) 2025, 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. + +onnx_config = dict( + type='onnx', + export_params=True, + keep_initializers_as_inputs=False, + opset_version=11, + save_file='end2end.onnx', + input_names=['input'], + output_names=['output'], + input_shape=None, + optimize=True) + +codebase_config = dict( + type='mmdet', + task='ObjectDetection', + model_type='end2end', + post_processing=dict( + score_threshold=0.05, + confidence_threshold=0.005, + iou_threshold=0.5, + max_output_boxes_per_class=200, + pre_top_k=5000, + keep_top_k=100, + background_label_id=-1, + )) + +backend_config = dict(type='onnxruntime') \ No newline at end of file diff --git a/models/cv/object_detection/yolof/igie/export.py b/models/cv/object_detection/yolof/igie/export.py new file mode 100644 index 00000000..eed56e0c --- /dev/null +++ b/models/cv/object_detection/yolof/igie/export.py @@ -0,0 +1,72 @@ +# Copyright (c) 2025, 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 torch +from mmdeploy.utils import load_config +from mmdeploy.apis import build_task_processor + +def parse_args(): + parser = argparse.ArgumentParser() + + parser.add_argument("--weight", + type=str, + required=True, + help="pytorch model weight.") + + parser.add_argument("--cfg", + type=str, + required=True, + help="model config file.") + + parser.add_argument("--output", + type=str, + required=True, + help="export onnx model path.") + + args = parser.parse_args() + return args + +def main(): + args = parse_args() + + deploy_cfg = 'deploy_default.py' + model_cfg = args.cfg + model_checkpoint = args.weight + + deploy_cfg, model_cfg = load_config(deploy_cfg, model_cfg) + + task_processor = build_task_processor(model_cfg, deploy_cfg, device='cpu') + + model = task_processor.build_pytorch_model(model_checkpoint) + + input_names = ['input'] + dynamic_axes = {'input': {0: '-1'}} + dummy_input = torch.randn(1, 3, 800, 800) + + torch.onnx.export( + model, + dummy_input, + args.output, + input_names = input_names, + dynamic_axes = dynamic_axes, + opset_version=13 + ) + + print("Export onnx model successfully! ") + +if __name__ == '__main__': + main() diff --git a/models/cv/object_detection/yolof/igie/inference.py b/models/cv/object_detection/yolof/igie/inference.py new file mode 100644 index 00000000..2351e0d5 --- /dev/null +++ b/models/cv/object_detection/yolof/igie/inference.py @@ -0,0 +1,158 @@ +# Copyright (c) 2025, 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 os +import argparse +import tvm +import torch +import numpy as np +from tvm import relay +from tqdm import tqdm +from mmdet.registry import RUNNERS +from mmengine.config import Config + +def parse_args(): + parser = argparse.ArgumentParser() + + parser.add_argument("--engine", + type=str, + required=True, + help="igie engine path.") + + parser.add_argument("--batchsize", + type=int, + required=True, + help="inference batch size.") + + parser.add_argument("--datasets", + type=str, + required=True, + help="datasets path.") + + parser.add_argument("--input_name", + type=str, + required=True, + help="input name of the model.") + + parser.add_argument("--warmup", + type=int, + default=3, + help="number of warmup before test.") + + parser.add_argument("--acc_target", + type=float, + default=None, + help="Model inference Accuracy target.") + + parser.add_argument("--fps_target", + type=float, + default=None, + help="Model inference FPS target.") + + parser.add_argument("--perf_only", + type=bool, + default=False, + help="Run performance test only") + + args = parser.parse_args() + + return args + +def main(): + args = parse_args() + + batch_size = args.batchsize + + # create iluvatar target & device + target = tvm.target.iluvatar(model="MR", options="-libs=cudnn,cublas,ixinfer") + device = tvm.device(target.kind.name, 0) + + # load engine + lib = tvm.runtime.load_module(args.engine) + + # create runtime from engine + module = tvm.contrib.graph_executor.GraphModule(lib["default"](device)) + + # just run perf test + if args.perf_only: + ftimer = module.module.time_evaluator("run", device, number=100, repeat=1) + prof_res = np.array(ftimer().results) * 1000 + fps = batch_size * 1000 / np.mean(prof_res) + print(f"\n* Mean inference time: {np.mean(prof_res):.3f} ms, Mean fps: {fps:.3f}") + else: + # warm up + for _ in range(args.warmup): + module.run() + + # runner config + cfg = Config.fromfile("yolof_r50-c5_8xb8-1x_coco.py") + + cfg.work_dir = "./workspace" + cfg['test_dataloader']['batch_size'] = batch_size + cfg['test_dataloader']['dataset']['data_root'] = args.datasets + cfg['test_dataloader']['dataset']['data_prefix']['img'] = 'images/val2017/' + cfg['test_evaluator']['ann_file'] = os.path.join(args.datasets, 'annotations/instances_val2017.json') + cfg['log_level'] = 'ERROR' + + # build runner + runner = RUNNERS.build(cfg) + setattr(runner.model.bbox_head, 'loss_cls', None) + + for data in tqdm(runner.test_dataloader): + cls_score = [] + box_reg = [] + + input_data = runner.model.data_preprocessor(data, False) + image = input_data['inputs'].cpu() + pad_batch = len(image) != batch_size + + if pad_batch: + origin_size = len(image) + image = np.resize(image, (batch_size, *image.shape[1:])) + + module.set_input("input", tvm.nd.array(image, device)) + + module.run() + + for i in range(module.get_num_outputs()): + output = module.get_output(i).asnumpy() + + if pad_batch: + output = output[:origin_size] + + output = torch.from_numpy(output) + + if i < module.get_num_outputs() / 2: + cls_score.append(output) + else: + box_reg.append(output) + + batch_img_metas = [ + data_samples.metainfo for data_samples in data['data_samples'] + ] + + preds = runner.model.bbox_head.predict_by_feat( + cls_score, box_reg, batch_img_metas=batch_img_metas, rescale=True + ) + + batch_data_samples = runner.model.add_pred_to_datasample(input_data['data_samples'], preds) + + runner.test_evaluator.process(data_samples=batch_data_samples, data_batch=data) + + metrics = runner.test_evaluator.evaluate(len(runner.test_dataloader.dataset)) + + +if __name__ == "__main__": + main() diff --git a/models/cv/object_detection/yolof/igie/requirements.txt b/models/cv/object_detection/yolof/igie/requirements.txt new file mode 100644 index 00000000..b6b3fff4 --- /dev/null +++ b/models/cv/object_detection/yolof/igie/requirements.txt @@ -0,0 +1,6 @@ +onnx +tqdm +onnxsim +mmdet==3.3.0 +mmdeploy==1.3.1 +mmengine==0.10.4 diff --git a/models/cv/object_detection/yolof/igie/scripts/infer_yolof_fp16_accuracy.sh b/models/cv/object_detection/yolof/igie/scripts/infer_yolof_fp16_accuracy.sh new file mode 100644 index 00000000..f82dae93 --- /dev/null +++ b/models/cv/object_detection/yolof/igie/scripts/infer_yolof_fp16_accuracy.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Copyright (c) 2025, 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. + +batchsize=32 +model_path="yolof_opt.onnx" +datasets_path=${DATASETS_DIR} + +# build engine +python3 build_engine.py \ + --model_path ${model_path} \ + --input input:${batchsize},3,800,800 \ + --precision fp16 \ + --engine_path yolof_opt_bs_${batchsize}_fp16.so + + +# inference +python3 inference.py \ + --engine yolof_opt_bs_${batchsize}_fp16.so \ + --batchsize ${batchsize} \ + --input_name input \ + --datasets ${datasets_path} diff --git a/models/cv/object_detection/yolof/igie/scripts/infer_yolof_fp16_performance.sh b/models/cv/object_detection/yolof/igie/scripts/infer_yolof_fp16_performance.sh new file mode 100644 index 00000000..db96214c --- /dev/null +++ b/models/cv/object_detection/yolof/igie/scripts/infer_yolof_fp16_performance.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# Copyright (c) 2025, 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. + +batchsize=32 +model_path="yolof_opt.onnx" +datasets_path=${DATASETS_DIR} + +# build engine +python3 build_engine.py \ + --model_path ${model_path} \ + --input input:${batchsize},3,800,800 \ + --precision fp16 \ + --engine_path yolof_opt_bs_${batchsize}_fp16.so + + +# inference +python3 inference.py \ + --engine yolof_opt_bs_${batchsize}_fp16.so \ + --batchsize ${batchsize} \ + --input_name input \ + --datasets ${datasets_path} \ + --perf_only True diff --git a/models/cv/object_detection/yolof/igie/yolof_r50-c5_8xb8-1x_coco.py b/models/cv/object_detection/yolof/igie/yolof_r50-c5_8xb8-1x_coco.py new file mode 100644 index 00000000..47f58c2d --- /dev/null +++ b/models/cv/object_detection/yolof/igie/yolof_r50-c5_8xb8-1x_coco.py @@ -0,0 +1,276 @@ +auto_scale_lr = dict(base_batch_size=64, enable=False) +backend_args = None +data_root = 'data/coco/' +dataset_type = 'CocoDataset' +default_hooks = dict( + checkpoint=dict(interval=1, type='CheckpointHook'), + logger=dict(interval=50, type='LoggerHook'), + param_scheduler=dict(type='ParamSchedulerHook'), + sampler_seed=dict(type='DistSamplerSeedHook'), + timer=dict(type='IterTimerHook'), + visualization=dict(type='DetVisualizationHook')) +default_scope = 'mmdet' +env_cfg = dict( + cudnn_benchmark=False, + dist_cfg=dict(backend='nccl'), + mp_cfg=dict(mp_start_method='fork', opencv_num_threads=0)) +load_from = None +log_level = 'ERROR' +log_processor = dict(by_epoch=True, type='LogProcessor', window_size=50) +model = dict( + backbone=dict( + depth=50, + frozen_stages=1, + init_cfg=dict( + checkpoint='open-mmlab://detectron/resnet50_caffe', + type='Pretrained'), + norm_cfg=dict(requires_grad=False, type='BN'), + norm_eval=True, + num_stages=4, + out_indices=(3, ), + style='caffe', + type='ResNet'), + bbox_head=dict( + anchor_generator=dict( + ratios=[ + 1.0, + ], + scales=[ + 1, + 2, + 4, + 8, + 16, + ], + strides=[ + 32, + ], + type='AnchorGenerator'), + bbox_coder=dict( + add_ctr_clamp=True, + ctr_clamp=32, + target_means=[ + 0.0, + 0.0, + 0.0, + 0.0, + ], + target_stds=[ + 1.0, + 1.0, + 1.0, + 1.0, + ], + type='DeltaXYWHBBoxCoder'), + in_channels=512, + loss_bbox=dict(loss_weight=1.0, type='GIoULoss'), + loss_cls=dict( + alpha=0.25, + gamma=2.0, + loss_weight=1.0, + type='FocalLoss', + use_sigmoid=True), + num_classes=80, + reg_decoded_bbox=True, + type='YOLOFHead'), + data_preprocessor=dict( + bgr_to_rgb=False, + mean=[ + 103.53, + 116.28, + 123.675, + ], + pad_size_divisor=32, + std=[ + 1.0, + 1.0, + 1.0, + ], + type='DetDataPreprocessor'), + neck=dict( + block_dilations=[ + 2, + 4, + 6, + 8, + ], + block_mid_channels=128, + in_channels=2048, + num_residual_blocks=4, + out_channels=512, + type='DilatedEncoder'), + test_cfg=dict( + max_per_img=100, + min_bbox_size=0, + nms=dict(iou_threshold=0.6, type='nms'), + nms_pre=1000, + score_thr=0.05), + train_cfg=dict( + allowed_border=-1, + assigner=dict( + neg_ignore_thr=0.7, pos_ignore_thr=0.15, type='UniformAssigner'), + debug=False, + pos_weight=-1), + type='YOLOF') +optim_wrapper = dict( + optimizer=dict(lr=0.12, momentum=0.9, type='SGD', weight_decay=0.0001), + paramwise_cfg=dict( + custom_keys=dict(backbone=dict(lr_mult=0.3333333333333333)), + norm_decay_mult=0.0), + type='OptimWrapper') +param_scheduler = [ + dict( + begin=0, + by_epoch=False, + end=1500, + start_factor=0.00066667, + type='LinearLR'), + dict( + begin=0, + by_epoch=True, + end=12, + gamma=0.1, + milestones=[ + 8, + 11, + ], + type='MultiStepLR'), +] +resume = False +test_cfg = dict(type='TestLoop') +test_dataloader = dict( + batch_size=32, + dataset=dict( + ann_file='annotations/instances_val2017.json', + backend_args=None, + data_prefix=dict(img='images/val2017/'), + data_root='data/datasets/coco/', + pipeline=[ + dict(backend_args=None, type='LoadImageFromFile'), + dict(keep_ratio=False, scale=( + 800, + 800, + ), type='Resize'), + dict(type='LoadAnnotations', with_bbox=True), + dict( + meta_keys=( + 'img_id', + 'img_path', + 'ori_shape', + 'img_shape', + 'scale_factor', + ), + type='PackDetInputs'), + ], + test_mode=True, + type='CocoDataset'), + drop_last=False, + num_workers=2, + persistent_workers=True, + sampler=dict(shuffle=False, type='DefaultSampler')) +test_evaluator = dict( + ann_file='data/datasets/coco/annotations/instances_val2017.json', + backend_args=None, + format_only=False, + metric='bbox', + type='CocoMetric') +test_pipeline = [ + dict(backend_args=None, type='LoadImageFromFile'), + dict(keep_ratio=False, scale=( + 800, + 800, + ), type='Resize'), + dict(type='LoadAnnotations', with_bbox=True), + dict( + meta_keys=( + 'img_id', + 'img_path', + 'ori_shape', + 'img_shape', + 'scale_factor', + ), + type='PackDetInputs'), +] +train_cfg = dict(max_epochs=12, type='EpochBasedTrainLoop', val_interval=1) +train_dataloader = dict( + batch_sampler=dict(type='AspectRatioBatchSampler'), + batch_size=8, + dataset=dict( + ann_file='annotations/instances_train2017.json', + backend_args=None, + data_prefix=dict(img='train2017/'), + data_root='data/coco/', + filter_cfg=dict(filter_empty_gt=True, min_size=32), + pipeline=[ + dict(backend_args=None, type='LoadImageFromFile'), + dict(type='LoadAnnotations', with_bbox=True), + dict(keep_ratio=False, scale=( + 800, + 800, + ), type='Resize'), + dict(prob=0.5, type='RandomFlip'), + dict(max_shift_px=32, prob=0.5, type='RandomShift'), + dict(type='PackDetInputs'), + ], + type='CocoDataset'), + num_workers=8, + persistent_workers=True, + sampler=dict(shuffle=True, type='DefaultSampler')) +train_pipeline = [ + dict(backend_args=None, type='LoadImageFromFile'), + dict(type='LoadAnnotations', with_bbox=True), + dict(keep_ratio=False, scale=( + 800, + 800, + ), type='Resize'), + dict(prob=0.5, type='RandomFlip'), + dict(max_shift_px=32, prob=0.5, type='RandomShift'), + dict(type='PackDetInputs'), +] +val_cfg = dict(type='ValLoop') +val_dataloader = dict( + batch_size=1, + dataset=dict( + ann_file='annotations/instances_val2017.json', + backend_args=None, + data_prefix=dict(img='val2017/'), + data_root='data/coco/', + pipeline=[ + dict(backend_args=None, type='LoadImageFromFile'), + dict(keep_ratio=False, scale=( + 800, + 800, + ), type='Resize'), + dict(type='LoadAnnotations', with_bbox=True), + dict( + meta_keys=( + 'img_id', + 'img_path', + 'ori_shape', + 'img_shape', + 'scale_factor', + ), + type='PackDetInputs'), + ], + test_mode=True, + type='CocoDataset'), + drop_last=False, + num_workers=2, + persistent_workers=True, + sampler=dict(shuffle=False, type='DefaultSampler')) +val_evaluator = dict( + ann_file='data/coco/annotations/instances_val2017.json', + backend_args=None, + format_only=False, + metric='bbox', + type='CocoMetric') +vis_backends = [ + dict(type='LocalVisBackend'), +] +visualizer = dict( + name='visualizer', + type='DetLocalVisualizer', + vis_backends=[ + dict(type='LocalVisBackend'), + ]) +work_dir = './workspace' -- Gitee From 8b3500751ed202b9feab026449c525dd4196a4dd Mon Sep 17 00:00:00 2001 From: "hongliang.yuan" Date: Tue, 15 Jul 2025 17:24:58 +0800 Subject: [PATCH 15/15] fix ci --- .../classification/mnasnet1_3/igie/ci/prepare.sh | 2 +- .../scripts/infer_mnasnet1_3_fp16_accuracy.sh | 2 +- .../scripts/infer_mnasnet1_3_fp16_performance.sh | 2 +- models/cv/classification/vgg13/igie/ci/prepare.sh | 2 +- .../igie/scripts/infer_vgg13_fp16_accuracy.sh | 2 +- .../igie/scripts/infer_vgg13_fp16_performance.sh | 2 +- .../cv/classification/vgg13_bn/igie/ci/prepare.sh | 2 +- .../igie/scripts/infer_vgg13_bn_fp16_accuracy.sh | 2 +- .../scripts/infer_vgg13_bn_fp16_performance.sh | 2 +- .../cv/object_detection/ssd/igie/ssd300_coco.py | 15 +++++++++++++++ .../yolof/igie/yolof_r50-c5_8xb8-1x_coco.py | 15 +++++++++++++++ .../object_detection/yolov13/igie/ci/prepare.sh | 3 ++- .../yolov13/igie/requirements.txt | 3 ++- 13 files changed, 43 insertions(+), 11 deletions(-) diff --git a/models/cv/classification/mnasnet1_3/igie/ci/prepare.sh b/models/cv/classification/mnasnet1_3/igie/ci/prepare.sh index 68c05a60..9d822d9c 100644 --- a/models/cv/classification/mnasnet1_3/igie/ci/prepare.sh +++ b/models/cv/classification/mnasnet1_3/igie/ci/prepare.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright (c) 2024, Shanghai Iluvatar CoreX Semiconductor Co., Ltd. +# Copyright (c) 2025, Shanghai Iluvatar CoreX Semiconductor Co., Ltd. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/models/cv/classification/mnasnet1_3/igie/scripts/infer_mnasnet1_3_fp16_accuracy.sh b/models/cv/classification/mnasnet1_3/igie/scripts/infer_mnasnet1_3_fp16_accuracy.sh index f1aff9ed..bc980afc 100644 --- a/models/cv/classification/mnasnet1_3/igie/scripts/infer_mnasnet1_3_fp16_accuracy.sh +++ b/models/cv/classification/mnasnet1_3/igie/scripts/infer_mnasnet1_3_fp16_accuracy.sh @@ -1,6 +1,6 @@ #!/bin/bash -# Copyright (c) 2024, Shanghai Iluvatar CoreX Semiconductor Co., Ltd. +# Copyright (c) 2025, Shanghai Iluvatar CoreX Semiconductor Co., Ltd. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/models/cv/classification/mnasnet1_3/igie/scripts/infer_mnasnet1_3_fp16_performance.sh b/models/cv/classification/mnasnet1_3/igie/scripts/infer_mnasnet1_3_fp16_performance.sh index e8c82cdd..535d5c9b 100644 --- a/models/cv/classification/mnasnet1_3/igie/scripts/infer_mnasnet1_3_fp16_performance.sh +++ b/models/cv/classification/mnasnet1_3/igie/scripts/infer_mnasnet1_3_fp16_performance.sh @@ -1,6 +1,6 @@ #!/bin/bash -# Copyright (c) 2024, Shanghai Iluvatar CoreX Semiconductor Co., Ltd. +# Copyright (c) 2025, Shanghai Iluvatar CoreX Semiconductor Co., Ltd. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/models/cv/classification/vgg13/igie/ci/prepare.sh b/models/cv/classification/vgg13/igie/ci/prepare.sh index 81385dd3..d57f4257 100644 --- a/models/cv/classification/vgg13/igie/ci/prepare.sh +++ b/models/cv/classification/vgg13/igie/ci/prepare.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright (c) 2024, Shanghai Iluvatar CoreX Semiconductor Co., Ltd. +# Copyright (c) 2025, Shanghai Iluvatar CoreX Semiconductor Co., Ltd. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/models/cv/classification/vgg13/igie/scripts/infer_vgg13_fp16_accuracy.sh b/models/cv/classification/vgg13/igie/scripts/infer_vgg13_fp16_accuracy.sh index ae196542..c3ae266f 100644 --- a/models/cv/classification/vgg13/igie/scripts/infer_vgg13_fp16_accuracy.sh +++ b/models/cv/classification/vgg13/igie/scripts/infer_vgg13_fp16_accuracy.sh @@ -1,6 +1,6 @@ #!/bin/bash -# Copyright (c) 2024, Shanghai Iluvatar CoreX Semiconductor Co., Ltd. +# Copyright (c) 2025, Shanghai Iluvatar CoreX Semiconductor Co., Ltd. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/models/cv/classification/vgg13/igie/scripts/infer_vgg13_fp16_performance.sh b/models/cv/classification/vgg13/igie/scripts/infer_vgg13_fp16_performance.sh index c5337250..428deaf7 100644 --- a/models/cv/classification/vgg13/igie/scripts/infer_vgg13_fp16_performance.sh +++ b/models/cv/classification/vgg13/igie/scripts/infer_vgg13_fp16_performance.sh @@ -1,6 +1,6 @@ #!/bin/bash -# Copyright (c) 2024, Shanghai Iluvatar CoreX Semiconductor Co., Ltd. +# Copyright (c) 2025, Shanghai Iluvatar CoreX Semiconductor Co., Ltd. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/models/cv/classification/vgg13_bn/igie/ci/prepare.sh b/models/cv/classification/vgg13_bn/igie/ci/prepare.sh index 6029b6c5..1c18d001 100644 --- a/models/cv/classification/vgg13_bn/igie/ci/prepare.sh +++ b/models/cv/classification/vgg13_bn/igie/ci/prepare.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright (c) 2024, Shanghai Iluvatar CoreX Semiconductor Co., Ltd. +# Copyright (c) 2025, Shanghai Iluvatar CoreX Semiconductor Co., Ltd. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/models/cv/classification/vgg13_bn/igie/scripts/infer_vgg13_bn_fp16_accuracy.sh b/models/cv/classification/vgg13_bn/igie/scripts/infer_vgg13_bn_fp16_accuracy.sh index 04d2fd10..5d5abe78 100644 --- a/models/cv/classification/vgg13_bn/igie/scripts/infer_vgg13_bn_fp16_accuracy.sh +++ b/models/cv/classification/vgg13_bn/igie/scripts/infer_vgg13_bn_fp16_accuracy.sh @@ -1,6 +1,6 @@ #!/bin/bash -# Copyright (c) 2024, Shanghai Iluvatar CoreX Semiconductor Co., Ltd. +# Copyright (c) 2025, Shanghai Iluvatar CoreX Semiconductor Co., Ltd. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/models/cv/classification/vgg13_bn/igie/scripts/infer_vgg13_bn_fp16_performance.sh b/models/cv/classification/vgg13_bn/igie/scripts/infer_vgg13_bn_fp16_performance.sh index 33c8777f..a45d6cce 100644 --- a/models/cv/classification/vgg13_bn/igie/scripts/infer_vgg13_bn_fp16_performance.sh +++ b/models/cv/classification/vgg13_bn/igie/scripts/infer_vgg13_bn_fp16_performance.sh @@ -1,6 +1,6 @@ #!/bin/bash -# Copyright (c) 2024, Shanghai Iluvatar CoreX Semiconductor Co., Ltd. +# Copyright (c) 2025, Shanghai Iluvatar CoreX Semiconductor Co., Ltd. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/models/cv/object_detection/ssd/igie/ssd300_coco.py b/models/cv/object_detection/ssd/igie/ssd300_coco.py index c0226b67..a2d4bd81 100644 --- a/models/cv/object_detection/ssd/igie/ssd300_coco.py +++ b/models/cv/object_detection/ssd/igie/ssd300_coco.py @@ -1,3 +1,18 @@ +# Copyright (c) 2025, 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. +# auto_scale_lr = dict(base_batch_size=64, enable=False) backend_args = None cudnn_benchmark = True diff --git a/models/cv/object_detection/yolof/igie/yolof_r50-c5_8xb8-1x_coco.py b/models/cv/object_detection/yolof/igie/yolof_r50-c5_8xb8-1x_coco.py index 47f58c2d..3549bbbe 100644 --- a/models/cv/object_detection/yolof/igie/yolof_r50-c5_8xb8-1x_coco.py +++ b/models/cv/object_detection/yolof/igie/yolof_r50-c5_8xb8-1x_coco.py @@ -1,3 +1,18 @@ +# Copyright (c) 2025, 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. +# auto_scale_lr = dict(base_batch_size=64, enable=False) backend_args = None data_root = 'data/coco/' diff --git a/models/cv/object_detection/yolov13/igie/ci/prepare.sh b/models/cv/object_detection/yolov13/igie/ci/prepare.sh index 0c535fcc..a02a6f32 100644 --- a/models/cv/object_detection/yolov13/igie/ci/prepare.sh +++ b/models/cv/object_detection/yolov13/igie/ci/prepare.sh @@ -27,7 +27,8 @@ fi pip3 install -r requirements.txt -git clone --depth 1 https://github.com/iMoonLab/yolov13.git +# git clone --depth 1 https://github.com/iMoonLab/yolov13.git +cp -r /mnt/deepspark/data/repos/yolov13 ./ cd yolov13 pip3 install -e . diff --git a/models/cv/object_detection/yolov13/igie/requirements.txt b/models/cv/object_detection/yolov13/igie/requirements.txt index 355ab489..763d3b6b 100644 --- a/models/cv/object_detection/yolov13/igie/requirements.txt +++ b/models/cv/object_detection/yolov13/igie/requirements.txt @@ -1,3 +1,4 @@ tqdm onnx==1.13.0 -huggingface_hub \ No newline at end of file +huggingface_hub +ultralytics \ No newline at end of file -- Gitee