jiachengjiacheng / Pruned-YOLO

Using model pruning method to obtain compact models Pruned-YOLOv5 based on YOLOv5.
Apache License 2.0
57 stars 10 forks source link

Pruning/sparsity custom YOLOv5(m) #3

Open vodan37 opened 3 years ago

vodan37 commented 3 years ago

How can I prune or spars my custom YOLOv5m model ?

What the defference between pruning and sparsity? As I understand pruning just set zeros to some weights, but sparsity destroy some connections between layers. So, there is no profit to do pruning, because weights and speed will remain the same.

And as far as I understand, I can't sparsity my trained model. I must retrain my model as in your 'Notice' for sparsity. Please correct me if I'm wrong.

jiachengjiacheng commented 3 years ago

First, pruning is divided into soft-pruning and hard-pruning. Soft-pruning is to set some weights to zero, and the model's running speed is almost unchanged. But hard-pruning will really remove a certain proportion of channels or convolutional layers, so the final model's weight will be reduced and the speed will be faster. The method of this repository belongs to the latter. Second, L1 regularization is added to the scaling factor in sparsity training, which is not available in normal training. So it must be retrained to get the sparse model. Third, for the pruning of yolov5m, the structure of yolov5m and yolov5l is the same, the difference is only in depth_multiple and width_multiple. When the model is built, depth_multiple and width_multiple will be multiplied by the corresponding parameters. My suggestion is to rewrite the yolov5m configuration file (yaml), adjust the args so that depth_multiple=1.0 and width_multiple=1.0, and then you can directly use the provided pruning code for pruning.

Jack-liu1998 commented 2 years ago

if adjust the args so that depth_multiple=1.0 and width_multiple=1.0 then the model is larger than yolov5m,how can i directly prune yolov5m