|
| 1 | +# CO-DETR (MMDetection) usage |
| 2 | + |
| 3 | +* [Convert model](#convert-model) |
| 4 | +* [Compile the lib](#compile-the-lib) |
| 5 | +* [Edit the config_infer_primary_codetr file](#edit-the-config_infer_primary_codetr-file) |
| 6 | +* [Edit the deepstream_app_config file](#edit-the-deepstream_app_config-file) |
| 7 | +* [Testing the model](#testing-the-model) |
| 8 | + |
| 9 | +## |
| 10 | + |
| 11 | +### Convert model |
| 12 | + |
| 13 | +#### 1. Download the CO-DETR (MMDetection) repo and install the requirements |
| 14 | + |
| 15 | +``` |
| 16 | +git clone https://github.com/open-mmlab/mmdetection.git |
| 17 | +cd mmdetection |
| 18 | +pip3 install openmim |
| 19 | +mim install mmengine |
| 20 | +mim install mmdeploy |
| 21 | +mim install "mmcv>=2.0.0rc4,<2.2.0" |
| 22 | +pip3 install -v -e . |
| 23 | +pip3 install onnx onnxslim onnxruntime |
| 24 | +``` |
| 25 | + |
| 26 | +**NOTE**: It is recommended to use Python virtualenv. |
| 27 | + |
| 28 | +#### 2. Copy conversor |
| 29 | + |
| 30 | +Copy the `export_codetr.py` file from `DeepStream-Yolo/utils` directory to the `mmdetection` folder. |
| 31 | + |
| 32 | +#### 3. Download the model |
| 33 | + |
| 34 | +Download the `pth` file from [CO-DETR (MMDetection)](https://github.com/open-mmlab/mmdetection/tree/main/projects/CO-DETR) releases (example for Co-DINO R50 DETR*) |
| 35 | + |
| 36 | +``` |
| 37 | +wget https://download.openmmlab.com/mmdetection/v3.0/codetr/co_dino_5scale_r50_1x_coco-7481f903.pth |
| 38 | +``` |
| 39 | + |
| 40 | +**NOTE**: You can use your custom model. |
| 41 | + |
| 42 | +#### 4. Convert model |
| 43 | + |
| 44 | +Generate the ONNX model file (example for Co-DINO R50 DETR) |
| 45 | + |
| 46 | +``` |
| 47 | +python3 export_codetr.py -w co_dino_5scale_r50_1x_coco-7481f903.pth -c projects/CO-DETR/configs/codino/co_dino_5scale_r50_8xb2_1x_coco.py --dynamic |
| 48 | +``` |
| 49 | + |
| 50 | +**NOTE**: To change the inference size (defaut: 640) |
| 51 | + |
| 52 | +``` |
| 53 | +-s SIZE |
| 54 | +--size SIZE |
| 55 | +-s HEIGHT WIDTH |
| 56 | +--size HEIGHT WIDTH |
| 57 | +``` |
| 58 | + |
| 59 | +Example for 1280 |
| 60 | + |
| 61 | +``` |
| 62 | +-s 1280 |
| 63 | +``` |
| 64 | + |
| 65 | +or |
| 66 | + |
| 67 | +``` |
| 68 | +-s 1280 1280 |
| 69 | +``` |
| 70 | + |
| 71 | +**NOTE**: To simplify the ONNX model (DeepStream >= 6.0) |
| 72 | + |
| 73 | +``` |
| 74 | +--simplify |
| 75 | +``` |
| 76 | + |
| 77 | +**NOTE**: To use dynamic batch-size (DeepStream >= 6.1) |
| 78 | + |
| 79 | +``` |
| 80 | +--dynamic |
| 81 | +``` |
| 82 | + |
| 83 | +**NOTE**: To use static batch-size (example for batch-size = 4) |
| 84 | + |
| 85 | +``` |
| 86 | +--batch 4 |
| 87 | +``` |
| 88 | + |
| 89 | +**NOTE**: If you are using the DeepStream 5.1, remove the `--dynamic` arg and use opset 12 or lower. The default opset is 11. |
| 90 | + |
| 91 | +``` |
| 92 | +--opset 12 |
| 93 | +``` |
| 94 | + |
| 95 | +#### 5. Copy generated files |
| 96 | + |
| 97 | +Copy the generated ONNX model file and labels.txt file (if generated) to the `DeepStream-Yolo` folder. |
| 98 | + |
| 99 | +## |
| 100 | + |
| 101 | +### Compile the lib |
| 102 | + |
| 103 | +1. Open the `DeepStream-Yolo` folder and compile the lib |
| 104 | + |
| 105 | +2. Set the `CUDA_VER` according to your DeepStream version |
| 106 | + |
| 107 | +``` |
| 108 | +export CUDA_VER=XY.Z |
| 109 | +``` |
| 110 | + |
| 111 | +* x86 platform |
| 112 | + |
| 113 | + ``` |
| 114 | + DeepStream 7.1 = 12.6 |
| 115 | + DeepStream 7.0 / 6.4 = 12.2 |
| 116 | + DeepStream 6.3 = 12.1 |
| 117 | + DeepStream 6.2 = 11.8 |
| 118 | + DeepStream 6.1.1 = 11.7 |
| 119 | + DeepStream 6.1 = 11.6 |
| 120 | + DeepStream 6.0.1 / 6.0 = 11.4 |
| 121 | + DeepStream 5.1 = 11.1 |
| 122 | + ``` |
| 123 | + |
| 124 | +* Jetson platform |
| 125 | + |
| 126 | + ``` |
| 127 | + DeepStream 7.1 = 12.6 |
| 128 | + DeepStream 7.0 / 6.4 = 12.2 |
| 129 | + DeepStream 6.3 / 6.2 / 6.1.1 / 6.1 = 11.4 |
| 130 | + DeepStream 6.0.1 / 6.0 / 5.1 = 10.2 |
| 131 | + ``` |
| 132 | + |
| 133 | +3. Make the lib |
| 134 | + |
| 135 | +``` |
| 136 | +make -C nvdsinfer_custom_impl_Yolo clean && make -C nvdsinfer_custom_impl_Yolo |
| 137 | +``` |
| 138 | + |
| 139 | +## |
| 140 | + |
| 141 | +### Edit the config_infer_primary_codetr file |
| 142 | + |
| 143 | +Edit the `config_infer_primary_codetr.txt` file according to your model (example for Co-DINO R50 DETR with 80 classes) |
| 144 | + |
| 145 | +``` |
| 146 | +[property] |
| 147 | +... |
| 148 | +onnx-file=co_dino_5scale_r50_1x_coco-7481f903.pth.onnx |
| 149 | +... |
| 150 | +num-detected-classes=80 |
| 151 | +... |
| 152 | +parse-bbox-func-name=NvDsInferParseYolo |
| 153 | +... |
| 154 | +``` |
| 155 | + |
| 156 | +**NOTE**: The **CO-DETR (MMDetection)** resizes the input with left/top padding. To get better accuracy, use |
| 157 | + |
| 158 | +``` |
| 159 | +[property] |
| 160 | +... |
| 161 | +maintain-aspect-ratio=1 |
| 162 | +symmetric-padding=0 |
| 163 | +... |
| 164 | +``` |
| 165 | + |
| 166 | +## |
| 167 | + |
| 168 | +### Edit the deepstream_app_config file |
| 169 | + |
| 170 | +``` |
| 171 | +... |
| 172 | +[primary-gie] |
| 173 | +... |
| 174 | +config-file=config_infer_primary_codetr.txt |
| 175 | +``` |
| 176 | + |
| 177 | +## |
| 178 | + |
| 179 | +### Testing the model |
| 180 | + |
| 181 | +``` |
| 182 | +deepstream-app -c deepstream_app_config.txt |
| 183 | +``` |
| 184 | + |
| 185 | +**NOTE**: The TensorRT engine file may take a very long time to generate (sometimes more than 10 minutes). |
| 186 | + |
| 187 | +**NOTE**: For more information about custom models configuration (`batch-size`, `network-mode`, etc), please check the [`docs/customModels.md`](customModels.md) file. |
0 commit comments