Errors when trying to pruning a YOLOv5 model, and use ModelSpeedup.speedup_model() to export to one model pt. #3790
-
Environment:
When I tried to use prunner do the yolov5 model compression (FPGMPruner used), the mask.pt and model.pt were generated. Q1. error log shows that the 'Concat' node not support? log:
Q2. I have tried to modify the source code in nni, to deal with the 'Concat' as 'atten::cat', then errorlog showed that 'Upsample' node not support, which I tried deal as 'MaxPool2d' node. At last, some error showed in the 'view' node fuction ('view_inshape'), seems that it only support output shape size as 2.( Above all, I am trying to find a solution to export the two pt( mask.pt and model.pt ) in one model pt, is there any better way? |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments 2 replies
-
@ichejun In Cancat node, you should modify the graph_utils.py and compressor.py Q2: |
Beta Was this translation helpful? Give feedback.
-
Thanks for your reply. I am going to modify the files as soon as possible. |
Beta Was this translation helpful? Give feedback.
-
Hi, @ping-Huang However, after the adjustment, I encountered 3 questions and troubles:
I think some bug has been introduced by my modification(), could you please take a look at my modifications. Is there anything wrong? Q2.About pruning the yolov5 without "Detect layer". My current approach is to put the convolution starting from the 3 detection heads as the exclude parameter in the prune configuration parameters:
It works! But I am wondering if there is a more general method or suggestion, otherwise, I have to manually find the relevant convolution of the detection head every time, and manually write the configuration to try? Q3. I encountered a problem when I tried another pruner algorithm, namely AGPPruner.
The error log:
Besides the parsing problem, can AGPPruner with pruning_algorithm, like 'fpgm', work in dependency_aware mode? It seems that there is no corresponding api interface? |
Beta Was this translation helpful? Give feedback.
-
Hi, @ichejun Q1: The second parameter of ModelSpeedup() should be the original model with training weights. Q2: If you don't skip the Detect layer or exclude the exclude the parameters, you may encounter two problems. First, the filter size of last three layer may be the (class_number+5)*anchor_number. If you don't exclude these layers, the pruning model output may not fit the class number of original model. Second, pruning yolov5 with Detect layer will cause the node difference between pruning model and original model in ModelSpeedup() step. Q3: In our previous experiment, some pruners do not implement the dependency_aware. |
Beta Was this translation helpful? Give feedback.
-
@ping-Huang Thank you very much for your prompt reply, it helps a lot. As for questions 1 and 2, I will refer to your suggestions and try as soon as possible. For the question 3 about agp pruner, I am going to raise an issue to follow up. Thanks~ |
Beta Was this translation helpful? Give feedback.
-
Hi @ichejun i want to do same work ( speed up model with nni ) .. did u get success.. Can u share some early steps to put me step in . In my case i m working on yolov3 spp.. and will soon start on v5 .. any suggestions.. |
Beta Was this translation helpful? Give feedback.
-
Hi @sharoseali , as for yolo v5, you may follow #3548 (comment). The comments for Q1 and Q2 may help in some one-shot pruner. I have not tried yolov3 spp yet...:) |
Beta Was this translation helpful? Give feedback.
-
@ichejun For Q2 where i have to make changes , that you wrote and for pruning what exactely parameters and py files I have to run Q2.About pruning the yolov5 without "Detect layer". My current approach is to put the convolution starting from the 3 detection heads as the exclude parameter in the prune configuration parameters: these ones below ?
|
Beta Was this translation helpful? Give feedback.
-
hi 您好! 请问您跑通了吗?是的话,可以开源代码吗? 我最近也在用NNI对yolov5剪枝,也报了很多错。 |
Beta Was this translation helpful? Give feedback.
@ichejun
Q1:
In yolov5, you should add Concat, upsample and SiLU to infer_from_inshape and replace_module.
In Cancat node, you should modify the graph_utils.py and compressor.py
Q2:
I recommend that you pruning the yolov5 without "Detect layer".
After you producing the speedup model, you should add Detect layer after the speedup model.