From 0279d29b3a93c4ed7eb02820f6d19d129d5ca141 Mon Sep 17 00:00:00 2001 From: "mingjiang.li" Date: Wed, 9 Jul 2025 14:00:31 +0800 Subject: [PATCH 1/4] add ixrt atss model - object detection Signed-off-by: mingjiang.li --- .gitignore | 3 + .../cv/object_detection/atss/ixrt/README.md | 72 +++++ .../object_detection/atss/ixrt/ci/prepare.sh | 29 ++ .../atss/ixrt/deploy_default.py | 41 +++ .../cv/object_detection/atss/ixrt/export.py | 72 +++++ .../atss/ixrt/requirements.txt | 6 + .../ixrt/scripts/infer_atss_fp16_accuracy.sh | 111 ++++++++ .../scripts/infer_atss_fp16_performance.sh | 112 ++++++++ .../ixrt_common/atss_r50_fpn_1x_coco.py | 269 ++++++++++++++++++ 9 files changed, 715 insertions(+) create mode 100644 models/cv/object_detection/atss/ixrt/README.md create mode 100644 models/cv/object_detection/atss/ixrt/ci/prepare.sh create mode 100644 models/cv/object_detection/atss/ixrt/deploy_default.py create mode 100644 models/cv/object_detection/atss/ixrt/export.py create mode 100644 models/cv/object_detection/atss/ixrt/requirements.txt create mode 100755 models/cv/object_detection/atss/ixrt/scripts/infer_atss_fp16_accuracy.sh create mode 100755 models/cv/object_detection/atss/ixrt/scripts/infer_atss_fp16_performance.sh create mode 100755 models/cv/object_detection/ixrt_common/atss_r50_fpn_1x_coco.py diff --git a/.gitignore b/.gitignore index 2a53e187..c1738571 100644 --- a/.gitignore +++ b/.gitignore @@ -39,6 +39,7 @@ pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ +.vscode/ .tox/ .nox/ .coverage @@ -63,3 +64,5 @@ imagenet_val/ *.pth *.engine data/ + +[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]_*/ diff --git a/models/cv/object_detection/atss/ixrt/README.md b/models/cv/object_detection/atss/ixrt/README.md new file mode 100644 index 00000000..45514dfe --- /dev/null +++ b/models/cv/object_detection/atss/ixrt/README.md @@ -0,0 +1,72 @@ +# ATSS (IxRT) + +## Model Description + +ATSS is an advanced adaptive training sample selection method that effectively enhances the performance of both anchor-based and anchor-free object detectors by dynamically choosing positive and negative samples based on the statistical characteristics of objects. The design of ATSS reduces reliance on hyperparameters, simplifies the sample selection process, and significantly improves detection accuracy without adding extra computational costs. + +## 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. + +```bash +wget https://download.openmmlab.com/mmdetection/v2.0/atss/atss_r50_fpn_1x_coco/atss_r50_fpn_1x_coco_20200209-985f7bd0.pth +``` + +### 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 +mkdir -p checkpoints/ + +python3 export.py --weight atss_r50_fpn_1x_coco_20200209-985f7bd0.pth --cfg ../../ixrt_common/atss_r50_fpn_1x_coco.py --output checkpoints/atss.onnx +``` + +## Model Inference + +```bash +export PROJ_DIR=./ +export DATASETS_DIR=/Path/to/coco/ +export CHECKPOINTS_DIR=./checkpoints +export RUN_DIR=../../ixrt_common +``` + +### FP16 + +```bash +# Accuracy +bash scripts/infer_atss_fp16_accuracy.sh +# Performance +bash scripts/infer_atss_fp16_performance.sh +``` + +## Model Results + +| Model | BatchSize | Precision | FPS | IOU@0.5 | IOU@0.5:0.95 | +| :----: | :----: | :----: | :----: | :----: | :----: | +| ATSS | 32 | FP16 | 131.117 | 0.538 | 0.359 | + +## References + +- [mmdetection](https://github.com/open-mmlab/mmdetection.git) diff --git a/models/cv/object_detection/atss/ixrt/ci/prepare.sh b/models/cv/object_detection/atss/ixrt/ci/prepare.sh new file mode 100644 index 00000000..3d588036 --- /dev/null +++ b/models/cv/object_detection/atss/ixrt/ci/prepare.sh @@ -0,0 +1,29 @@ +#!/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 +mkdir -p checkpoints/ +python3 export.py --weight atss_r50_fpn_1x_coco_20200209-985f7bd0.pth --cfg ../../ixrt_common/atss_r50_fpn_1x_coco.py --output checkpoints/atss.onnx diff --git a/models/cv/object_detection/atss/ixrt/deploy_default.py b/models/cv/object_detection/atss/ixrt/deploy_default.py new file mode 100644 index 00000000..b8d8e43d --- /dev/null +++ b/models/cv/object_detection/atss/ixrt/deploy_default.py @@ -0,0 +1,41 @@ +# 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. + +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/atss/ixrt/export.py b/models/cv/object_detection/atss/ixrt/export.py new file mode 100644 index 00000000..13573c9d --- /dev/null +++ b/models/cv/object_detection/atss/ixrt/export.py @@ -0,0 +1,72 @@ +# Copyright (c) 2024, Shanghai Iluvatar CoreX Semiconductor Co., Ltd. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import argparse + +import 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() \ No newline at end of file diff --git a/models/cv/object_detection/atss/ixrt/requirements.txt b/models/cv/object_detection/atss/ixrt/requirements.txt new file mode 100644 index 00000000..b6b3fff4 --- /dev/null +++ b/models/cv/object_detection/atss/ixrt/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/atss/ixrt/scripts/infer_atss_fp16_accuracy.sh b/models/cv/object_detection/atss/ixrt/scripts/infer_atss_fp16_accuracy.sh new file mode 100755 index 00000000..d7de703c --- /dev/null +++ b/models/cv/object_detection/atss/ixrt/scripts/infer_atss_fp16_accuracy.sh @@ -0,0 +1,111 @@ +#!/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. + +EXIT_STATUS=0 +check_status() +{ + if ((${PIPESTATUS[0]} != 0));then + EXIT_STATUS=1 + fi +} + +# Run paraments +BSZ=32 +WARM_UP=-1 +TGT=-1 +LOOP_COUNT=-1 +RUN_MODE=MAP +PRECISION=float16 + +# Update arguments +index=0 +options=$@ +arguments=($options) +for argument in $options +do + index=`expr $index + 1` + case $argument in + --bs) BSZ=${arguments[index]};; + --tgt) TGT=${arguments[index]};; + esac +done + +MODEL_NAME="atss" +ORIGINE_MODEL="${CHECKPOINTS_DIR}/${MODEL_NAME}.onnx" + +echo CHECKPOINTS_DIR : ${CHECKPOINTS_DIR} +echo DATASETS_DIR : ${DATASETS_DIR} +echo RUN_DIR : ${RUN_DIR} + +step=0 +CURRENT_MODEL=${ORIGINE_MODEL} +# Simplify Model +let step++ +echo; +echo [STEP ${step}] : Simplify Model +SIM_MODEL=${CHECKPOINTS_DIR}/${MODEL_NAME}_sim.onnx +if [ -f ${SIM_MODEL} ];then + echo " "Simplify Model Skipped, ${SIM_MODEL} has been existed +else + python3 ${RUN_DIR}/simplify_model.py \ + --origin_model ${CURRENT_MODEL} \ + --output_model ${SIM_MODEL} + echo " "Generate ${SIM_MODEL} +fi + +CURRENT_MODEL=${SIM_MODEL} + +# Change Batchsize +let step++ +echo; +echo [STEP ${step}] : Change Batchsize +FINAL_MODEL=${CHECKPOINTS_DIR}/${MODEL_NAME}_bs${BSZ}.onnx +if [ -f $FINAL_MODEL ];then + echo " "Change Batchsize Skip, $FINAL_MODEL has been existed +else + python3 ${RUN_DIR}/modify_batchsize.py \ + --batch_size ${BSZ} \ + --origin_model ${CURRENT_MODEL} \ + --output_model ${FINAL_MODEL} + echo " "Generate ${FINAL_MODEL} +fi +CURRENT_MODEL=${FINAL_MODEL} + + +# Build Engine +let step++ +echo; +echo [STEP ${step}] : Build Engine +ENGINE_FILE=${CHECKPOINTS_DIR}/${MODEL_NAME}_${PRECISION}_bs${BSZ}.engine +if [ -f $ENGINE_FILE ];then + echo " "Build Engine Skip, $ENGINE_FILE has been existed +else + python3 ${RUN_DIR}/build_engine.py \ + --model ${CURRENT_MODEL} \ + --engine ${ENGINE_FILE} + echo " "Generate Engine ${ENGINE_FILE} +fi + +# Inference +let step++ +echo; +echo [STEP ${step}] : Inference +python3 ${RUN_DIR}/inference_mmdet.py \ + --engine ${ENGINE_FILE} \ + --cfg_file ${RUN_DIR}/atss_r50_fpn_1x_coco.py \ + --datasets ${DATASETS_DIR} \ + --batchsize ${BSZ} \ + --acc_target ${TGT}; check_status +exit ${EXIT_STATUS} diff --git a/models/cv/object_detection/atss/ixrt/scripts/infer_atss_fp16_performance.sh b/models/cv/object_detection/atss/ixrt/scripts/infer_atss_fp16_performance.sh new file mode 100755 index 00000000..d6b026bf --- /dev/null +++ b/models/cv/object_detection/atss/ixrt/scripts/infer_atss_fp16_performance.sh @@ -0,0 +1,112 @@ +#!/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. + +EXIT_STATUS=0 +check_status() +{ + if ((${PIPESTATUS[0]} != 0));then + EXIT_STATUS=1 + fi +} + +# Run paraments +BSZ=32 +WARM_UP=-1 +TGT=-1 +LOOP_COUNT=-1 +RUN_MODE=MAP +PRECISION=float16 + +# Update arguments +index=0 +options=$@ +arguments=($options) +for argument in $options +do + index=`expr $index + 1` + case $argument in + --bs) BSZ=${arguments[index]};; + --tgt) TGT=${arguments[index]};; + esac +done + +MODEL_NAME="atss_opt" +ORIGINE_MODEL="${CHECKPOINTS_DIR}/atss_opt.onnx" + +echo CHECKPOINTS_DIR : ${CHECKPOINTS_DIR} +echo DATASETS_DIR : ${DATASETS_DIR} +echo RUN_DIR : ${RUN_DIR} + +step=0 +CURRENT_MODEL=${ORIGINE_MODEL} +# Simplify Model +let step++ +echo; +echo [STEP ${step}] : Simplify Model +SIM_MODEL=${CHECKPOINTS_DIR}/${MODEL_NAME}_sim.onnx +if [ -f ${SIM_MODEL} ];then + echo " "Simplify Model Skipped, ${SIM_MODEL} has been existed +else + python3 ${RUN_DIR}/simplify_model.py \ + --origin_model ${CURRENT_MODEL} \ + --output_model ${SIM_MODEL} + echo " "Generate ${SIM_MODEL} +fi + +CURRENT_MODEL=${SIM_MODEL} + +# Change Batchsize +let step++ +echo; +echo [STEP ${step}] : Change Batchsize +FINAL_MODEL=${CHECKPOINTS_DIR}/${MODEL_NAME}_bs${BSZ}.onnx +if [ -f $FINAL_MODEL ];then + echo " "Change Batchsize Skip, $FINAL_MODEL has been existed +else + python3 ${RUN_DIR}/modify_batchsize.py \ + --batch_size ${BSZ} \ + --origin_model ${CURRENT_MODEL} \ + --output_model ${FINAL_MODEL} + echo " "Generate ${FINAL_MODEL} +fi +CURRENT_MODEL=${FINAL_MODEL} + + +# Build Engine +let step++ +echo; +echo [STEP ${step}] : Build Engine +ENGINE_FILE=${CHECKPOINTS_DIR}/${MODEL_NAME}_${PRECISION}_bs{BSZ}.engine +if [ -f $ENGINE_FILE ];then + echo " "Build Engine Skip, $ENGINE_FILE has been existed +else + python3 ${RUN_DIR}/build_engine.py \ + --model ${CURRENT_MODEL} \ + --engine ${ENGINE_FILE} + echo " "Generate Engine ${ENGINE_FILE} +fi + +# Inference +let step++ +echo; +echo [STEP ${step}] : Inference +python3 ${RUN_DIR}/inference_mmdet.py \ + --engine ${ENGINE_FILE} \ + --cfg_file ${RUN_DIR}/atss_r50_fpn_1x_coco.py \ + --perf_only True \ + --datasets ${DATASETS_DIR} \ + --batchsize ${BSZ} \ + --fps_target ${TGT}; check_status +exit ${EXIT_STATUS} diff --git a/models/cv/object_detection/ixrt_common/atss_r50_fpn_1x_coco.py b/models/cv/object_detection/ixrt_common/atss_r50_fpn_1x_coco.py new file mode 100755 index 00000000..88db9b74 --- /dev/null +++ b/models/cv/object_detection/ixrt_common/atss_r50_fpn_1x_coco.py @@ -0,0 +1,269 @@ +auto_scale_lr = dict(base_batch_size=16, 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='torchvision://resnet50', type='Pretrained'), + norm_cfg=dict(requires_grad=True, type='BN'), + norm_eval=True, + num_stages=4, + out_indices=( + 0, + 1, + 2, + 3, + ), + style='pytorch', + type='ResNet'), + bbox_head=dict( + anchor_generator=dict( + octave_base_scale=8, + ratios=[ + 1.0, + ], + scales_per_octave=1, + strides=[ + 8, + 16, + 32, + 64, + 128, + ], + type='AnchorGenerator'), + 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'), + feat_channels=256, + in_channels=256, + loss_bbox=dict(loss_weight=2.0, type='GIoULoss'), + loss_centerness=dict( + loss_weight=1.0, type='CrossEntropyLoss', use_sigmoid=True), + loss_cls=dict( + alpha=0.25, + gamma=2.0, + loss_weight=1.0, + type='FocalLoss', + use_sigmoid=True), + num_classes=80, + stacked_convs=4, + type='ATSSHead'), + data_preprocessor=dict( + bgr_to_rgb=True, + mean=[ + 123.675, + 116.28, + 103.53, + ], + pad_size_divisor=32, + std=[ + 58.395, + 57.12, + 57.375, + ], + type='DetDataPreprocessor'), + neck=dict( + add_extra_convs='on_output', + in_channels=[ + 256, + 512, + 1024, + 2048, + ], + num_outs=5, + out_channels=256, + start_level=1, + type='FPN'), + 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(topk=9, type='ATSSAssigner'), + debug=False, + pos_weight=-1), + type='ATSS') +optim_wrapper = dict( + optimizer=dict(lr=0.01, momentum=0.9, type='SGD', weight_decay=0.0001), + 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=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='val2017/'), + data_root='./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='./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=2, + 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=True, scale=( + 1333, + 800, + ), type='Resize'), + dict(prob=0.5, type='RandomFlip'), + dict(type='PackDetInputs'), + ], + type='CocoDataset'), + 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(keep_ratio=True, scale=( + 1333, + 800, + ), type='Resize'), + dict(prob=0.5, type='RandomFlip'), + 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 = './' -- Gitee From 4947fc923762daada296ef522305cdc167457815 Mon Sep 17 00:00:00 2001 From: "hongliang.yuan" Date: Mon, 14 Jul 2025 16:04:46 +0800 Subject: [PATCH 2/4] add paa retinanet ixrt model --- .../cv/object_detection/atss/ixrt/README.md | 8 +- .../object_detection/atss/ixrt/ci/prepare.sh | 5 +- .../atss/ixrt/deploy_default.py | 41 --- .../cv/object_detection/atss/ixrt/export.py | 72 ----- .../atss/ixrt/requirements.txt | 6 - .../scripts/infer_atss_fp16_performance.sh | 4 +- .../ixrt_common/atss_r50_fpn_1x_coco.py | 269 ------------------ models/cv/object_detection/paa/ixrt/README.md | 73 +++++ .../object_detection/paa/ixrt/ci/prepare.sh | 30 ++ .../ixrt/scripts/infer_paa_fp16_accuracy.sh | 111 ++++++++ .../scripts/infer_paa_fp16_performance.sh | 112 ++++++++ .../object_detection/retinanet/ixrt/README.md | 73 +++++ .../retinanet/ixrt/ci/prepare.sh | 30 ++ .../scripts/infer_retinanet_fp16_accuracy.sh | 111 ++++++++ .../infer_retinanet_fp16_performance.sh | 112 ++++++++ 15 files changed, 661 insertions(+), 396 deletions(-) delete mode 100644 models/cv/object_detection/atss/ixrt/deploy_default.py delete mode 100644 models/cv/object_detection/atss/ixrt/export.py delete mode 100644 models/cv/object_detection/atss/ixrt/requirements.txt delete mode 100755 models/cv/object_detection/ixrt_common/atss_r50_fpn_1x_coco.py create mode 100644 models/cv/object_detection/paa/ixrt/README.md create mode 100644 models/cv/object_detection/paa/ixrt/ci/prepare.sh create mode 100644 models/cv/object_detection/paa/ixrt/scripts/infer_paa_fp16_accuracy.sh create mode 100644 models/cv/object_detection/paa/ixrt/scripts/infer_paa_fp16_performance.sh create mode 100644 models/cv/object_detection/retinanet/ixrt/README.md create mode 100644 models/cv/object_detection/retinanet/ixrt/ci/prepare.sh create mode 100644 models/cv/object_detection/retinanet/ixrt/scripts/infer_retinanet_fp16_accuracy.sh create mode 100644 models/cv/object_detection/retinanet/ixrt/scripts/infer_retinanet_fp16_performance.sh diff --git a/models/cv/object_detection/atss/ixrt/README.md b/models/cv/object_detection/atss/ixrt/README.md index 45514dfe..d86e2eee 100644 --- a/models/cv/object_detection/atss/ixrt/README.md +++ b/models/cv/object_detection/atss/ixrt/README.md @@ -31,16 +31,16 @@ yum install -y mesa-libGL ## Ubuntu apt install -y libgl1-mesa-glx -pip3 install -r requirements.txt +# use igie to export onnx +pip3 install -r ../igie/requirements.txt ``` ### Model Conversion ```bash -# export onnx model mkdir -p checkpoints/ - -python3 export.py --weight atss_r50_fpn_1x_coco_20200209-985f7bd0.pth --cfg ../../ixrt_common/atss_r50_fpn_1x_coco.py --output checkpoints/atss.onnx +cp ../igie/atss_r50_fpn_1x_coco.py ./ +python3 ../igie/export.py --weight atss_r50_fpn_1x_coco_20200209-985f7bd0.pth --cfg ./atss_r50_fpn_1x_coco.py --output checkpoints/atss.onnx ``` ## Model Inference diff --git a/models/cv/object_detection/atss/ixrt/ci/prepare.sh b/models/cv/object_detection/atss/ixrt/ci/prepare.sh index 3d588036..63926d0d 100644 --- a/models/cv/object_detection/atss/ixrt/ci/prepare.sh +++ b/models/cv/object_detection/atss/ixrt/ci/prepare.sh @@ -24,6 +24,7 @@ elif [[ ${ID} == "centos" ]]; then else echo "Not Support Os" fi -pip3 install -r requirements.txt +pip3 install -r ../igie/requirements.txt mkdir -p checkpoints/ -python3 export.py --weight atss_r50_fpn_1x_coco_20200209-985f7bd0.pth --cfg ../../ixrt_common/atss_r50_fpn_1x_coco.py --output checkpoints/atss.onnx +cp ../igie/atss_r50_fpn_1x_coco.py ./ +python3 ../igie/export.py --weight atss_r50_fpn_1x_coco_20200209-985f7bd0.pth --cfg ./atss_r50_fpn_1x_coco.py --output checkpoints/atss.onnx diff --git a/models/cv/object_detection/atss/ixrt/deploy_default.py b/models/cv/object_detection/atss/ixrt/deploy_default.py deleted file mode 100644 index b8d8e43d..00000000 --- a/models/cv/object_detection/atss/ixrt/deploy_default.py +++ /dev/null @@ -1,41 +0,0 @@ -# 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. - -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/atss/ixrt/export.py b/models/cv/object_detection/atss/ixrt/export.py deleted file mode 100644 index 13573c9d..00000000 --- a/models/cv/object_detection/atss/ixrt/export.py +++ /dev/null @@ -1,72 +0,0 @@ -# Copyright (c) 2024, Shanghai Iluvatar CoreX Semiconductor Co., Ltd. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import argparse - -import 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() \ No newline at end of file diff --git a/models/cv/object_detection/atss/ixrt/requirements.txt b/models/cv/object_detection/atss/ixrt/requirements.txt deleted file mode 100644 index b6b3fff4..00000000 --- a/models/cv/object_detection/atss/ixrt/requirements.txt +++ /dev/null @@ -1,6 +0,0 @@ -onnx -tqdm -onnxsim -mmdet==3.3.0 -mmdeploy==1.3.1 -mmengine==0.10.4 diff --git a/models/cv/object_detection/atss/ixrt/scripts/infer_atss_fp16_performance.sh b/models/cv/object_detection/atss/ixrt/scripts/infer_atss_fp16_performance.sh index d6b026bf..f0fed50b 100755 --- a/models/cv/object_detection/atss/ixrt/scripts/infer_atss_fp16_performance.sh +++ b/models/cv/object_detection/atss/ixrt/scripts/infer_atss_fp16_performance.sh @@ -42,8 +42,8 @@ do esac done -MODEL_NAME="atss_opt" -ORIGINE_MODEL="${CHECKPOINTS_DIR}/atss_opt.onnx" +MODEL_NAME="atss" +ORIGINE_MODEL="${CHECKPOINTS_DIR}/${MODEL_NAME}.onnx" echo CHECKPOINTS_DIR : ${CHECKPOINTS_DIR} echo DATASETS_DIR : ${DATASETS_DIR} diff --git a/models/cv/object_detection/ixrt_common/atss_r50_fpn_1x_coco.py b/models/cv/object_detection/ixrt_common/atss_r50_fpn_1x_coco.py deleted file mode 100755 index 88db9b74..00000000 --- a/models/cv/object_detection/ixrt_common/atss_r50_fpn_1x_coco.py +++ /dev/null @@ -1,269 +0,0 @@ -auto_scale_lr = dict(base_batch_size=16, 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='torchvision://resnet50', type='Pretrained'), - norm_cfg=dict(requires_grad=True, type='BN'), - norm_eval=True, - num_stages=4, - out_indices=( - 0, - 1, - 2, - 3, - ), - style='pytorch', - type='ResNet'), - bbox_head=dict( - anchor_generator=dict( - octave_base_scale=8, - ratios=[ - 1.0, - ], - scales_per_octave=1, - strides=[ - 8, - 16, - 32, - 64, - 128, - ], - type='AnchorGenerator'), - 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'), - feat_channels=256, - in_channels=256, - loss_bbox=dict(loss_weight=2.0, type='GIoULoss'), - loss_centerness=dict( - loss_weight=1.0, type='CrossEntropyLoss', use_sigmoid=True), - loss_cls=dict( - alpha=0.25, - gamma=2.0, - loss_weight=1.0, - type='FocalLoss', - use_sigmoid=True), - num_classes=80, - stacked_convs=4, - type='ATSSHead'), - data_preprocessor=dict( - bgr_to_rgb=True, - mean=[ - 123.675, - 116.28, - 103.53, - ], - pad_size_divisor=32, - std=[ - 58.395, - 57.12, - 57.375, - ], - type='DetDataPreprocessor'), - neck=dict( - add_extra_convs='on_output', - in_channels=[ - 256, - 512, - 1024, - 2048, - ], - num_outs=5, - out_channels=256, - start_level=1, - type='FPN'), - 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(topk=9, type='ATSSAssigner'), - debug=False, - pos_weight=-1), - type='ATSS') -optim_wrapper = dict( - optimizer=dict(lr=0.01, momentum=0.9, type='SGD', weight_decay=0.0001), - 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=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='val2017/'), - data_root='./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='./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=2, - 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=True, scale=( - 1333, - 800, - ), type='Resize'), - dict(prob=0.5, type='RandomFlip'), - dict(type='PackDetInputs'), - ], - type='CocoDataset'), - 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(keep_ratio=True, scale=( - 1333, - 800, - ), type='Resize'), - dict(prob=0.5, type='RandomFlip'), - 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 = './' diff --git a/models/cv/object_detection/paa/ixrt/README.md b/models/cv/object_detection/paa/ixrt/README.md new file mode 100644 index 00000000..1632f13b --- /dev/null +++ b/models/cv/object_detection/paa/ixrt/README.md @@ -0,0 +1,73 @@ +# PAA (IxRT) + +## Model Description + +PAA (Probabilistic Anchor Assignment) is an algorithm for object detection that adaptively assigns positive and negative anchor samples using a probabilistic model. It employs a Gaussian mixture model to dynamically select positive and negative samples based on score distribution, avoiding the misassignment issues of traditional IoU threshold-based methods. PAA enhances detection accuracy, particularly in complex scenarios, and is compatible with existing detection frameworks. + +## 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. + +```bash +wget https://download.openmmlab.com/mmdetection/v2.0/paa/paa_r50_fpn_1x_coco/paa_r50_fpn_1x_coco_20200821-936edec3.pth +``` + +### Install Dependencies + +```bash +# Install libGL +## CentOS +yum install -y mesa-libGL +## Ubuntu +apt install -y libgl1-mesa-glx + +# use igie to export onnx +pip3 install -r ../igie/requirements.txt +``` + +### Model Conversion + +```bash +mkdir -p checkpoints/ +cp ../igie/paa_r50_fpn_1x_coco.py ./ +# export onnx model +python3 ../igie/export.py --weight paa_r50_fpn_1x_coco_20200821-936edec3.pth --cfg paa_r50_fpn_1x_coco.py --output checkpoints/paa.onnx +``` + +## Model Inference + +```bash +export PROJ_DIR=./ +export DATASETS_DIR=/Path/to/coco/ +export CHECKPOINTS_DIR=./checkpoints +export RUN_DIR=../../ixrt_common +``` + +### FP16 + +```bash +# Accuracy +bash scripts/infer_paa_fp16_accuracy.sh +# Performance +bash scripts/infer_paa_fp16_performance.sh +``` + +## Model Results + +| Model | BatchSize | Precision | FPS | IOU@0.5 | IOU@0.5:0.95 | +| :----: | :----: | :----: | :----: | :----: | :----: | +| PAA | 32 | FP16 | 131.117 | 0.538 | 0.359 | + +## References + +- [mmdetection](https://github.com/open-mmlab/mmdetection.git) diff --git a/models/cv/object_detection/paa/ixrt/ci/prepare.sh b/models/cv/object_detection/paa/ixrt/ci/prepare.sh new file mode 100644 index 00000000..9ed3df60 --- /dev/null +++ b/models/cv/object_detection/paa/ixrt/ci/prepare.sh @@ -0,0 +1,30 @@ +#!/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 ../igie/requirements.txt +mkdir -p checkpoints/ +cp ../igie/paa_r50_fpn_1x_coco.py ./ +python3 ../igie/export.py --weight paa_r50_fpn_1x_coco_20200821-936edec3.pth --cfg paa_r50_fpn_1x_coco.py --output checkpoints/paa.onnx diff --git a/models/cv/object_detection/paa/ixrt/scripts/infer_paa_fp16_accuracy.sh b/models/cv/object_detection/paa/ixrt/scripts/infer_paa_fp16_accuracy.sh new file mode 100644 index 00000000..6be29ddf --- /dev/null +++ b/models/cv/object_detection/paa/ixrt/scripts/infer_paa_fp16_accuracy.sh @@ -0,0 +1,111 @@ +#!/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. + +EXIT_STATUS=0 +check_status() +{ + if ((${PIPESTATUS[0]} != 0));then + EXIT_STATUS=1 + fi +} + +# Run paraments +BSZ=32 +WARM_UP=-1 +TGT=-1 +LOOP_COUNT=-1 +RUN_MODE=MAP +PRECISION=float16 + +# Update arguments +index=0 +options=$@ +arguments=($options) +for argument in $options +do + index=`expr $index + 1` + case $argument in + --bs) BSZ=${arguments[index]};; + --tgt) TGT=${arguments[index]};; + esac +done + +MODEL_NAME="paa" +ORIGINE_MODEL="${CHECKPOINTS_DIR}/${MODEL_NAME}.onnx" + +echo CHECKPOINTS_DIR : ${CHECKPOINTS_DIR} +echo DATASETS_DIR : ${DATASETS_DIR} +echo RUN_DIR : ${RUN_DIR} + +step=0 +CURRENT_MODEL=${ORIGINE_MODEL} +# Simplify Model +let step++ +echo; +echo [STEP ${step}] : Simplify Model +SIM_MODEL=${CHECKPOINTS_DIR}/${MODEL_NAME}_sim.onnx +if [ -f ${SIM_MODEL} ];then + echo " "Simplify Model Skipped, ${SIM_MODEL} has been existed +else + python3 ${RUN_DIR}/simplify_model.py \ + --origin_model ${CURRENT_MODEL} \ + --output_model ${SIM_MODEL} + echo " "Generate ${SIM_MODEL} +fi + +CURRENT_MODEL=${SIM_MODEL} + +# Change Batchsize +let step++ +echo; +echo [STEP ${step}] : Change Batchsize +FINAL_MODEL=${CHECKPOINTS_DIR}/${MODEL_NAME}_bs${BSZ}.onnx +if [ -f $FINAL_MODEL ];then + echo " "Change Batchsize Skip, $FINAL_MODEL has been existed +else + python3 ${RUN_DIR}/modify_batchsize.py \ + --batch_size ${BSZ} \ + --origin_model ${CURRENT_MODEL} \ + --output_model ${FINAL_MODEL} + echo " "Generate ${FINAL_MODEL} +fi +CURRENT_MODEL=${FINAL_MODEL} + + +# Build Engine +let step++ +echo; +echo [STEP ${step}] : Build Engine +ENGINE_FILE=${CHECKPOINTS_DIR}/${MODEL_NAME}_${PRECISION}_bs${BSZ}.engine +if [ -f $ENGINE_FILE ];then + echo " "Build Engine Skip, $ENGINE_FILE has been existed +else + python3 ${RUN_DIR}/build_engine.py \ + --model ${CURRENT_MODEL} \ + --engine ${ENGINE_FILE} + echo " "Generate Engine ${ENGINE_FILE} +fi + +# Inference +let step++ +echo; +echo [STEP ${step}] : Inference +python3 ${RUN_DIR}/inference_mmdet.py \ + --engine ${ENGINE_FILE} \ + --cfg_file ${RUN_DIR}/paa_r50_fpn_1x_coco.py \ + --datasets ${DATASETS_DIR} \ + --batchsize ${BSZ} \ + --acc_target ${TGT}; check_status +exit ${EXIT_STATUS} diff --git a/models/cv/object_detection/paa/ixrt/scripts/infer_paa_fp16_performance.sh b/models/cv/object_detection/paa/ixrt/scripts/infer_paa_fp16_performance.sh new file mode 100644 index 00000000..f64e7a8c --- /dev/null +++ b/models/cv/object_detection/paa/ixrt/scripts/infer_paa_fp16_performance.sh @@ -0,0 +1,112 @@ +#!/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. + +EXIT_STATUS=0 +check_status() +{ + if ((${PIPESTATUS[0]} != 0));then + EXIT_STATUS=1 + fi +} + +# Run paraments +BSZ=32 +WARM_UP=-1 +TGT=-1 +LOOP_COUNT=-1 +RUN_MODE=MAP +PRECISION=float16 + +# Update arguments +index=0 +options=$@ +arguments=($options) +for argument in $options +do + index=`expr $index + 1` + case $argument in + --bs) BSZ=${arguments[index]};; + --tgt) TGT=${arguments[index]};; + esac +done + +MODEL_NAME="paa" +ORIGINE_MODEL="${CHECKPOINTS_DIR}/${MODEL_NAME}.onnx" + +echo CHECKPOINTS_DIR : ${CHECKPOINTS_DIR} +echo DATASETS_DIR : ${DATASETS_DIR} +echo RUN_DIR : ${RUN_DIR} + +step=0 +CURRENT_MODEL=${ORIGINE_MODEL} +# Simplify Model +let step++ +echo; +echo [STEP ${step}] : Simplify Model +SIM_MODEL=${CHECKPOINTS_DIR}/${MODEL_NAME}_sim.onnx +if [ -f ${SIM_MODEL} ];then + echo " "Simplify Model Skipped, ${SIM_MODEL} has been existed +else + python3 ${RUN_DIR}/simplify_model.py \ + --origin_model ${CURRENT_MODEL} \ + --output_model ${SIM_MODEL} + echo " "Generate ${SIM_MODEL} +fi + +CURRENT_MODEL=${SIM_MODEL} + +# Change Batchsize +let step++ +echo; +echo [STEP ${step}] : Change Batchsize +FINAL_MODEL=${CHECKPOINTS_DIR}/${MODEL_NAME}_bs${BSZ}.onnx +if [ -f $FINAL_MODEL ];then + echo " "Change Batchsize Skip, $FINAL_MODEL has been existed +else + python3 ${RUN_DIR}/modify_batchsize.py \ + --batch_size ${BSZ} \ + --origin_model ${CURRENT_MODEL} \ + --output_model ${FINAL_MODEL} + echo " "Generate ${FINAL_MODEL} +fi +CURRENT_MODEL=${FINAL_MODEL} + + +# Build Engine +let step++ +echo; +echo [STEP ${step}] : Build Engine +ENGINE_FILE=${CHECKPOINTS_DIR}/${MODEL_NAME}_${PRECISION}_bs{BSZ}.engine +if [ -f $ENGINE_FILE ];then + echo " "Build Engine Skip, $ENGINE_FILE has been existed +else + python3 ${RUN_DIR}/build_engine.py \ + --model ${CURRENT_MODEL} \ + --engine ${ENGINE_FILE} + echo " "Generate Engine ${ENGINE_FILE} +fi + +# Inference +let step++ +echo; +echo [STEP ${step}] : Inference +python3 ${RUN_DIR}/inference_mmdet.py \ + --engine ${ENGINE_FILE} \ + --cfg_file ${RUN_DIR}/paa_r50_fpn_1x_coco.py \ + --perf_only True \ + --datasets ${DATASETS_DIR} \ + --batchsize ${BSZ} \ + --fps_target ${TGT}; check_status +exit ${EXIT_STATUS} diff --git a/models/cv/object_detection/retinanet/ixrt/README.md b/models/cv/object_detection/retinanet/ixrt/README.md new file mode 100644 index 00000000..e64bc503 --- /dev/null +++ b/models/cv/object_detection/retinanet/ixrt/README.md @@ -0,0 +1,73 @@ +# RetinaNet (IxRT) + +## Model Description + +RetinaNet, an innovative object detector, challenges the conventional trade-off between speed and accuracy in the realm of computer vision. Traditionally, two-stage detectors, exemplified by R-CNN, achieve high accuracy by applying a classifier to a limited set of candidate object locations. In contrast, one-stage detectors, like RetinaNet, operate over a dense sampling of possible object locations, aiming for simplicity and speed. + +## 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. + +```bash +wget https://download.openmmlab.com/mmdetection/v2.0/retinanet/retinanet_r50_fpn_1x_coco/retinanet_r50_fpn_1x_coco_20200130-c2398f9e.pth +``` + +### Install Dependencies + +```bash +# Install libGL +## CentOS +yum install -y mesa-libGL +## Ubuntu +apt install -y libgl1-mesa-glx + +# use igie to export onnx +pip3 install -r ../igie/requirements.txt +``` + +### Model Conversion + +```bash +mkdir -p checkpoints/ +cp ../igie/retinanet_r50_fpn_1x_coco.py ./ +# export onnx model +python3 ../igie/export.py --weight retinanet_r50_fpn_1x_coco_20200130-c2398f9e.pth --cfg retinanet_r50_fpn_1x_coco.py --output checkpoints/retinanet.onnx +``` + +## Model Inference + +```bash +export PROJ_DIR=./ +export DATASETS_DIR=/Path/to/coco/ +export CHECKPOINTS_DIR=./checkpoints +export RUN_DIR=../../ixrt_common +``` + +### FP16 + +```bash +# Accuracy +bash scripts/infer_retinanet_fp16_accuracy.sh +# Performance +bash scripts/infer_retinanet_fp16_performance.sh +``` + +## Model Results + +| Model | BatchSize | Precision | FPS | IOU@0.5 | IOU@0.5:0.95 | +| :----: | :----: | :----: | :----: | :----: | :----: | +| PAA | 32 | FP16 | 131.117 | 0.538 | 0.359 | + +## References + +- [mmdetection](https://github.com/open-mmlab/mmdetection.git) diff --git a/models/cv/object_detection/retinanet/ixrt/ci/prepare.sh b/models/cv/object_detection/retinanet/ixrt/ci/prepare.sh new file mode 100644 index 00000000..76bfa0d0 --- /dev/null +++ b/models/cv/object_detection/retinanet/ixrt/ci/prepare.sh @@ -0,0 +1,30 @@ +#!/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 ../igie/requirements.txt +mkdir -p checkpoints/ +cp ../igie/retinanet_r50_fpn_1x_coco.py ./ +python3 ../igie/export.py --weight retinanet_r50_fpn_1x_coco_20200130-c2398f9e.pth --cfg retinanet_r50_fpn_1x_coco.py --output checkpoints/retinanet.onnx \ No newline at end of file diff --git a/models/cv/object_detection/retinanet/ixrt/scripts/infer_retinanet_fp16_accuracy.sh b/models/cv/object_detection/retinanet/ixrt/scripts/infer_retinanet_fp16_accuracy.sh new file mode 100644 index 00000000..e3b5b785 --- /dev/null +++ b/models/cv/object_detection/retinanet/ixrt/scripts/infer_retinanet_fp16_accuracy.sh @@ -0,0 +1,111 @@ +#!/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. + +EXIT_STATUS=0 +check_status() +{ + if ((${PIPESTATUS[0]} != 0));then + EXIT_STATUS=1 + fi +} + +# Run paraments +BSZ=32 +WARM_UP=-1 +TGT=-1 +LOOP_COUNT=-1 +RUN_MODE=MAP +PRECISION=float16 + +# Update arguments +index=0 +options=$@ +arguments=($options) +for argument in $options +do + index=`expr $index + 1` + case $argument in + --bs) BSZ=${arguments[index]};; + --tgt) TGT=${arguments[index]};; + esac +done + +MODEL_NAME="retinanet" +ORIGINE_MODEL="${CHECKPOINTS_DIR}/${MODEL_NAME}.onnx" + +echo CHECKPOINTS_DIR : ${CHECKPOINTS_DIR} +echo DATASETS_DIR : ${DATASETS_DIR} +echo RUN_DIR : ${RUN_DIR} + +step=0 +CURRENT_MODEL=${ORIGINE_MODEL} +# Simplify Model +let step++ +echo; +echo [STEP ${step}] : Simplify Model +SIM_MODEL=${CHECKPOINTS_DIR}/${MODEL_NAME}_sim.onnx +if [ -f ${SIM_MODEL} ];then + echo " "Simplify Model Skipped, ${SIM_MODEL} has been existed +else + python3 ${RUN_DIR}/simplify_model.py \ + --origin_model ${CURRENT_MODEL} \ + --output_model ${SIM_MODEL} + echo " "Generate ${SIM_MODEL} +fi + +CURRENT_MODEL=${SIM_MODEL} + +# Change Batchsize +let step++ +echo; +echo [STEP ${step}] : Change Batchsize +FINAL_MODEL=${CHECKPOINTS_DIR}/${MODEL_NAME}_bs${BSZ}.onnx +if [ -f $FINAL_MODEL ];then + echo " "Change Batchsize Skip, $FINAL_MODEL has been existed +else + python3 ${RUN_DIR}/modify_batchsize.py \ + --batch_size ${BSZ} \ + --origin_model ${CURRENT_MODEL} \ + --output_model ${FINAL_MODEL} + echo " "Generate ${FINAL_MODEL} +fi +CURRENT_MODEL=${FINAL_MODEL} + + +# Build Engine +let step++ +echo; +echo [STEP ${step}] : Build Engine +ENGINE_FILE=${CHECKPOINTS_DIR}/${MODEL_NAME}_${PRECISION}_bs${BSZ}.engine +if [ -f $ENGINE_FILE ];then + echo " "Build Engine Skip, $ENGINE_FILE has been existed +else + python3 ${RUN_DIR}/build_engine.py \ + --model ${CURRENT_MODEL} \ + --engine ${ENGINE_FILE} + echo " "Generate Engine ${ENGINE_FILE} +fi + +# Inference +let step++ +echo; +echo [STEP ${step}] : Inference +python3 ${RUN_DIR}/inference_mmdet.py \ + --engine ${ENGINE_FILE} \ + --cfg_file ${RUN_DIR}/retinanet_r50_fpn_1x_coco.py \ + --datasets ${DATASETS_DIR} \ + --batchsize ${BSZ} \ + --acc_target ${TGT}; check_status +exit ${EXIT_STATUS} diff --git a/models/cv/object_detection/retinanet/ixrt/scripts/infer_retinanet_fp16_performance.sh b/models/cv/object_detection/retinanet/ixrt/scripts/infer_retinanet_fp16_performance.sh new file mode 100644 index 00000000..3f656396 --- /dev/null +++ b/models/cv/object_detection/retinanet/ixrt/scripts/infer_retinanet_fp16_performance.sh @@ -0,0 +1,112 @@ +#!/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. + +EXIT_STATUS=0 +check_status() +{ + if ((${PIPESTATUS[0]} != 0));then + EXIT_STATUS=1 + fi +} + +# Run paraments +BSZ=32 +WARM_UP=-1 +TGT=-1 +LOOP_COUNT=-1 +RUN_MODE=MAP +PRECISION=float16 + +# Update arguments +index=0 +options=$@ +arguments=($options) +for argument in $options +do + index=`expr $index + 1` + case $argument in + --bs) BSZ=${arguments[index]};; + --tgt) TGT=${arguments[index]};; + esac +done + +MODEL_NAME="retinanet" +ORIGINE_MODEL="${CHECKPOINTS_DIR}/${MODEL_NAME}.onnx" + +echo CHECKPOINTS_DIR : ${CHECKPOINTS_DIR} +echo DATASETS_DIR : ${DATASETS_DIR} +echo RUN_DIR : ${RUN_DIR} + +step=0 +CURRENT_MODEL=${ORIGINE_MODEL} +# Simplify Model +let step++ +echo; +echo [STEP ${step}] : Simplify Model +SIM_MODEL=${CHECKPOINTS_DIR}/${MODEL_NAME}_sim.onnx +if [ -f ${SIM_MODEL} ];then + echo " "Simplify Model Skipped, ${SIM_MODEL} has been existed +else + python3 ${RUN_DIR}/simplify_model.py \ + --origin_model ${CURRENT_MODEL} \ + --output_model ${SIM_MODEL} + echo " "Generate ${SIM_MODEL} +fi + +CURRENT_MODEL=${SIM_MODEL} + +# Change Batchsize +let step++ +echo; +echo [STEP ${step}] : Change Batchsize +FINAL_MODEL=${CHECKPOINTS_DIR}/${MODEL_NAME}_bs${BSZ}.onnx +if [ -f $FINAL_MODEL ];then + echo " "Change Batchsize Skip, $FINAL_MODEL has been existed +else + python3 ${RUN_DIR}/modify_batchsize.py \ + --batch_size ${BSZ} \ + --origin_model ${CURRENT_MODEL} \ + --output_model ${FINAL_MODEL} + echo " "Generate ${FINAL_MODEL} +fi +CURRENT_MODEL=${FINAL_MODEL} + + +# Build Engine +let step++ +echo; +echo [STEP ${step}] : Build Engine +ENGINE_FILE=${CHECKPOINTS_DIR}/${MODEL_NAME}_${PRECISION}_bs{BSZ}.engine +if [ -f $ENGINE_FILE ];then + echo " "Build Engine Skip, $ENGINE_FILE has been existed +else + python3 ${RUN_DIR}/build_engine.py \ + --model ${CURRENT_MODEL} \ + --engine ${ENGINE_FILE} + echo " "Generate Engine ${ENGINE_FILE} +fi + +# Inference +let step++ +echo; +echo [STEP ${step}] : Inference +python3 ${RUN_DIR}/inference_mmdet.py \ + --engine ${ENGINE_FILE} \ + --cfg_file ${RUN_DIR}/retinanet_r50_fpn_1x_coco.py \ + --perf_only True \ + --datasets ${DATASETS_DIR} \ + --batchsize ${BSZ} \ + --fps_target ${TGT}; check_status +exit ${EXIT_STATUS} -- Gitee From 3146c2befcab1c113ce7ed789c46558c58c46111 Mon Sep 17 00:00:00 2001 From: "hongliang.yuan" Date: Mon, 14 Jul 2025 16:46:22 +0800 Subject: [PATCH 3/4] update --- .../cv/object_detection/atss/ixrt/README.md | 6 +- .../object_detection/atss/ixrt/ci/prepare.sh | 5 +- .../atss/ixrt/deploy_default.py | 41 +++ .../cv/object_detection/atss/ixrt/export.py | 72 +++++ .../scripts/infer_atss_fp16_performance.sh | 2 +- .../ixrt_common/atss_r50_fpn_1x_coco.py | 283 +++++++++++++++++ .../ixrt_common/paa_r50_fpn_1x_coco.py | 291 ++++++++++++++++++ .../ixrt_common/retinanet_r50_fpn_1x_coco.py | 251 +++++++++++++++ models/cv/object_detection/paa/ixrt/README.md | 7 +- .../object_detection/paa/ixrt/ci/prepare.sh | 5 +- .../paa/ixrt/deploy_default.py | 41 +++ models/cv/object_detection/paa/ixrt/export.py | 74 +++++ .../paa/ixrt/requirements.txt | 6 + .../scripts/infer_paa_fp16_performance.sh | 2 +- .../object_detection/retinanet/ixrt/README.md | 5 +- .../retinanet/ixrt/ci/prepare.sh | 5 +- .../retinanet/ixrt/deploy_default.py | 41 +++ .../object_detection/retinanet/ixrt/export.py | 74 +++++ .../retinanet/ixrt/requirements.txt | 6 + 19 files changed, 1195 insertions(+), 22 deletions(-) create mode 100644 models/cv/object_detection/atss/ixrt/deploy_default.py create mode 100644 models/cv/object_detection/atss/ixrt/export.py create mode 100644 models/cv/object_detection/ixrt_common/atss_r50_fpn_1x_coco.py create mode 100644 models/cv/object_detection/ixrt_common/paa_r50_fpn_1x_coco.py create mode 100644 models/cv/object_detection/ixrt_common/retinanet_r50_fpn_1x_coco.py create mode 100644 models/cv/object_detection/paa/ixrt/deploy_default.py create mode 100644 models/cv/object_detection/paa/ixrt/export.py create mode 100644 models/cv/object_detection/paa/ixrt/requirements.txt create mode 100644 models/cv/object_detection/retinanet/ixrt/deploy_default.py create mode 100644 models/cv/object_detection/retinanet/ixrt/export.py create mode 100644 models/cv/object_detection/retinanet/ixrt/requirements.txt diff --git a/models/cv/object_detection/atss/ixrt/README.md b/models/cv/object_detection/atss/ixrt/README.md index d86e2eee..37ff704c 100644 --- a/models/cv/object_detection/atss/ixrt/README.md +++ b/models/cv/object_detection/atss/ixrt/README.md @@ -31,16 +31,14 @@ yum install -y mesa-libGL ## Ubuntu apt install -y libgl1-mesa-glx -# use igie to export onnx -pip3 install -r ../igie/requirements.txt +pip3 install -r requirements.txt ``` ### Model Conversion ```bash mkdir -p checkpoints/ -cp ../igie/atss_r50_fpn_1x_coco.py ./ -python3 ../igie/export.py --weight atss_r50_fpn_1x_coco_20200209-985f7bd0.pth --cfg ./atss_r50_fpn_1x_coco.py --output checkpoints/atss.onnx +python3 export.py --weight atss_r50_fpn_1x_coco_20200209-985f7bd0.pth --cfg ../../ixrt_common/atss_r50_fpn_1x_coco.py --output checkpoints/atss.onnx ``` ## Model Inference diff --git a/models/cv/object_detection/atss/ixrt/ci/prepare.sh b/models/cv/object_detection/atss/ixrt/ci/prepare.sh index 63926d0d..3d588036 100644 --- a/models/cv/object_detection/atss/ixrt/ci/prepare.sh +++ b/models/cv/object_detection/atss/ixrt/ci/prepare.sh @@ -24,7 +24,6 @@ elif [[ ${ID} == "centos" ]]; then else echo "Not Support Os" fi -pip3 install -r ../igie/requirements.txt +pip3 install -r requirements.txt mkdir -p checkpoints/ -cp ../igie/atss_r50_fpn_1x_coco.py ./ -python3 ../igie/export.py --weight atss_r50_fpn_1x_coco_20200209-985f7bd0.pth --cfg ./atss_r50_fpn_1x_coco.py --output checkpoints/atss.onnx +python3 export.py --weight atss_r50_fpn_1x_coco_20200209-985f7bd0.pth --cfg ../../ixrt_common/atss_r50_fpn_1x_coco.py --output checkpoints/atss.onnx diff --git a/models/cv/object_detection/atss/ixrt/deploy_default.py b/models/cv/object_detection/atss/ixrt/deploy_default.py new file mode 100644 index 00000000..b8d8e43d --- /dev/null +++ b/models/cv/object_detection/atss/ixrt/deploy_default.py @@ -0,0 +1,41 @@ +# 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. + +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/atss/ixrt/export.py b/models/cv/object_detection/atss/ixrt/export.py new file mode 100644 index 00000000..13573c9d --- /dev/null +++ b/models/cv/object_detection/atss/ixrt/export.py @@ -0,0 +1,72 @@ +# Copyright (c) 2024, Shanghai Iluvatar CoreX Semiconductor Co., Ltd. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import argparse + +import 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() \ No newline at end of file diff --git a/models/cv/object_detection/atss/ixrt/scripts/infer_atss_fp16_performance.sh b/models/cv/object_detection/atss/ixrt/scripts/infer_atss_fp16_performance.sh index f0fed50b..2271d41b 100755 --- a/models/cv/object_detection/atss/ixrt/scripts/infer_atss_fp16_performance.sh +++ b/models/cv/object_detection/atss/ixrt/scripts/infer_atss_fp16_performance.sh @@ -88,7 +88,7 @@ CURRENT_MODEL=${FINAL_MODEL} let step++ echo; echo [STEP ${step}] : Build Engine -ENGINE_FILE=${CHECKPOINTS_DIR}/${MODEL_NAME}_${PRECISION}_bs{BSZ}.engine +ENGINE_FILE=${CHECKPOINTS_DIR}/${MODEL_NAME}_${PRECISION}_bs${BSZ}.engine if [ -f $ENGINE_FILE ];then echo " "Build Engine Skip, $ENGINE_FILE has been existed else diff --git a/models/cv/object_detection/ixrt_common/atss_r50_fpn_1x_coco.py b/models/cv/object_detection/ixrt_common/atss_r50_fpn_1x_coco.py new file mode 100644 index 00000000..3fc51df9 --- /dev/null +++ b/models/cv/object_detection/ixrt_common/atss_r50_fpn_1x_coco.py @@ -0,0 +1,283 @@ +# 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. + +auto_scale_lr = dict(base_batch_size=16, 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='torchvision://resnet50', type='Pretrained'), + norm_cfg=dict(requires_grad=True, type='BN'), + norm_eval=True, + num_stages=4, + out_indices=( + 0, + 1, + 2, + 3, + ), + style='pytorch', + type='ResNet'), + bbox_head=dict( + anchor_generator=dict( + octave_base_scale=8, + ratios=[ + 1.0, + ], + scales_per_octave=1, + strides=[ + 8, + 16, + 32, + 64, + 128, + ], + type='AnchorGenerator'), + 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'), + feat_channels=256, + in_channels=256, + loss_bbox=dict(loss_weight=2.0, type='GIoULoss'), + loss_centerness=dict( + loss_weight=1.0, type='CrossEntropyLoss', use_sigmoid=True), + loss_cls=dict( + alpha=0.25, + gamma=2.0, + loss_weight=1.0, + type='FocalLoss', + use_sigmoid=True), + num_classes=80, + stacked_convs=4, + type='ATSSHead'), + data_preprocessor=dict( + bgr_to_rgb=True, + mean=[ + 123.675, + 116.28, + 103.53, + ], + pad_size_divisor=32, + std=[ + 58.395, + 57.12, + 57.375, + ], + type='DetDataPreprocessor'), + neck=dict( + add_extra_convs='on_output', + in_channels=[ + 256, + 512, + 1024, + 2048, + ], + num_outs=5, + out_channels=256, + start_level=1, + type='FPN'), + 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(topk=9, type='ATSSAssigner'), + debug=False, + pos_weight=-1), + type='ATSS') +optim_wrapper = dict( + optimizer=dict(lr=0.01, momentum=0.9, type='SGD', weight_decay=0.0001), + 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=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/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/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=2, + 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=True, scale=( + 1333, + 800, + ), type='Resize'), + dict(prob=0.5, type='RandomFlip'), + dict(type='PackDetInputs'), + ], + type='CocoDataset'), + 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(keep_ratio=True, scale=( + 1333, + 800, + ), type='Resize'), + dict(prob=0.5, type='RandomFlip'), + 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'), + ]) \ No newline at end of file diff --git a/models/cv/object_detection/ixrt_common/paa_r50_fpn_1x_coco.py b/models/cv/object_detection/ixrt_common/paa_r50_fpn_1x_coco.py new file mode 100644 index 00000000..2797e347 --- /dev/null +++ b/models/cv/object_detection/ixrt_common/paa_r50_fpn_1x_coco.py @@ -0,0 +1,291 @@ +# 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. + +auto_scale_lr = dict(base_batch_size=16, 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='torchvision://resnet50', type='Pretrained'), + norm_cfg=dict(requires_grad=True, type='BN'), + norm_eval=True, + num_stages=4, + out_indices=( + 0, + 1, + 2, + 3, + ), + style='pytorch', + type='ResNet'), + bbox_head=dict( + anchor_generator=dict( + octave_base_scale=8, + ratios=[ + 1.0, + ], + scales_per_octave=1, + strides=[ + 8, + 16, + 32, + 64, + 128, + ], + type='AnchorGenerator'), + 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'), + feat_channels=256, + in_channels=256, + loss_bbox=dict(loss_weight=1.3, type='GIoULoss'), + loss_centerness=dict( + loss_weight=0.5, type='CrossEntropyLoss', use_sigmoid=True), + 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, + score_voting=True, + stacked_convs=4, + topk=9, + type='PAAHead'), + data_preprocessor=dict( + bgr_to_rgb=True, + mean=[ + 123.675, + 116.28, + 103.53, + ], + pad_size_divisor=32, + std=[ + 58.395, + 57.12, + 57.375, + ], + type='DetDataPreprocessor'), + neck=dict( + add_extra_convs='on_output', + in_channels=[ + 256, + 512, + 1024, + 2048, + ], + num_outs=5, + out_channels=256, + start_level=1, + type='FPN'), + 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( + ignore_iof_thr=-1, + min_pos_iou=0, + neg_iou_thr=0.1, + pos_iou_thr=0.1, + type='MaxIoUAssigner'), + debug=False, + pos_weight=-1), + type='PAA') +optim_wrapper = dict( + optimizer=dict(lr=0.01, momentum=0.9, type='SGD', weight_decay=0.0001), + 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=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/coco/', + pipeline=[ + dict(backend_args=None, type='LoadImageFromFile'), + dict(keep_ratio=True, 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/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=True, 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=2, + 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=True, scale=( + 1333, + 800, + ), type='Resize'), + dict(prob=0.5, type='RandomFlip'), + dict(type='PackDetInputs'), + ], + type='CocoDataset'), + 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(keep_ratio=True, scale=( + 1333, + 800, + ), type='Resize'), + dict(prob=0.5, type='RandomFlip'), + 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=True, 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'), + ]) diff --git a/models/cv/object_detection/ixrt_common/retinanet_r50_fpn_1x_coco.py b/models/cv/object_detection/ixrt_common/retinanet_r50_fpn_1x_coco.py new file mode 100644 index 00000000..d176b02d --- /dev/null +++ b/models/cv/object_detection/ixrt_common/retinanet_r50_fpn_1x_coco.py @@ -0,0 +1,251 @@ +# 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. + +backend_args = None +data = dict( + samples_per_gpu=32, + val=dict( + ann_file='data/coco/annotations/instances_val2017.json', + img_prefix='data/coco/images/val2017/', + 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'), + ], + type='CocoDataset'), + workers_per_gpu=1) +data_root = 'data/coco/' +dataset_type = 'CocoDataset' +default_scope = 'mmdet' +evaluation = dict(interval=1, metric='bbox') +img_norm_cfg = dict( + mean=[ + 123.675, + 116.28, + 103.53, + ], + std=[ + 58.395, + 57.12, + 57.375, + ], + to_rgb=True) +load_from = 'retinanet_r50_fpn_1x_coco_20200130-c2398f9e.pth' +model = dict( + backbone=dict( + depth=50, + frozen_stages=1, + init_cfg=dict(checkpoint='torchvision://resnet50', type='Pretrained'), + norm_cfg=dict(requires_grad=True, type='BN'), + norm_eval=True, + num_stages=4, + out_indices=( + 0, + 1, + 2, + 3, + ), + style='pytorch', + type='ResNet'), + bbox_head=dict( + anchor_generator=dict( + octave_base_scale=4, + ratios=[ + 0.5, + 1.0, + 2.0, + ], + scales_per_octave=3, + strides=[ + 8, + 16, + 32, + 64, + 128, + ], + type='AnchorGenerator'), + bbox_coder=dict( + target_means=[ + 0.0, + 0.0, + 0.0, + 0.0, + ], + target_stds=[ + 1.0, + 1.0, + 1.0, + 1.0, + ], + type='DeltaXYWHBBoxCoder'), + feat_channels=256, + in_channels=256, + loss_bbox=dict(loss_weight=1.0, type='L1Loss'), + loss_cls=dict( + alpha=0.25, + gamma=2.0, + loss_weight=1.0, + type='FocalLoss', + use_sigmoid=True), + num_classes=80, + stacked_convs=4, + type='RetinaHead'), + data_preprocessor=dict( + bgr_to_rgb=True, + mean=[ + 123.675, + 116.28, + 103.53, + ], + pad_size_divisor=32, + std=[ + 58.395, + 57.12, + 57.375, + ], + type='DetDataPreprocessor'), + neck=dict( + add_extra_convs='on_input', + in_channels=[ + 256, + 512, + 1024, + 2048, + ], + num_outs=5, + out_channels=256, + start_level=1, + type='FPN'), + test_cfg=dict( + max_per_img=100, + min_bbox_size=0, + nms=dict(iou_threshold=0.5, type='nms'), + nms_pre=1000, + score_thr=0.05), + train_cfg=dict( + allowed_border=-1, + assigner=dict( + ignore_iof_thr=-1, + min_pos_iou=0, + neg_iou_thr=0.4, + pos_iou_thr=0.5, + type='MaxIoUAssigner'), + debug=False, + pos_weight=-1, + sampler=dict(type='PseudoSampler')), + type='RetinaNet') +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/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/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'), +] +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='images/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') diff --git a/models/cv/object_detection/paa/ixrt/README.md b/models/cv/object_detection/paa/ixrt/README.md index 1632f13b..65f049da 100644 --- a/models/cv/object_detection/paa/ixrt/README.md +++ b/models/cv/object_detection/paa/ixrt/README.md @@ -32,23 +32,22 @@ yum install -y mesa-libGL apt install -y libgl1-mesa-glx # use igie to export onnx -pip3 install -r ../igie/requirements.txt +pip3 install -r requirements.txt ``` ### Model Conversion ```bash mkdir -p checkpoints/ -cp ../igie/paa_r50_fpn_1x_coco.py ./ # export onnx model -python3 ../igie/export.py --weight paa_r50_fpn_1x_coco_20200821-936edec3.pth --cfg paa_r50_fpn_1x_coco.py --output checkpoints/paa.onnx +python3 export.py --weight paa_r50_fpn_1x_coco_20200821-936edec3.pth --cfg paa_r50_fpn_1x_coco.py --output checkpoints/paa.onnx ``` ## Model Inference ```bash export PROJ_DIR=./ -export DATASETS_DIR=/Path/to/coco/ +export DATASETS_DIR=./coco/ export CHECKPOINTS_DIR=./checkpoints export RUN_DIR=../../ixrt_common ``` diff --git a/models/cv/object_detection/paa/ixrt/ci/prepare.sh b/models/cv/object_detection/paa/ixrt/ci/prepare.sh index 9ed3df60..88e3f319 100644 --- a/models/cv/object_detection/paa/ixrt/ci/prepare.sh +++ b/models/cv/object_detection/paa/ixrt/ci/prepare.sh @@ -24,7 +24,6 @@ elif [[ ${ID} == "centos" ]]; then else echo "Not Support Os" fi -pip3 install -r ../igie/requirements.txt +pip3 install -r requirements.txt mkdir -p checkpoints/ -cp ../igie/paa_r50_fpn_1x_coco.py ./ -python3 ../igie/export.py --weight paa_r50_fpn_1x_coco_20200821-936edec3.pth --cfg paa_r50_fpn_1x_coco.py --output checkpoints/paa.onnx +python3 export.py --weight paa_r50_fpn_1x_coco_20200821-936edec3.pth --cfg paa_r50_fpn_1x_coco.py --output checkpoints/paa.onnx diff --git a/models/cv/object_detection/paa/ixrt/deploy_default.py b/models/cv/object_detection/paa/ixrt/deploy_default.py new file mode 100644 index 00000000..b8d8e43d --- /dev/null +++ b/models/cv/object_detection/paa/ixrt/deploy_default.py @@ -0,0 +1,41 @@ +# 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. + +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/paa/ixrt/export.py b/models/cv/object_detection/paa/ixrt/export.py new file mode 100644 index 00000000..bceaba78 --- /dev/null +++ b/models/cv/object_detection/paa/ixrt/export.py @@ -0,0 +1,74 @@ +# Copyright (c) 2024, Shanghai Iluvatar CoreX Semiconductor Co., Ltd. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +import argparse + +import 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'] + output_names = ['output'] + dynamic_axes = {'input': {0: '-1'}, 'output': {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, + output_names = output_names, + opset_version=13 + ) + + print("Export onnx model successfully! ") + +if __name__ == '__main__': + main() + diff --git a/models/cv/object_detection/paa/ixrt/requirements.txt b/models/cv/object_detection/paa/ixrt/requirements.txt new file mode 100644 index 00000000..520dadd4 --- /dev/null +++ b/models/cv/object_detection/paa/ixrt/requirements.txt @@ -0,0 +1,6 @@ +onnx +tqdm +onnxsim +mmdet +mmdeploy==1.3.1 +mmengine diff --git a/models/cv/object_detection/paa/ixrt/scripts/infer_paa_fp16_performance.sh b/models/cv/object_detection/paa/ixrt/scripts/infer_paa_fp16_performance.sh index f64e7a8c..fcd40af7 100644 --- a/models/cv/object_detection/paa/ixrt/scripts/infer_paa_fp16_performance.sh +++ b/models/cv/object_detection/paa/ixrt/scripts/infer_paa_fp16_performance.sh @@ -88,7 +88,7 @@ CURRENT_MODEL=${FINAL_MODEL} let step++ echo; echo [STEP ${step}] : Build Engine -ENGINE_FILE=${CHECKPOINTS_DIR}/${MODEL_NAME}_${PRECISION}_bs{BSZ}.engine +ENGINE_FILE=${CHECKPOINTS_DIR}/${MODEL_NAME}_${PRECISION}_bs${BSZ}.engine if [ -f $ENGINE_FILE ];then echo " "Build Engine Skip, $ENGINE_FILE has been existed else diff --git a/models/cv/object_detection/retinanet/ixrt/README.md b/models/cv/object_detection/retinanet/ixrt/README.md index e64bc503..369268e3 100644 --- a/models/cv/object_detection/retinanet/ixrt/README.md +++ b/models/cv/object_detection/retinanet/ixrt/README.md @@ -32,16 +32,15 @@ yum install -y mesa-libGL apt install -y libgl1-mesa-glx # use igie to export onnx -pip3 install -r ../igie/requirements.txt +pip3 install -r requirements.txt ``` ### Model Conversion ```bash mkdir -p checkpoints/ -cp ../igie/retinanet_r50_fpn_1x_coco.py ./ # export onnx model -python3 ../igie/export.py --weight retinanet_r50_fpn_1x_coco_20200130-c2398f9e.pth --cfg retinanet_r50_fpn_1x_coco.py --output checkpoints/retinanet.onnx +python3 export.py --weight retinanet_r50_fpn_1x_coco_20200130-c2398f9e.pth --cfg retinanet_r50_fpn_1x_coco.py --output checkpoints/retinanet.onnx ``` ## Model Inference diff --git a/models/cv/object_detection/retinanet/ixrt/ci/prepare.sh b/models/cv/object_detection/retinanet/ixrt/ci/prepare.sh index 76bfa0d0..b2efe90f 100644 --- a/models/cv/object_detection/retinanet/ixrt/ci/prepare.sh +++ b/models/cv/object_detection/retinanet/ixrt/ci/prepare.sh @@ -24,7 +24,6 @@ elif [[ ${ID} == "centos" ]]; then else echo "Not Support Os" fi -pip3 install -r ../igie/requirements.txt +pip3 install -r requirements.txt mkdir -p checkpoints/ -cp ../igie/retinanet_r50_fpn_1x_coco.py ./ -python3 ../igie/export.py --weight retinanet_r50_fpn_1x_coco_20200130-c2398f9e.pth --cfg retinanet_r50_fpn_1x_coco.py --output checkpoints/retinanet.onnx \ No newline at end of file +python3 export.py --weight retinanet_r50_fpn_1x_coco_20200130-c2398f9e.pth --cfg retinanet_r50_fpn_1x_coco.py --output checkpoints/retinanet.onnx \ No newline at end of file diff --git a/models/cv/object_detection/retinanet/ixrt/deploy_default.py b/models/cv/object_detection/retinanet/ixrt/deploy_default.py new file mode 100644 index 00000000..b8d8e43d --- /dev/null +++ b/models/cv/object_detection/retinanet/ixrt/deploy_default.py @@ -0,0 +1,41 @@ +# 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. + +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/retinanet/ixrt/export.py b/models/cv/object_detection/retinanet/ixrt/export.py new file mode 100644 index 00000000..bceaba78 --- /dev/null +++ b/models/cv/object_detection/retinanet/ixrt/export.py @@ -0,0 +1,74 @@ +# Copyright (c) 2024, Shanghai Iluvatar CoreX Semiconductor Co., Ltd. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +import argparse + +import 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'] + output_names = ['output'] + dynamic_axes = {'input': {0: '-1'}, 'output': {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, + output_names = output_names, + opset_version=13 + ) + + print("Export onnx model successfully! ") + +if __name__ == '__main__': + main() + diff --git a/models/cv/object_detection/retinanet/ixrt/requirements.txt b/models/cv/object_detection/retinanet/ixrt/requirements.txt new file mode 100644 index 00000000..520dadd4 --- /dev/null +++ b/models/cv/object_detection/retinanet/ixrt/requirements.txt @@ -0,0 +1,6 @@ +onnx +tqdm +onnxsim +mmdet +mmdeploy==1.3.1 +mmengine -- Gitee From 653b88bbb9b9c6b78ec1d736a52e007f9783ac2f Mon Sep 17 00:00:00 2001 From: "hongliang.yuan" Date: Mon, 14 Jul 2025 17:41:55 +0800 Subject: [PATCH 4/4] update --- models/cv/object_detection/fcos/ixrt/ci/prepare.sh | 2 +- models/cv/object_detection/ixrt_common/inference_mmdet.py | 3 ++- models/cv/object_detection/paa/ixrt/README.md | 4 ++-- models/cv/object_detection/paa/ixrt/ci/prepare.sh | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/models/cv/object_detection/fcos/ixrt/ci/prepare.sh b/models/cv/object_detection/fcos/ixrt/ci/prepare.sh index a0469775..633e4f20 100644 --- a/models/cv/object_detection/fcos/ixrt/ci/prepare.sh +++ b/models/cv/object_detection/fcos/ixrt/ci/prepare.sh @@ -25,6 +25,6 @@ else echo "Not Support Os" fi pip3 install -r requirements.txt -pip install /root/data/install/mmcv_full-1.7.0+corex.20250108131027-cp310-cp310-linux_x86_64.whl +pip install /root/data/install/mmcv-2.1.0+corex.4.3.0-cp310-cp310-linux_x86_64.whl mkdir -p checkpoints cp /root/data/checkpoints/fcos_opt.onnx checkpoints/ diff --git a/models/cv/object_detection/ixrt_common/inference_mmdet.py b/models/cv/object_detection/ixrt_common/inference_mmdet.py index 18fd4755..f4b246ed 100644 --- a/models/cv/object_detection/ixrt_common/inference_mmdet.py +++ b/models/cv/object_detection/ixrt_common/inference_mmdet.py @@ -177,7 +177,8 @@ def main(): data_samples.metainfo for data_samples in input_data['data_samples'] ] - if "fovea_r50" or "fsaf" in args.cfg_file: + filename = os.path.basename(args.cfg_file) + if filename.lower().startswith(("fovea_r50_", "fsaf_")): results_list = runner.model.bbox_head.predict_by_feat(cls_score, box_reg, batch_img_metas=batch_img_metas, rescale=True) else: results_list = runner.model.bbox_head.predict_by_feat(cls_score, box_reg, score_factors, batch_img_metas=batch_img_metas, rescale=True) diff --git a/models/cv/object_detection/paa/ixrt/README.md b/models/cv/object_detection/paa/ixrt/README.md index 65f049da..126ac01a 100644 --- a/models/cv/object_detection/paa/ixrt/README.md +++ b/models/cv/object_detection/paa/ixrt/README.md @@ -40,7 +40,7 @@ pip3 install -r requirements.txt ```bash mkdir -p checkpoints/ # export onnx model -python3 export.py --weight paa_r50_fpn_1x_coco_20200821-936edec3.pth --cfg paa_r50_fpn_1x_coco.py --output checkpoints/paa.onnx +python3 export.py --weight paa_r50_fpn_1x_coco_20200821-936edec3.pth --cfg ../../ixrt_common/paa_r50_fpn_1x_coco.py --output checkpoints/paa.onnx ``` ## Model Inference @@ -65,7 +65,7 @@ bash scripts/infer_paa_fp16_performance.sh | Model | BatchSize | Precision | FPS | IOU@0.5 | IOU@0.5:0.95 | | :----: | :----: | :----: | :----: | :----: | :----: | -| PAA | 32 | FP16 | 131.117 | 0.538 | 0.359 | +| PAA | 32 | FP16 | 131.117 | 0.555 | 0.381 | ## References diff --git a/models/cv/object_detection/paa/ixrt/ci/prepare.sh b/models/cv/object_detection/paa/ixrt/ci/prepare.sh index 88e3f319..266a93f8 100644 --- a/models/cv/object_detection/paa/ixrt/ci/prepare.sh +++ b/models/cv/object_detection/paa/ixrt/ci/prepare.sh @@ -26,4 +26,4 @@ else fi pip3 install -r requirements.txt mkdir -p checkpoints/ -python3 export.py --weight paa_r50_fpn_1x_coco_20200821-936edec3.pth --cfg paa_r50_fpn_1x_coco.py --output checkpoints/paa.onnx +python3 export.py --weight paa_r50_fpn_1x_coco_20200821-936edec3.pth --cfg ../../ixrt_common/paa_r50_fpn_1x_coco.py --output checkpoints/paa.onnx -- Gitee