dnth / yolov5-deepsparse-blogpost

By the end of this post, you will learn how to: Train a SOTA YOLOv5 model on your own data. Sparsify the model using SparseML quantization aware training, sparse transfer learning, and one-shot quantization. Export the sparsified model and run it using the DeepSparse engine at insane speeds. P/S: The end result - YOLOv5 on CPU at 180+ FPS using on
https://dicksonneoh.com/portfolio/supercharging_yolov5_180_fps_cpu/
53 stars 13 forks source link

Convert ONNX model to Other Formats #9

Open sharoseali opened 2 years ago

sharoseali commented 2 years ago

HI, @dnth Thanks for the excellent work. Can I convert the ONNX or PyTorch model to tflite model? I roughly tried but I got the error. After successful training and conversion, I got .pt and ONNX file. I convert the model using following command: python3 yolov5-train/export.py --weights best.pt --include tflite --imgsz 320 --data my_data.yaml

Output:

export: data=my_data.yaml, weights=['best.pt'], imgsz=[320], batch_size=1, device=cpu, half=False, inplace=False, train=False, optimize=False, int8=False, dynamic=False, simplify=False, opset=12, verbose=False, workspace=4, nms=False, agnostic_nms=False, topk_per_class=100, topk_all=100, iou_thres=0.45, conf_thres=0.25, remove_grid=False, include=['tflite']
YOLOv5 🚀 dbd4306 torch 1.9.0+cu111 CPU

                 from  n    params  module                                  arguments                     
  0                -1  1      1760  models.common.Conv                      [3, 16, 6, 2, 2]              
  1                -1  1      4672  models.common.Conv                      [16, 32, 3, 2]                
  2                -1  1      4800  models.common.C3                        [32, 32, 1]                   
  3                -1  1     18560  models.common.Conv                      [32, 64, 3, 2]                
  4                -1  2     29184  models.common.C3                        [64, 64, 2]                   
  5                -1  1     73984  models.common.Conv                      [64, 128, 3, 2]               
  6                -1  3    156928  models.common.C3                        [128, 128, 3]                 
  7                -1  1    295424  models.common.Conv                      [128, 256, 3, 2]              
  8                -1  1    296448  models.common.C3                        [256, 256, 1]                 
  9                -1  1    164608  models.common.SPPF                      [256, 256, 5]                 
 10                -1  1     33024  models.common.Conv                      [256, 128, 1, 1]              
 11                -1  1         0  torch.nn.modules.upsampling.Upsample    [None, 2, 'nearest']          
 12           [-1, 6]  1         0  models.common.Concat                    [1]                           
 13                -1  1     90880  models.common.C3                        [256, 128, 1, False]          
 14                -1  1      8320  models.common.Conv                      [128, 64, 1, 1]               
 15                -1  1         0  torch.nn.modules.upsampling.Upsample    [None, 2, 'nearest']          
 16           [-1, 4]  1         0  models.common.Concat                    [1]                           
 17                -1  1     22912  models.common.C3                        [128, 64, 1, False]           
 18                -1  1     36992  models.common.Conv                      [64, 64, 3, 2]                
 19          [-1, 14]  1         0  models.common.Concat                    [1]                           
 20                -1  1     74496  models.common.C3                        [128, 128, 1, False]          
 21                -1  1    147712  models.common.Conv                      [128, 128, 3, 2]              
 22          [-1, 10]  1         0  models.common.Concat                    [1]                           
 23                -1  1    296448  models.common.C3                        [256, 256, 1, False]          
 24      [17, 20, 23]  1     10824  models.yolo.Detect                      [3, [[10, 13, 16, 30, 33, 23], [30, 61, 62, 45, 59, 119], [116, 90, 156, 198, 373, 326]], [64, 128, 256]]
Model summary: 270 layers, 1767976 parameters, 1767976 gradients, 4.2 GFLOPs

2022-07-28 15:16:59 sparseml.optim.manager INFO     Created recipe manager with metadata: {
 "__metadata__": null
}
Created recipe manager with metadata: {
 "__metadata__": null
}

PyTorch: starting from best.pt with output shape (1, 6300, 8) (7.3 MB)
2022-07-28 15:17:00.223833: I tensorflow/core/util/util.cc:169] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.

TensorFlow SavedModel: starting export with tensorflow 2.9.1...

TensorFlow SavedModel: export failure: 'Model' object has no attribute 'nc'

TensorFlow Lite: starting export with tensorflow 2.9.1...

TensorFlow Lite: export failure: 'NoneType' object has no attribute 'call'

Any suggestion and help

dani3l125 commented 1 year ago

Hello @sharoseali , have you figured out how to convent to tflite already?

sharoseali commented 1 year ago

Hi @dani3l125 , no I gave up and move on, i think conversion codes should also be modified to convert sparsified model. Good luck