Add dynamic batch-size (ONNX) + Fixes
This commit is contained in:
@@ -2,16 +2,14 @@
|
|||||||
|
|
||||||
NVIDIA DeepStream SDK 6.2 / 6.1.1 / 6.1 / 6.0.1 / 6.0 configuration for YOLO models
|
NVIDIA DeepStream SDK 6.2 / 6.1.1 / 6.1 / 6.0.1 / 6.0 configuration for YOLO models
|
||||||
|
|
||||||
-------------------------------------
|
--------------------------------------------------------------------------------------------------
|
||||||
### **Big update on DeepStream-Yolo**
|
|
||||||
-------------------------------------
|
|
||||||
### Important: please generate the ONNX model and the TensorRT engine again with the updated files
|
### Important: please generate the ONNX model and the TensorRT engine again with the updated files
|
||||||
-------------------------------------
|
--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
### Future updates
|
### Future updates
|
||||||
|
|
||||||
* DeepStream tutorials
|
* DeepStream tutorials
|
||||||
* Dynamic batch-size
|
|
||||||
* Updated INT8 calibration
|
* Updated INT8 calibration
|
||||||
* Support for segmentation models
|
* Support for segmentation models
|
||||||
* Support for classification models
|
* Support for classification models
|
||||||
@@ -24,6 +22,7 @@ NVIDIA DeepStream SDK 6.2 / 6.1.1 / 6.1 / 6.0.1 / 6.0 configuration for YOLO mod
|
|||||||
* **Support for Darknet YOLO models (YOLOv4, etc) using cfg and weights conversion with GPU post-processing**
|
* **Support for Darknet YOLO models (YOLOv4, etc) using cfg and weights conversion with GPU post-processing**
|
||||||
* **Support for YOLO-NAS, PPYOLOE+, PPYOLOE, DAMO-YOLO, YOLOX, YOLOR, YOLOv8, YOLOv7, YOLOv6 and YOLOv5 using ONNX conversion with GPU post-processing**
|
* **Support for YOLO-NAS, PPYOLOE+, PPYOLOE, DAMO-YOLO, YOLOX, YOLOR, YOLOv8, YOLOv7, YOLOv6 and YOLOv5 using ONNX conversion with GPU post-processing**
|
||||||
* **Add GPU bbox parser (it is slightly slower than CPU bbox parser on V100 GPU tests)**
|
* **Add GPU bbox parser (it is slightly slower than CPU bbox parser on V100 GPU tests)**
|
||||||
|
* **Dynamic batch-size for ONNX exported models (YOLO-NAS, PPYOLOE+, PPYOLOE, DAMO-YOLO, YOLOX, YOLOR, YOLOv8, YOLOv7, YOLOv6 and YOLOv5)**
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ wget https://idstcv.oss-cn-zhangjiakou.aliyuncs.com/DAMO-YOLO/release_model/clea
|
|||||||
Generate the ONNX model file (example for DAMO-YOLO-S*)
|
Generate the ONNX model file (example for DAMO-YOLO-S*)
|
||||||
|
|
||||||
```
|
```
|
||||||
python3 export_damoyolo.py -w damoyolo_tinynasL25_S_477.pth -c configs/damoyolo_tinynasL25_S.py --simplify
|
python3 export_damoyolo.py -w damoyolo_tinynasL25_S_477.pth -c configs/damoyolo_tinynasL25_S.py --simplify --dynamic
|
||||||
```
|
```
|
||||||
|
|
||||||
**NOTE**: To change the inference size (defaut: 640)
|
**NOTE**: To change the inference size (defaut: 640)
|
||||||
@@ -66,7 +66,7 @@ or
|
|||||||
|
|
||||||
#### 5. Copy generated files
|
#### 5. Copy generated files
|
||||||
|
|
||||||
Copy the generated ONNX model file to the `DeepStream-Yolo` folder.
|
Copy the generated ONNX model file and labels.txt file (if generated) to the `DeepStream-Yolo` folder.
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ python3 export_ppyoloe.py -w ppyoloe_plus_crn_s_80e_coco.pdparams -c configs/ppy
|
|||||||
|
|
||||||
#### 5. Copy generated files
|
#### 5. Copy generated files
|
||||||
|
|
||||||
Copy the generated ONNX model file to the `DeepStream-Yolo` folder.
|
Copy the generated ONNX model file and labels.txt file (if generated) to the `DeepStream-Yolo` folder.
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ wget https://sghub.deci.ai/models/yolo_nas_s_coco.pth
|
|||||||
Generate the ONNX model file (example for YOLO-NAS S)
|
Generate the ONNX model file (example for YOLO-NAS S)
|
||||||
|
|
||||||
```
|
```
|
||||||
python3 export_yolonas.py -m yolo_nas_s -w yolo_nas_s_coco.pth --simplify
|
python3 export_yolonas.py -m yolo_nas_s -w yolo_nas_s_coco.pth --simplify --dynamic
|
||||||
```
|
```
|
||||||
|
|
||||||
**NOTE**: Model names
|
**NOTE**: Model names
|
||||||
@@ -85,7 +85,7 @@ or
|
|||||||
-s 1280 1280
|
-s 1280 1280
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 5. Copy generated files
|
#### 5. Copy generated file
|
||||||
|
|
||||||
Copy the generated ONNX model file to the `DeepStream-Yolo` folder.
|
Copy the generated ONNX model file to the `DeepStream-Yolo` folder.
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ Generate the ONNX model file
|
|||||||
Example for YOLOR-CSP
|
Example for YOLOR-CSP
|
||||||
|
|
||||||
```
|
```
|
||||||
python3 export_yolor.py -w yolor_csp.pt -c cfg/yolor_csp.cfg --simplify
|
python3 export_yolor.py -w yolor_csp.pt -c cfg/yolor_csp.cfg --simplify --dynamic
|
||||||
```
|
```
|
||||||
|
|
||||||
- Paper branch
|
- Paper branch
|
||||||
@@ -52,7 +52,7 @@ Generate the ONNX model file
|
|||||||
Example for YOLOR-P6
|
Example for YOLOR-P6
|
||||||
|
|
||||||
```
|
```
|
||||||
python3 export_yolor.py -w yolor-p6.pt --simplify
|
python3 export_yolor.py -w yolor-p6.pt --simplify --dynamic
|
||||||
```
|
```
|
||||||
|
|
||||||
**NOTE**: To convert a P6 model
|
**NOTE**: To convert a P6 model
|
||||||
@@ -84,7 +84,7 @@ or
|
|||||||
|
|
||||||
#### 5. Copy generated files
|
#### 5. Copy generated files
|
||||||
|
|
||||||
Copy the generated ONNX model file to the `DeepStream-Yolo` folder
|
Copy the generated ONNX model file and labels.txt file (if generated) to the `DeepStream-Yolo` folder
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
||||||
|
|||||||
@@ -43,10 +43,10 @@ wget https://github.com/Megvii-BaseDetection/YOLOX/releases/download/0.1.1rc0/yo
|
|||||||
Generate the ONNX model file (example for YOLOX-s)
|
Generate the ONNX model file (example for YOLOX-s)
|
||||||
|
|
||||||
```
|
```
|
||||||
python3 export_yolox.py -w yolox_s.pth -c exps/default/yolox_s.py --simplify
|
python3 export_yolox.py -w yolox_s.pth -c exps/default/yolox_s.py --simplify --dynamic
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 5. Copy generated files
|
#### 5. Copy generated file
|
||||||
|
|
||||||
Copy the generated ONNX model file to the `DeepStream-Yolo` folder.
|
Copy the generated ONNX model file to the `DeepStream-Yolo` folder.
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ wget https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5s.pt
|
|||||||
Generate the ONNX model file (example for YOLOv5s)
|
Generate the ONNX model file (example for YOLOv5s)
|
||||||
|
|
||||||
```
|
```
|
||||||
python3 export_yoloV5.py -w yolov5s.pt --simplify
|
python3 export_yoloV5.py -w yolov5s.pt --simplify --dynamic
|
||||||
```
|
```
|
||||||
|
|
||||||
**NOTE**: To convert a P6 model
|
**NOTE**: To convert a P6 model
|
||||||
@@ -76,7 +76,7 @@ or
|
|||||||
|
|
||||||
#### 5. Copy generated files
|
#### 5. Copy generated files
|
||||||
|
|
||||||
Copy the generated ONNX model file to the `DeepStream-Yolo` folder.
|
Copy the generated ONNX model file and labels.txt file (if generated) to the `DeepStream-Yolo` folder.
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ wget https://github.com/meituan/YOLOv6/releases/download/0.4.0/yolov6s.pt
|
|||||||
Generate the ONNX model file (example for YOLOv6-S 4.0)
|
Generate the ONNX model file (example for YOLOv6-S 4.0)
|
||||||
|
|
||||||
```
|
```
|
||||||
python3 export_yoloV6.py -w yolov6s.pt --simplify
|
python3 export_yoloV6.py -w yolov6s.pt --simplify --dynamic
|
||||||
```
|
```
|
||||||
|
|
||||||
**NOTE**: To convert a P6 model
|
**NOTE**: To convert a P6 model
|
||||||
@@ -74,7 +74,7 @@ or
|
|||||||
-s 1280 1280
|
-s 1280 1280
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 5. Copy generated files
|
#### 5. Copy generated file
|
||||||
|
|
||||||
Copy the generated ONNX model file to the `DeepStream-Yolo` folder.
|
Copy the generated ONNX model file to the `DeepStream-Yolo` folder.
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ wget https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7.pt
|
|||||||
Generate the ONNX model file (example for YOLOv7)
|
Generate the ONNX model file (example for YOLOv7)
|
||||||
|
|
||||||
```
|
```
|
||||||
python3 export_yoloV7.py -w yolov7.pt --simplify
|
python3 export_yoloV7.py -w yolov7.pt --simplify --dynamic
|
||||||
```
|
```
|
||||||
|
|
||||||
**NOTE**: To convert a P6 model
|
**NOTE**: To convert a P6 model
|
||||||
@@ -78,7 +78,7 @@ or
|
|||||||
|
|
||||||
#### 6. Copy generated files
|
#### 6. Copy generated files
|
||||||
|
|
||||||
Copy the generated ONNX model file to the `DeepStream-Yolo` folder.
|
Copy the generated ONNX model file and labels.txt file (if generated) to the `DeepStream-Yolo` folder.
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ wget https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8s.pt
|
|||||||
Generate the ONNX model file (example for YOLOv8s)
|
Generate the ONNX model file (example for YOLOv8s)
|
||||||
|
|
||||||
```
|
```
|
||||||
python3 export_yoloV8.py -w yolov8s.pt --simplify
|
python3 export_yoloV8.py -w yolov8s.pt --simplify --dynamic
|
||||||
```
|
```
|
||||||
|
|
||||||
**NOTE**: To change the inference size (defaut: 640)
|
**NOTE**: To change the inference size (defaut: 640)
|
||||||
@@ -69,7 +69,7 @@ or
|
|||||||
|
|
||||||
#### 5. Copy generated files
|
#### 5. Copy generated files
|
||||||
|
|
||||||
Copy the generated ONNX model file to the `DeepStream-Yolo` folder.
|
Copy the generated ONNX model file and labels.txt file (if generated) to the `DeepStream-Yolo` folder.
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
||||||
|
|||||||
@@ -46,9 +46,21 @@ def damoyolo_export(weights, config_file, device):
|
|||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
suppress_warnings()
|
suppress_warnings()
|
||||||
|
|
||||||
|
print('\nStarting: %s' % args.weights)
|
||||||
|
|
||||||
|
print('Opening DAMO-YOLO model')
|
||||||
|
|
||||||
device = torch.device('cpu')
|
device = torch.device('cpu')
|
||||||
cfg, model = damoyolo_export(args.weights, args.config, device)
|
cfg, model = damoyolo_export(args.weights, args.config, device)
|
||||||
|
|
||||||
|
if len(cfg.dataset['class_names']) > 0:
|
||||||
|
print('Creating labels.txt file')
|
||||||
|
f = open('labels.txt', 'w')
|
||||||
|
for name in cfg.dataset['class_names']:
|
||||||
|
f.write(name + '\n')
|
||||||
|
f.close()
|
||||||
|
|
||||||
model = nn.Sequential(model, DeepStreamOutput())
|
model = nn.Sequential(model, DeepStreamOutput())
|
||||||
|
|
||||||
img_size = args.size * 2 if len(args.size) == 1 else args.size
|
img_size = args.size * 2 if len(args.size) == 1 else args.size
|
||||||
@@ -56,15 +68,29 @@ def main(args):
|
|||||||
onnx_input_im = torch.zeros(1, 3, *img_size).to(device)
|
onnx_input_im = torch.zeros(1, 3, *img_size).to(device)
|
||||||
onnx_output_file = cfg.miscs['exp_name'] + '.onnx'
|
onnx_output_file = cfg.miscs['exp_name'] + '.onnx'
|
||||||
|
|
||||||
|
dynamic_axes = {
|
||||||
|
'input': {
|
||||||
|
0: 'batch'
|
||||||
|
},
|
||||||
|
'output': {
|
||||||
|
0: 'batch'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
print('Exporting the model to ONNX')
|
||||||
torch.onnx.export(model, onnx_input_im, onnx_output_file, verbose=False, opset_version=args.opset,
|
torch.onnx.export(model, onnx_input_im, onnx_output_file, verbose=False, opset_version=args.opset,
|
||||||
do_constant_folding=True, input_names=['input'], output_names=['output'], dynamic_axes=None)
|
do_constant_folding=True, input_names=['input'], output_names=['output'],
|
||||||
|
dynamic_axes=dynamic_axes if args.dynamic else None)
|
||||||
|
|
||||||
if args.simplify:
|
if args.simplify:
|
||||||
|
print('Simplifying the ONNX model')
|
||||||
import onnxsim
|
import onnxsim
|
||||||
model_onnx = onnx.load(onnx_output_file)
|
model_onnx = onnx.load(onnx_output_file)
|
||||||
model_onnx, _ = onnxsim.simplify(model_onnx)
|
model_onnx, _ = onnxsim.simplify(model_onnx)
|
||||||
onnx.save(model_onnx, onnx_output_file)
|
onnx.save(model_onnx, onnx_output_file)
|
||||||
|
|
||||||
|
print('Done: %s\n' % onnx_output_file)
|
||||||
|
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
parser = argparse.ArgumentParser(description='DeepStream DAMO-YOLO conversion')
|
parser = argparse.ArgumentParser(description='DeepStream DAMO-YOLO conversion')
|
||||||
@@ -73,6 +99,7 @@ def parse_args():
|
|||||||
parser.add_argument('-s', '--size', nargs='+', type=int, default=[640], help='Inference size [H,W] (default [640])')
|
parser.add_argument('-s', '--size', nargs='+', type=int, default=[640], help='Inference size [H,W] (default [640])')
|
||||||
parser.add_argument('--opset', type=int, default=11, help='ONNX opset version')
|
parser.add_argument('--opset', type=int, default=11, help='ONNX opset version')
|
||||||
parser.add_argument('--simplify', action='store_true', help='ONNX simplify model')
|
parser.add_argument('--simplify', action='store_true', help='ONNX simplify model')
|
||||||
|
parser.add_argument('--dynamic', action='store_true', help='Dynamic batch-size')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
if not os.path.isfile(args.weights):
|
if not os.path.isfile(args.weights):
|
||||||
raise SystemExit('Invalid weights file')
|
raise SystemExit('Invalid weights file')
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from ppdet.utils.check import check_version, check_config
|
|||||||
from ppdet.utils.cli import ArgsParser
|
from ppdet.utils.cli import ArgsParser
|
||||||
from ppdet.engine import Trainer
|
from ppdet.engine import Trainer
|
||||||
from ppdet.slim import build_slim_model
|
from ppdet.slim import build_slim_model
|
||||||
|
from ppdet.data.source.category import get_categories
|
||||||
|
|
||||||
|
|
||||||
class DeepStreamOutput(nn.Layer):
|
class DeepStreamOutput(nn.Layer):
|
||||||
@@ -39,13 +40,26 @@ def ppyoloe_export(FLAGS):
|
|||||||
os.makedirs('.tmp')
|
os.makedirs('.tmp')
|
||||||
static_model, _ = trainer._get_infer_cfg_and_input_spec('.tmp')
|
static_model, _ = trainer._get_infer_cfg_and_input_spec('.tmp')
|
||||||
os.system('rm -r .tmp')
|
os.system('rm -r .tmp')
|
||||||
return cfg, static_model
|
return trainer.cfg, static_model
|
||||||
|
|
||||||
|
|
||||||
def main(FLAGS):
|
def main(FLAGS):
|
||||||
|
print('\nStarting: %s' % FLAGS.weights)
|
||||||
|
|
||||||
|
print('\nOpening PPYOLOE model\n')
|
||||||
|
|
||||||
paddle.set_device('cpu')
|
paddle.set_device('cpu')
|
||||||
cfg, model = ppyoloe_export(FLAGS)
|
cfg, model = ppyoloe_export(FLAGS)
|
||||||
|
|
||||||
|
anno_file = cfg['TestDataset'].get_anno()
|
||||||
|
if os.path.isfile(anno_file):
|
||||||
|
_, catid2name = get_categories(cfg['metric'], anno_file, 'detection_arch')
|
||||||
|
print('\nCreating labels.txt file')
|
||||||
|
f = open('labels.txt', 'w')
|
||||||
|
for name in catid2name.values():
|
||||||
|
f.write(str(name) + '\n')
|
||||||
|
f.close()
|
||||||
|
|
||||||
model = nn.Sequential(model, DeepStreamOutput())
|
model = nn.Sequential(model, DeepStreamOutput())
|
||||||
|
|
||||||
img_size = [cfg.eval_height, cfg.eval_width]
|
img_size = [cfg.eval_height, cfg.eval_width]
|
||||||
@@ -55,14 +69,18 @@ def main(FLAGS):
|
|||||||
onnx_input_im['scale_factor'] = paddle.static.InputSpec(shape=[None, 2], dtype='float32', name='scale_factor')
|
onnx_input_im['scale_factor'] = paddle.static.InputSpec(shape=[None, 2], dtype='float32', name='scale_factor')
|
||||||
onnx_output_file = cfg.filename + '.onnx'
|
onnx_output_file = cfg.filename + '.onnx'
|
||||||
|
|
||||||
|
print('\nExporting the model to ONNX\n')
|
||||||
paddle.onnx.export(model, cfg.filename, input_spec=[onnx_input_im], opset_version=FLAGS.opset)
|
paddle.onnx.export(model, cfg.filename, input_spec=[onnx_input_im], opset_version=FLAGS.opset)
|
||||||
|
|
||||||
if FLAGS.simplify:
|
if FLAGS.simplify:
|
||||||
|
print('\nSimplifying the ONNX model')
|
||||||
import onnxsim
|
import onnxsim
|
||||||
model_onnx = onnx.load(onnx_output_file)
|
model_onnx = onnx.load(onnx_output_file)
|
||||||
model_onnx, _ = onnxsim.simplify(model_onnx)
|
model_onnx, _ = onnxsim.simplify(model_onnx)
|
||||||
onnx.save(model_onnx, onnx_output_file)
|
onnx.save(model_onnx, onnx_output_file)
|
||||||
|
|
||||||
|
print('\nDone: %s\n' % onnx_output_file)
|
||||||
|
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
parser = ArgsParser()
|
parser = ArgsParser()
|
||||||
|
|||||||
@@ -41,9 +41,21 @@ def yolov5_export(weights, device):
|
|||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
suppress_warnings()
|
suppress_warnings()
|
||||||
|
|
||||||
|
print('\nStarting: %s' % args.weights)
|
||||||
|
|
||||||
|
print('Opening YOLOv5 model\n')
|
||||||
|
|
||||||
device = select_device('cpu')
|
device = select_device('cpu')
|
||||||
model = yolov5_export(args.weights, device)
|
model = yolov5_export(args.weights, device)
|
||||||
|
|
||||||
|
if len(model.names.keys()) > 0:
|
||||||
|
print('\nCreating labels.txt file')
|
||||||
|
f = open('labels.txt', 'w')
|
||||||
|
for name in model.names.values():
|
||||||
|
f.write(name + '\n')
|
||||||
|
f.close()
|
||||||
|
|
||||||
model = nn.Sequential(model, DeepStreamOutput())
|
model = nn.Sequential(model, DeepStreamOutput())
|
||||||
|
|
||||||
img_size = args.size * 2 if len(args.size) == 1 else args.size
|
img_size = args.size * 2 if len(args.size) == 1 else args.size
|
||||||
@@ -54,15 +66,29 @@ def main(args):
|
|||||||
onnx_input_im = torch.zeros(1, 3, *img_size).to(device)
|
onnx_input_im = torch.zeros(1, 3, *img_size).to(device)
|
||||||
onnx_output_file = os.path.basename(args.weights).split('.pt')[0] + '.onnx'
|
onnx_output_file = os.path.basename(args.weights).split('.pt')[0] + '.onnx'
|
||||||
|
|
||||||
|
dynamic_axes = {
|
||||||
|
'input': {
|
||||||
|
0: 'batch'
|
||||||
|
},
|
||||||
|
'output': {
|
||||||
|
0: 'batch'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
print('\nExporting the model to ONNX')
|
||||||
torch.onnx.export(model, onnx_input_im, onnx_output_file, verbose=False, opset_version=args.opset,
|
torch.onnx.export(model, onnx_input_im, onnx_output_file, verbose=False, opset_version=args.opset,
|
||||||
do_constant_folding=True, input_names=['input'], output_names=['output'], dynamic_axes=None)
|
do_constant_folding=True, input_names=['input'], output_names=['output'],
|
||||||
|
dynamic_axes=dynamic_axes if args.dynamic else None)
|
||||||
|
|
||||||
if args.simplify:
|
if args.simplify:
|
||||||
|
print('Simplifying the ONNX model')
|
||||||
import onnxsim
|
import onnxsim
|
||||||
model_onnx = onnx.load(onnx_output_file)
|
model_onnx = onnx.load(onnx_output_file)
|
||||||
model_onnx, _ = onnxsim.simplify(model_onnx)
|
model_onnx, _ = onnxsim.simplify(model_onnx)
|
||||||
onnx.save(model_onnx, onnx_output_file)
|
onnx.save(model_onnx, onnx_output_file)
|
||||||
|
|
||||||
|
print('Done: %s\n' % onnx_output_file)
|
||||||
|
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
parser = argparse.ArgumentParser(description='DeepStream YOLOv5 conversion')
|
parser = argparse.ArgumentParser(description='DeepStream YOLOv5 conversion')
|
||||||
@@ -71,6 +97,7 @@ def parse_args():
|
|||||||
parser.add_argument('--p6', action='store_true', help='P6 model')
|
parser.add_argument('--p6', action='store_true', help='P6 model')
|
||||||
parser.add_argument('--opset', type=int, default=17, help='ONNX opset version')
|
parser.add_argument('--opset', type=int, default=17, help='ONNX opset version')
|
||||||
parser.add_argument('--simplify', action='store_true', help='ONNX simplify model')
|
parser.add_argument('--simplify', action='store_true', help='ONNX simplify model')
|
||||||
|
parser.add_argument('--dynamic', action='store_true', help='Dynamic batch-size')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
if not os.path.isfile(args.weights):
|
if not os.path.isfile(args.weights):
|
||||||
raise SystemExit('Invalid weights file')
|
raise SystemExit('Invalid weights file')
|
||||||
|
|||||||
@@ -51,6 +51,11 @@ def yolov6_export(weights, device):
|
|||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
suppress_warnings()
|
suppress_warnings()
|
||||||
|
|
||||||
|
print('\nStarting: %s' % args.weights)
|
||||||
|
|
||||||
|
print('Opening YOLOv6 model\n')
|
||||||
|
|
||||||
device = torch.device('cpu')
|
device = torch.device('cpu')
|
||||||
model = yolov6_export(args.weights, device)
|
model = yolov6_export(args.weights, device)
|
||||||
|
|
||||||
@@ -64,15 +69,29 @@ def main(args):
|
|||||||
onnx_input_im = torch.zeros(1, 3, *img_size).to(device)
|
onnx_input_im = torch.zeros(1, 3, *img_size).to(device)
|
||||||
onnx_output_file = os.path.basename(args.weights).split('.pt')[0] + '.onnx'
|
onnx_output_file = os.path.basename(args.weights).split('.pt')[0] + '.onnx'
|
||||||
|
|
||||||
|
dynamic_axes = {
|
||||||
|
'input': {
|
||||||
|
0: 'batch'
|
||||||
|
},
|
||||||
|
'output': {
|
||||||
|
0: 'batch'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
print('\nExporting the model to ONNX')
|
||||||
torch.onnx.export(model, onnx_input_im, onnx_output_file, verbose=False, opset_version=args.opset,
|
torch.onnx.export(model, onnx_input_im, onnx_output_file, verbose=False, opset_version=args.opset,
|
||||||
do_constant_folding=True, input_names=['input'], output_names=['output'], dynamic_axes=None)
|
do_constant_folding=True, input_names=['input'], output_names=['output'],
|
||||||
|
dynamic_axes=dynamic_axes if args.dynamic else None)
|
||||||
|
|
||||||
if args.simplify:
|
if args.simplify:
|
||||||
|
print('Simplifying the ONNX model')
|
||||||
import onnxsim
|
import onnxsim
|
||||||
model_onnx = onnx.load(onnx_output_file)
|
model_onnx = onnx.load(onnx_output_file)
|
||||||
model_onnx, _ = onnxsim.simplify(model_onnx)
|
model_onnx, _ = onnxsim.simplify(model_onnx)
|
||||||
onnx.save(model_onnx, onnx_output_file)
|
onnx.save(model_onnx, onnx_output_file)
|
||||||
|
|
||||||
|
print('Done: %s\n' % onnx_output_file)
|
||||||
|
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
parser = argparse.ArgumentParser(description='DeepStream YOLOv6 conversion')
|
parser = argparse.ArgumentParser(description='DeepStream YOLOv6 conversion')
|
||||||
@@ -81,6 +100,7 @@ def parse_args():
|
|||||||
parser.add_argument('--p6', action='store_true', help='P6 model')
|
parser.add_argument('--p6', action='store_true', help='P6 model')
|
||||||
parser.add_argument('--opset', type=int, default=13, help='ONNX opset version')
|
parser.add_argument('--opset', type=int, default=13, help='ONNX opset version')
|
||||||
parser.add_argument('--simplify', action='store_true', help='ONNX simplify model')
|
parser.add_argument('--simplify', action='store_true', help='ONNX simplify model')
|
||||||
|
parser.add_argument('--dynamic', action='store_true', help='Dynamic batch-size')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
if not os.path.isfile(args.weights):
|
if not os.path.isfile(args.weights):
|
||||||
raise SystemExit('Invalid weights file')
|
raise SystemExit('Invalid weights file')
|
||||||
|
|||||||
@@ -45,9 +45,21 @@ def yolov7_export(weights, device):
|
|||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
suppress_warnings()
|
suppress_warnings()
|
||||||
|
|
||||||
|
print('\nStarting: %s' % args.weights)
|
||||||
|
|
||||||
|
print('Opening YOLOv7 model\n')
|
||||||
|
|
||||||
device = select_device('cpu')
|
device = select_device('cpu')
|
||||||
model = yolov7_export(args.weights, device)
|
model = yolov7_export(args.weights, device)
|
||||||
|
|
||||||
|
if len(model.names) > 0:
|
||||||
|
print('\nCreating labels.txt file')
|
||||||
|
f = open('labels.txt', 'w')
|
||||||
|
for name in model.names:
|
||||||
|
f.write(name + '\n')
|
||||||
|
f.close()
|
||||||
|
|
||||||
model = nn.Sequential(model, DeepStreamOutput())
|
model = nn.Sequential(model, DeepStreamOutput())
|
||||||
|
|
||||||
img_size = args.size * 2 if len(args.size) == 1 else args.size
|
img_size = args.size * 2 if len(args.size) == 1 else args.size
|
||||||
@@ -58,15 +70,29 @@ def main(args):
|
|||||||
onnx_input_im = torch.zeros(1, 3, *img_size).to(device)
|
onnx_input_im = torch.zeros(1, 3, *img_size).to(device)
|
||||||
onnx_output_file = os.path.basename(args.weights).split('.pt')[0] + '.onnx'
|
onnx_output_file = os.path.basename(args.weights).split('.pt')[0] + '.onnx'
|
||||||
|
|
||||||
|
dynamic_axes = {
|
||||||
|
'input': {
|
||||||
|
0: 'batch'
|
||||||
|
},
|
||||||
|
'output': {
|
||||||
|
0: 'batch'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
print('\nExporting the model to ONNX')
|
||||||
torch.onnx.export(model, onnx_input_im, onnx_output_file, verbose=False, opset_version=args.opset,
|
torch.onnx.export(model, onnx_input_im, onnx_output_file, verbose=False, opset_version=args.opset,
|
||||||
do_constant_folding=True, input_names=['input'], output_names=['output'], dynamic_axes=None)
|
do_constant_folding=True, input_names=['input'], output_names=['output'],
|
||||||
|
dynamic_axes=dynamic_axes if args.dynamic else None)
|
||||||
|
|
||||||
if args.simplify:
|
if args.simplify:
|
||||||
|
print('Simplifying the ONNX model')
|
||||||
import onnxsim
|
import onnxsim
|
||||||
model_onnx = onnx.load(onnx_output_file)
|
model_onnx = onnx.load(onnx_output_file)
|
||||||
model_onnx, _ = onnxsim.simplify(model_onnx)
|
model_onnx, _ = onnxsim.simplify(model_onnx)
|
||||||
onnx.save(model_onnx, onnx_output_file)
|
onnx.save(model_onnx, onnx_output_file)
|
||||||
|
|
||||||
|
print('Done: %s\n' % onnx_output_file)
|
||||||
|
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
parser = argparse.ArgumentParser(description='DeepStream YOLOv7 conversion')
|
parser = argparse.ArgumentParser(description='DeepStream YOLOv7 conversion')
|
||||||
@@ -75,6 +101,7 @@ def parse_args():
|
|||||||
parser.add_argument('--p6', action='store_true', help='P6 model')
|
parser.add_argument('--p6', action='store_true', help='P6 model')
|
||||||
parser.add_argument('--opset', type=int, default=12, help='ONNX opset version')
|
parser.add_argument('--opset', type=int, default=12, help='ONNX opset version')
|
||||||
parser.add_argument('--simplify', action='store_true', help='ONNX simplify model')
|
parser.add_argument('--simplify', action='store_true', help='ONNX simplify model')
|
||||||
|
parser.add_argument('--dynamic', action='store_true', help='Dynamic batch-size')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
if not os.path.isfile(args.weights):
|
if not os.path.isfile(args.weights):
|
||||||
raise SystemExit('Invalid weights file')
|
raise SystemExit('Invalid weights file')
|
||||||
|
|||||||
@@ -40,9 +40,21 @@ def yolov7_u6_export(weights, device):
|
|||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
suppress_warnings()
|
suppress_warnings()
|
||||||
|
|
||||||
|
print('\nStarting: %s' % args.weights)
|
||||||
|
|
||||||
|
print('Opening YOLOv7_u6 model\n')
|
||||||
|
|
||||||
device = select_device('cpu')
|
device = select_device('cpu')
|
||||||
model = yolov7_u6_export(args.weights, device)
|
model = yolov7_u6_export(args.weights, device)
|
||||||
|
|
||||||
|
if len(model.names.keys()) > 0:
|
||||||
|
print('\nCreating labels.txt file')
|
||||||
|
f = open('labels.txt', 'w')
|
||||||
|
for name in model.names.values():
|
||||||
|
f.write(name + '\n')
|
||||||
|
f.close()
|
||||||
|
|
||||||
model = nn.Sequential(model, DeepStreamOutput())
|
model = nn.Sequential(model, DeepStreamOutput())
|
||||||
|
|
||||||
img_size = args.size * 2 if len(args.size) == 1 else args.size
|
img_size = args.size * 2 if len(args.size) == 1 else args.size
|
||||||
@@ -50,15 +62,29 @@ def main(args):
|
|||||||
onnx_input_im = torch.zeros(1, 3, *img_size).to(device)
|
onnx_input_im = torch.zeros(1, 3, *img_size).to(device)
|
||||||
onnx_output_file = os.path.basename(args.weights).split('.pt')[0] + '.onnx'
|
onnx_output_file = os.path.basename(args.weights).split('.pt')[0] + '.onnx'
|
||||||
|
|
||||||
|
dynamic_axes = {
|
||||||
|
'input': {
|
||||||
|
0: 'batch'
|
||||||
|
},
|
||||||
|
'output': {
|
||||||
|
0: 'batch'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
print('\nExporting the model to ONNX')
|
||||||
torch.onnx.export(model, onnx_input_im, onnx_output_file, verbose=False, opset_version=args.opset,
|
torch.onnx.export(model, onnx_input_im, onnx_output_file, verbose=False, opset_version=args.opset,
|
||||||
do_constant_folding=True, input_names=['input'], output_names=['output'], dynamic_axes=None)
|
do_constant_folding=True, input_names=['input'], output_names=['output'],
|
||||||
|
dynamic_axes=dynamic_axes if args.dynamic else None)
|
||||||
|
|
||||||
if args.simplify:
|
if args.simplify:
|
||||||
|
print('Simplifying the ONNX model')
|
||||||
import onnxsim
|
import onnxsim
|
||||||
model_onnx = onnx.load(onnx_output_file)
|
model_onnx = onnx.load(onnx_output_file)
|
||||||
model_onnx, _ = onnxsim.simplify(model_onnx)
|
model_onnx, _ = onnxsim.simplify(model_onnx)
|
||||||
onnx.save(model_onnx, onnx_output_file)
|
onnx.save(model_onnx, onnx_output_file)
|
||||||
|
|
||||||
|
print('Done: %s\n' % onnx_output_file)
|
||||||
|
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
parser = argparse.ArgumentParser(description='DeepStream YOLOv7-u6 conversion')
|
parser = argparse.ArgumentParser(description='DeepStream YOLOv7-u6 conversion')
|
||||||
@@ -66,6 +92,7 @@ def parse_args():
|
|||||||
parser.add_argument('-s', '--size', nargs='+', type=int, default=[640], help='Inference size [H,W] (default [640])')
|
parser.add_argument('-s', '--size', nargs='+', type=int, default=[640], help='Inference size [H,W] (default [640])')
|
||||||
parser.add_argument('--opset', type=int, default=12, help='ONNX opset version')
|
parser.add_argument('--opset', type=int, default=12, help='ONNX opset version')
|
||||||
parser.add_argument('--simplify', action='store_true', help='ONNX simplify model')
|
parser.add_argument('--simplify', action='store_true', help='ONNX simplify model')
|
||||||
|
parser.add_argument('--dynamic', action='store_true', help='Dynamic batch-size')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
if not os.path.isfile(args.weights):
|
if not os.path.isfile(args.weights):
|
||||||
raise SystemExit('Invalid weights file')
|
raise SystemExit('Invalid weights file')
|
||||||
|
|||||||
@@ -48,9 +48,21 @@ def yolov8_export(weights, device):
|
|||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
suppress_warnings()
|
suppress_warnings()
|
||||||
|
|
||||||
|
print('\nStarting: %s' % args.weights)
|
||||||
|
|
||||||
|
print('Opening YOLOv8 model\n')
|
||||||
|
|
||||||
device = select_device('cpu')
|
device = select_device('cpu')
|
||||||
model = yolov8_export(args.weights, device)
|
model = yolov8_export(args.weights, device)
|
||||||
|
|
||||||
|
if len(model.names.keys()) > 0:
|
||||||
|
print('\nCreating labels.txt file')
|
||||||
|
f = open('labels.txt', 'w')
|
||||||
|
for name in model.names.values():
|
||||||
|
f.write(name + '\n')
|
||||||
|
f.close()
|
||||||
|
|
||||||
model = nn.Sequential(model, DeepStreamOutput())
|
model = nn.Sequential(model, DeepStreamOutput())
|
||||||
|
|
||||||
img_size = args.size * 2 if len(args.size) == 1 else args.size
|
img_size = args.size * 2 if len(args.size) == 1 else args.size
|
||||||
@@ -58,15 +70,29 @@ def main(args):
|
|||||||
onnx_input_im = torch.zeros(1, 3, *img_size).to(device)
|
onnx_input_im = torch.zeros(1, 3, *img_size).to(device)
|
||||||
onnx_output_file = os.path.basename(args.weights).split('.pt')[0] + '.onnx'
|
onnx_output_file = os.path.basename(args.weights).split('.pt')[0] + '.onnx'
|
||||||
|
|
||||||
|
dynamic_axes = {
|
||||||
|
'input': {
|
||||||
|
0: 'batch'
|
||||||
|
},
|
||||||
|
'output': {
|
||||||
|
0: 'batch'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
print('\nExporting the model to ONNX')
|
||||||
torch.onnx.export(model, onnx_input_im, onnx_output_file, verbose=False, opset_version=args.opset,
|
torch.onnx.export(model, onnx_input_im, onnx_output_file, verbose=False, opset_version=args.opset,
|
||||||
do_constant_folding=True, input_names=['input'], output_names=['output'], dynamic_axes=None)
|
do_constant_folding=True, input_names=['input'], output_names=['output'],
|
||||||
|
dynamic_axes=dynamic_axes if args.dynamic else None)
|
||||||
|
|
||||||
if args.simplify:
|
if args.simplify:
|
||||||
|
print('Simplifying the ONNX model')
|
||||||
import onnxsim
|
import onnxsim
|
||||||
model_onnx = onnx.load(onnx_output_file)
|
model_onnx = onnx.load(onnx_output_file)
|
||||||
model_onnx, _ = onnxsim.simplify(model_onnx)
|
model_onnx, _ = onnxsim.simplify(model_onnx)
|
||||||
onnx.save(model_onnx, onnx_output_file)
|
onnx.save(model_onnx, onnx_output_file)
|
||||||
|
|
||||||
|
print('Done: %s\n' % onnx_output_file)
|
||||||
|
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
parser = argparse.ArgumentParser(description='DeepStream YOLOv8 conversion')
|
parser = argparse.ArgumentParser(description='DeepStream YOLOv8 conversion')
|
||||||
@@ -74,6 +100,7 @@ def parse_args():
|
|||||||
parser.add_argument('-s', '--size', nargs='+', type=int, default=[640], help='Inference size [H,W] (default [640])')
|
parser.add_argument('-s', '--size', nargs='+', type=int, default=[640], help='Inference size [H,W] (default [640])')
|
||||||
parser.add_argument('--opset', type=int, default=16, help='ONNX opset version')
|
parser.add_argument('--opset', type=int, default=16, help='ONNX opset version')
|
||||||
parser.add_argument('--simplify', action='store_true', help='ONNX simplify model')
|
parser.add_argument('--simplify', action='store_true', help='ONNX simplify model')
|
||||||
|
parser.add_argument('--dynamic', action='store_true', help='Dynamic batch-size')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
if not os.path.isfile(args.weights):
|
if not os.path.isfile(args.weights):
|
||||||
raise SystemExit('Invalid weights file')
|
raise SystemExit('Invalid weights file')
|
||||||
|
|||||||
@@ -34,6 +34,11 @@ def yolonas_export(model_name, weights, num_classes, size):
|
|||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
suppress_warnings()
|
suppress_warnings()
|
||||||
|
|
||||||
|
print('\nStarting: %s' % args.weights)
|
||||||
|
|
||||||
|
print('Opening YOLO-NAS model\n')
|
||||||
|
|
||||||
device = torch.device('cpu')
|
device = torch.device('cpu')
|
||||||
model = yolonas_export(args.model, args.weights, args.classes, args.size)
|
model = yolonas_export(args.model, args.weights, args.classes, args.size)
|
||||||
|
|
||||||
@@ -44,15 +49,29 @@ def main(args):
|
|||||||
onnx_input_im = torch.zeros(1, 3, *img_size).to(device)
|
onnx_input_im = torch.zeros(1, 3, *img_size).to(device)
|
||||||
onnx_output_file = os.path.basename(args.weights).split('.pt')[0] + '.onnx'
|
onnx_output_file = os.path.basename(args.weights).split('.pt')[0] + '.onnx'
|
||||||
|
|
||||||
|
dynamic_axes = {
|
||||||
|
'input': {
|
||||||
|
0: 'batch'
|
||||||
|
},
|
||||||
|
'output': {
|
||||||
|
0: 'batch'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
print('\nExporting the model to ONNX')
|
||||||
torch.onnx.export(model, onnx_input_im, onnx_output_file, verbose=False, opset_version=args.opset,
|
torch.onnx.export(model, onnx_input_im, onnx_output_file, verbose=False, opset_version=args.opset,
|
||||||
do_constant_folding=True, input_names=['input'], output_names=['output'], dynamic_axes=None)
|
do_constant_folding=True, input_names=['input'], output_names=['output'],
|
||||||
|
dynamic_axes=dynamic_axes if args.dynamic else None)
|
||||||
|
|
||||||
if args.simplify:
|
if args.simplify:
|
||||||
|
print('Simplifying the ONNX model')
|
||||||
import onnxsim
|
import onnxsim
|
||||||
model_onnx = onnx.load(onnx_output_file)
|
model_onnx = onnx.load(onnx_output_file)
|
||||||
model_onnx, _ = onnxsim.simplify(model_onnx)
|
model_onnx, _ = onnxsim.simplify(model_onnx)
|
||||||
onnx.save(model_onnx, onnx_output_file)
|
onnx.save(model_onnx, onnx_output_file)
|
||||||
|
|
||||||
|
print('Done: %s\n' % onnx_output_file)
|
||||||
|
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
parser = argparse.ArgumentParser(description='DeepStream YOLO-NAS conversion')
|
parser = argparse.ArgumentParser(description='DeepStream YOLO-NAS conversion')
|
||||||
@@ -62,6 +81,7 @@ def parse_args():
|
|||||||
parser.add_argument('-s', '--size', nargs='+', type=int, default=[640], help='Inference size [H,W] (default [640])')
|
parser.add_argument('-s', '--size', nargs='+', type=int, default=[640], help='Inference size [H,W] (default [640])')
|
||||||
parser.add_argument('--opset', type=int, default=14, help='ONNX opset version')
|
parser.add_argument('--opset', type=int, default=14, help='ONNX opset version')
|
||||||
parser.add_argument('--simplify', action='store_true', help='ONNX simplify model')
|
parser.add_argument('--simplify', action='store_true', help='ONNX simplify model')
|
||||||
|
parser.add_argument('--dynamic', action='store_true', help='Dynamic batch-size')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
if args.model == '':
|
if args.model == '':
|
||||||
raise SystemExit('Invalid model name')
|
raise SystemExit('Invalid model name')
|
||||||
|
|||||||
@@ -57,9 +57,21 @@ def yolor_export(weights, cfg, size, device):
|
|||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
suppress_warnings()
|
suppress_warnings()
|
||||||
|
|
||||||
|
print('\nStarting: %s' % args.weights)
|
||||||
|
|
||||||
|
print('Opening YOLOR model\n')
|
||||||
|
|
||||||
device = torch.device('cpu')
|
device = torch.device('cpu')
|
||||||
model = yolor_export(args.weights, args.cfg, args.size, device)
|
model = yolor_export(args.weights, args.cfg, args.size, device)
|
||||||
|
|
||||||
|
if hasattr(model, 'names') and len(model.names) > 0:
|
||||||
|
print('\nCreating labels.txt file')
|
||||||
|
f = open('labels.txt', 'w')
|
||||||
|
for name in model.names:
|
||||||
|
f.write(name + '\n')
|
||||||
|
f.close()
|
||||||
|
|
||||||
model = nn.Sequential(model, DeepStreamOutput())
|
model = nn.Sequential(model, DeepStreamOutput())
|
||||||
|
|
||||||
img_size = args.size * 2 if len(args.size) == 1 else args.size
|
img_size = args.size * 2 if len(args.size) == 1 else args.size
|
||||||
@@ -70,15 +82,29 @@ def main(args):
|
|||||||
onnx_input_im = torch.zeros(1, 3, *img_size).to(device)
|
onnx_input_im = torch.zeros(1, 3, *img_size).to(device)
|
||||||
onnx_output_file = os.path.basename(args.weights).split('.pt')[0] + '.onnx'
|
onnx_output_file = os.path.basename(args.weights).split('.pt')[0] + '.onnx'
|
||||||
|
|
||||||
|
dynamic_axes = {
|
||||||
|
'input': {
|
||||||
|
0: 'batch'
|
||||||
|
},
|
||||||
|
'output': {
|
||||||
|
0: 'batch'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
print('\nExporting the model to ONNX')
|
||||||
torch.onnx.export(model, onnx_input_im, onnx_output_file, verbose=False, opset_version=args.opset,
|
torch.onnx.export(model, onnx_input_im, onnx_output_file, verbose=False, opset_version=args.opset,
|
||||||
do_constant_folding=True, input_names=['input'], output_names=['output'], dynamic_axes=None)
|
do_constant_folding=True, input_names=['input'], output_names=['output'],
|
||||||
|
dynamic_axes=dynamic_axes if args.dynamic else None)
|
||||||
|
|
||||||
if args.simplify:
|
if args.simplify:
|
||||||
|
print('Simplifying the ONNX model')
|
||||||
import onnxsim
|
import onnxsim
|
||||||
model_onnx = onnx.load(onnx_output_file)
|
model_onnx = onnx.load(onnx_output_file)
|
||||||
model_onnx, _ = onnxsim.simplify(model_onnx)
|
model_onnx, _ = onnxsim.simplify(model_onnx)
|
||||||
onnx.save(model_onnx, onnx_output_file)
|
onnx.save(model_onnx, onnx_output_file)
|
||||||
|
|
||||||
|
print('Done: %s\n' % onnx_output_file)
|
||||||
|
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
parser = argparse.ArgumentParser(description='DeepStream YOLOR conversion')
|
parser = argparse.ArgumentParser(description='DeepStream YOLOR conversion')
|
||||||
@@ -88,6 +114,7 @@ def parse_args():
|
|||||||
parser.add_argument('--p6', action='store_true', help='P6 model')
|
parser.add_argument('--p6', action='store_true', help='P6 model')
|
||||||
parser.add_argument('--opset', type=int, default=12, help='ONNX opset version')
|
parser.add_argument('--opset', type=int, default=12, help='ONNX opset version')
|
||||||
parser.add_argument('--simplify', action='store_true', help='ONNX simplify model')
|
parser.add_argument('--simplify', action='store_true', help='ONNX simplify model')
|
||||||
|
parser.add_argument('--dynamic', action='store_true', help='Dynamic batch-size')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
if not os.path.isfile(args.weights):
|
if not os.path.isfile(args.weights):
|
||||||
raise SystemExit('Invalid weights file')
|
raise SystemExit('Invalid weights file')
|
||||||
|
|||||||
@@ -42,6 +42,11 @@ def yolox_export(weights, exp_file):
|
|||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
suppress_warnings()
|
suppress_warnings()
|
||||||
|
|
||||||
|
print('\nStarting: %s' % args.weights)
|
||||||
|
|
||||||
|
print('Opening YOLOX model')
|
||||||
|
|
||||||
device = torch.device('cpu')
|
device = torch.device('cpu')
|
||||||
model, exp = yolox_export(args.weights, args.exp)
|
model, exp = yolox_export(args.weights, args.exp)
|
||||||
|
|
||||||
@@ -52,15 +57,29 @@ def main(args):
|
|||||||
onnx_input_im = torch.zeros(1, 3, *img_size).to(device)
|
onnx_input_im = torch.zeros(1, 3, *img_size).to(device)
|
||||||
onnx_output_file = os.path.basename(args.weights).split('.pt')[0] + '.onnx'
|
onnx_output_file = os.path.basename(args.weights).split('.pt')[0] + '.onnx'
|
||||||
|
|
||||||
|
dynamic_axes = {
|
||||||
|
'input': {
|
||||||
|
0: 'batch'
|
||||||
|
},
|
||||||
|
'output': {
|
||||||
|
0: 'batch'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
print('Exporting the model to ONNX')
|
||||||
torch.onnx.export(model, onnx_input_im, onnx_output_file, verbose=False, opset_version=args.opset,
|
torch.onnx.export(model, onnx_input_im, onnx_output_file, verbose=False, opset_version=args.opset,
|
||||||
do_constant_folding=True, input_names=['input'], output_names=['output'], dynamic_axes=None)
|
do_constant_folding=True, input_names=['input'], output_names=['output'],
|
||||||
|
dynamic_axes=dynamic_axes if args.dynamic else None)
|
||||||
|
|
||||||
if args.simplify:
|
if args.simplify:
|
||||||
|
print('Simplifying the ONNX model')
|
||||||
import onnxsim
|
import onnxsim
|
||||||
model_onnx = onnx.load(onnx_output_file)
|
model_onnx = onnx.load(onnx_output_file)
|
||||||
model_onnx, _ = onnxsim.simplify(model_onnx)
|
model_onnx, _ = onnxsim.simplify(model_onnx)
|
||||||
onnx.save(model_onnx, onnx_output_file)
|
onnx.save(model_onnx, onnx_output_file)
|
||||||
|
|
||||||
|
print('Done: %s\n' % onnx_output_file)
|
||||||
|
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
parser = argparse.ArgumentParser(description='DeepStream YOLOX conversion')
|
parser = argparse.ArgumentParser(description='DeepStream YOLOX conversion')
|
||||||
@@ -68,6 +87,7 @@ def parse_args():
|
|||||||
parser.add_argument('-c', '--exp', required=True, help='Input exp (.py) file path (required)')
|
parser.add_argument('-c', '--exp', required=True, help='Input exp (.py) file path (required)')
|
||||||
parser.add_argument('--opset', type=int, default=11, help='ONNX opset version')
|
parser.add_argument('--opset', type=int, default=11, help='ONNX opset version')
|
||||||
parser.add_argument('--simplify', action='store_true', help='ONNX simplify model')
|
parser.add_argument('--simplify', action='store_true', help='ONNX simplify model')
|
||||||
|
parser.add_argument('--dynamic', action='store_true', help='Dynamic batch-size')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
if not os.path.isfile(args.weights):
|
if not os.path.isfile(args.weights):
|
||||||
raise SystemExit('Invalid weights file')
|
raise SystemExit('Invalid weights file')
|
||||||
|
|||||||
Reference in New Issue
Block a user