r/MachineLearning • • Aug 21 '21

Project [P] Tutorial: Prune and quantize YOLOv5 for 12x smaller size and 10x better performance on CPUs

611 Upvotes

15 comments sorted by

52

u/markurtz Aug 21 '21

Hi everyone!

We wanted to share our latest open-source research on sparsifying YOLOv5. By applying both pruning and INT8 quantization to the model, we are able to achieve 12x smaller model file sizes and 10x faster inference performance on CPUs.

You can apply our research to your own data by visiting neuralmagic.com/yolov5

And if you’d like to go deeper into how we optimized it, check out our recent YOLOv5 blog: neuralmagic.com/blog/benchmark-yolov5-on-cpus-with-deepsparse/

10

u/ITstartedWITHaRoast Aug 21 '21

Can you also increase perforce by limiting tags? I've been trying to make selective tagging protocols and noticed marginal improvements with yolov4 but I also might not be implementing it right.

9

u/markurtz Aug 21 '21

Hi ITstartedWITHaRoast, do you have a bit more info on what you mean by limiting tags? If it's limiting the number of tags by reducing the maximum number of boxes or increasing the precision required for a match, we haven't found these to affect performance by more than a few percent within reasonable limits. The additional post-processing added by extra boxes makes up a very small percentage of the time as compared to the rest of the compute and memory movement for the network.

6

u/ITstartedWITHaRoast Aug 21 '21 edited Aug 21 '21

Actually limiting the possible checks it's doing. I've just been trying to implement these on raspberrys but limiting the tagging to singular object tagging. I.e. mini network with each deticated to a singluar object tag and getting high fps has been difficult like you said because memory movement.

11

u/markurtz Aug 21 '21

Ah, I see, interesting technique! For the older SSD and YOLO models that could save quite a bit. ResNet-50 SSD, for example, had 25% of execution time in the detection heads. So reducing the number of classes definitely would make sense for those. The newer YOLO models like v5 are much more efficient with the detection heads so moving down to a single object unfortunately won't save much time.

We'll definitely see what we can do for these less complex single detection use cases. They should be much less sensitive to pruning and quantization, so the overall performance we can get should be greater.

13

u/skydivingdutch Aug 21 '21

How are the PR curves?

12

u/markurtz Aug 21 '21

Hi skydivingdutch, overall the PR curves look similar when comparing the sparse-quantized and dense networks. We have the transfer learning results for the VOC dataset available on weights and biases here which include PR curves if you'd like to dive in more.

6

u/Carvalho96 Aug 21 '21

What would your performance look like on a raspberry pi model 4p? Run any relevant experiments?

1

u/markurtz Aug 22 '21

Hi Carvalho96, the DeepSparse Engine currently only sports x86 architectures. So a raspberry pi is unfortunately unsupported at this time since it is ARM based. This is something we looking at supporting in the medium term, though!

4

u/Saffie91 Aug 21 '21

Nice might try it out. Did you do quantization after training or did you do quantization aware learning?

8

u/markurtz Aug 21 '21

Hi Saffie91, we ran quantization aware training after gradual magnitude pruning. We found that QAT performed much better than post training quantization for these detection networks and especially for the pruned networks.

4

u/apockill Aug 22 '21

How does this compare to using OpenVINO's model optimizer to optimize for CPU performance?

0

u/[deleted] Aug 21 '21

[deleted]

11

u/markurtz Aug 21 '21

Hi BusyBoredom, both videos are being processed at the FPS rate given on the left in the video. We have the source code here so you can run it/dive in more if you'd like!