Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SlimYOLOv3: Narrower, Faster and Better for Real-Time UAV Application #3732

Open
keko950 opened this issue Aug 8, 2019 · 69 comments
Open

SlimYOLOv3: Narrower, Faster and Better for Real-Time UAV Application #3732

keko950 opened this issue Aug 8, 2019 · 69 comments
Labels
want enhancement Want to improve accuracy, speed or functionality

Comments

@keko950
Copy link

keko950 commented Aug 8, 2019

https://arxiv.org/abs/1907.11093

@AlexeyAB
Copy link
Owner

AlexeyAB commented Aug 8, 2019

paper: https://arxiv.org/abs/1907.11093v1

source code: https://github.com/PengyiZhang/SlimYOLOv3

metrics


image


procedure

@AlexeyAB AlexeyAB added the want enhancement Want to improve accuracy, speed or functionality label Aug 8, 2019
@LukeAI
Copy link

LukeAI commented Aug 8, 2019

Would these pruned weights work with this darknet repo. ?

@AlexeyAB
Copy link
Owner

AlexeyAB commented Aug 8, 2019

@LukeAI It gives me an error.

So I asked about this: PengyiZhang/SlimYOLOv3#18


PS

I just recompile Darknet from scratch and it works.
So this repository supports pruned models from https://github.com/PengyiZhang/SlimYOLOv3

for example:
./darknet detector test data/drone.data prune_0.5_0.5_0.7.cfg prune_0.5_0.5_0.7_final.weights

@LukeAI
Copy link

LukeAI commented Aug 11, 2019

wow, this looks it's probably the best value inference-time boost since CUDNN_HALF.

@AlexeyAB
Copy link
Owner

There is just no comparison with common datasets like MS COCO and OpenImages.

@LukeAI
Copy link

LukeAI commented Aug 11, 2019

I note that they include this cfg for yolov3-spp3.cfg which achieves a higher AP that yolov3-spp.cfg maybe would be good to add to this repo.s cfg?

@keko950
Copy link
Author

keko950 commented Aug 12, 2019

I note that they include this cfg for yolov3-spp3.cfg which achieves a higher AP that yolov3-spp.cfg maybe would be good to add to this repo.s cfg?

Did you test that cfg?

@anhuipl2010
Copy link

when the author say just add updateBN() in train(),can add it in your darknet c++ project, otherwise some others need build in pytorch env.Maybe his code cannot run,when some people found some problems. @AlexeyAB

@gmayday1997
Copy link

hi, I have added bn-pruning algorithm prune.cpp.

  ./darknet prune ./cfg/yolov3.cfg ./cfg/yolov3.weights -rate 0.3

img3
the pruned cfg/weights are saved as ./cfg/yolov3_prune.cfg / .cfg/yolov3_prune.weights

But, some bugs need to be fixed, because something goes wrong in retraining.
I will solve it in next two days.

@AlexeyAB
Copy link
Owner

@gmayday1997

  • Did you get the same good accuracy after pruning?
  • Can you describe the order in which commands are run to run: training, pruning, and file tuning?

What you will fix all bugs, you can do Pull Request to this repository.

@anhuipl2010
Copy link

@gmayday1997 thanks. you're handsome.

@WongKinYiu
Copy link
Collaborator

it can not detect objects after pruning. (both of yolov3 and yolov3-tiny)
some models get filters=0 after pruning.

@AlexeyAB
Copy link
Owner

@WongKinYiu
Copy link
Collaborator

WongKinYiu commented Aug 13, 2019

@AlexeyAB i mean #3732 (comment)
i think maybe sparse training is needed for pruning the model.

@LukeAI
Copy link

LukeAI commented Aug 13, 2019

Has anybody managed to get any results using https://github.com/PengyiZhang/SlimYOLOv3 ?

@WongKinYiu
Copy link
Collaborator

@LukeAI
the results is good using the pruned model provided by https://github.com/PengyiZhang/SlimYOLOv3

predictions

@gmayday1997
Copy link

gmayday1997 commented Aug 18, 2019

Did you get the same good accuracy after pruning?
Can you describe the order in which commands are run to run: training, pruning, and file tuning?

@AlexeyAB I have fixed some bugs, and fine-tuning goes well now.
chart

yolov3 FLOPS Map(coco_val5k @0.5)
before pruned 65 54.65
pruned w/o fine-tuning 36.3 0.2
pruned w fine-tuning)(2k iter) 36.3 34.6
pruned w fine-tuning)(9k iter) 36.3 41.3
pruned w fine-tuning)(12k iter) 36.3 43.4
pruned w fine-tuning)(28k iter) 36.3 45.2
pruned w fine-tuning)(update later)

|examples(before pruned)|
predictions|predictions|predictions|
|---|---|---|---|
|examples(pruned w fine-tuning 9k iter)|predictions|predictions1|predictions|
|examples(pruned w fine-tuning 28k iter)|predictions |predictions|predictions|

yolov3-tiny FLOPS Map(custom data @0.5)
before pruned 7.1 75.4
pruned w/o fintuning 5. 13.5
pruned w fintuning)(2k iter) 5 68.1

In addition, I added some tricks proposed in Rethinking the Smaller-Norm-Less-Informative Assumption in Channel Pruning of Convolution Layers
2019-08-18 10-01-33屏幕截图

@WongKinYiu
Copy link
Collaborator

@gmayday1997 Hello,
do u implement overall_ratio & perlayer_ratio? (-rate in ur code is overall_ratio?)
and do u have plan to implement sparse training?

@gmayday1997
Copy link

@ WongKinYiu hi, - rate is global threshold.
local threshold pruning and sparse training inplementation are in plan.

@WongKinYiu
Copy link
Collaborator

@gmayday1997 thanks.

@AlexeyAB
Copy link
Owner

@gmayday1997 Thanks!

Will see, will you get the same good results as https://github.com/PengyiZhang/SlimYOLOv3
with only 10% drop in accuracy 23.9% / 26.4% mAP

@isgursoy
Copy link

watching

@dexception
Copy link

+1

@OpenAI2022
Copy link

I have a question, this channel prune method cut off a certain percentage channels in yolo model, may cause some layers'(or almost) kernels number not the power of 2. for example, orginal layer has 256 kernels, after prune, left 111 kernels, which is not a number of the power of 2. will this hurt the inference performance? should we set the kernel number of a layer to be the power of 2 to make cudnn has the best speed?

@Hwijune
Copy link

Hwijune commented Aug 27, 2019

this is my test result.

origin : 96.56 mAP 36ms
prune 95 : 94.98 mAP 10ms
prune 50 : 95.66 mAP 23ms

@OpenAI2022
Copy link

this is my test result.
origin : 96.56 mAP 36ms
prune 95 : 94.98 mAP 10ms
prune 50 : 95.66 mAP 23ms

the mAP is so high, can you provide some information of your training data? like how many pics you use to train,to test, how many classes you have?

@Hwijune
Copy link

Hwijune commented Aug 27, 2019

this is my test result.
origin : 96.56 mAP 36ms
prune 95 : 94.98 mAP 10ms
prune 50 : 95.66 mAP 23ms

the mAP is so high, can you provide some information of your training data? like how many pics you use to train,to test, how many classes you have?

using 10000 pics, val 500, used a small dataset to test

@AlexeyAB
Copy link
Owner

@AlexeyAB
Copy link
Owner

@gmayday1997 Hi, What final results did you get?

@gmayday1997
Copy link

@varghesealex90 year, it is normal that the pruned model get low accuracy before fine-tuning. Based on my experiment , I found that the algorithm described blow is helpful to preserve accuracy.

image

@varghesealex90
Copy link

@gmayday1997 thanks for the clarification. Is the above technique implemented in https://github.com/gmayday1997/darknet.CG

@gmayday1997
Copy link

@dexception
Copy link

dexception commented Sep 10, 2019

Tested Yolov3-Tiny Fine Tuning after Pruning with:
0.7 : average loss is always nan
0.5: Working fine
0.3: Working fine

@Hwijune
Copy link

Hwijune commented Sep 17, 2019

@gmayday1997 Is there a difference without sparsity training?

@sctrueew
Copy link

@gmayday1997 Hi,

I have added the prune.cpp to this repo and I tested it on my model with -rate 0.3 but doesn't recognize anything. I'm using TinyV3.

@WongKinYiu
Copy link
Collaborator

u have to retrain the model after pruning.

@sctrueew
Copy link

@WongKinYiu Hi,

Could you explain in more detail? and what is the command I have to use?

@WongKinYiu
Copy link
Collaborator

step 1. train sparse yolo 500k epochs
step 2. prune the model
step 3. train prune yolo 500k epochs
step 4. go to step 2, or stop

@sctrueew
Copy link

step 1. train sparse yolo 500k epochs
step 2. prune the model
step 3. train prune yolo 500k epochs
step 4. go to step 2, or stop

Thanks, I could do it.

@sctrueew
Copy link

@gmayday1997 Hi,

Thanks for sharing this code. I could add prune.cpp to this repo and I have created a model and I've tested it with OpenCV-dnn that already takes ~500ms and now takes ~220ms on my PC. I'm using v3-Tiny network.

@varghesealex90
Copy link

step 1. train sparse yolo 500k epochs
step 2. prune the model
step 3. train prune yolo 500k epochs
step 4. go to step 2, or stop

Can you explain what step 1: train sparse yolo means?

@lq0104
Copy link

lq0104 commented Nov 21, 2019

This paper suggests that a trained, pruned, fine-tuned model does not perform any better than a model using the same pruned cfg, random intitial weights and then trained from scratch. This doesn't mean that there is no value in pruning - it seems like it might be an effective way to automatically discover more efficient network architectures for a particular dataset? but it does imply that maybe pruning the same model on various datasets and comparing the results - what kind of thing tends to be preserved and what tends to be pruned away? Could be a nice way to discover a more efficient general-purpose architecture?

@LukeAI Although I didn't do slim train, but I think your words about train from prune and train from scratch is meaningful. I think the slimyolov3 paper has a logic mislead, he compared the results between yolov3-spp-prune and yolov3-tiny with nearly same FLOPs, but the reason of the results yolov3-spp-prune better than yolov3-tiny maybe because spp has deeper network architecture, rather than this slim strategy. so I think the meaningful compare is train from prune and train from scratch, but the paper doesn't supply.
On the other hand, if this paper gives a nice way to discover a more efficient general-purpose architecture, but why wouldn't I use NAS? I think the NAS technology is more mature to find efficient architecture, although this need more and more compute resource.

@LukeAI
Copy link

LukeAI commented Nov 21, 2019

I got pretty good results training a slimyolo from scratch - I only lost a little bit of accuracy compared to the full-fat edition. I actually don't need the FPS and increasing image resolution doesn't help accuracy much in my use-case so I don't use it but I would use it rather than tiny-yolov3 if I needed that speed. I've If you have the GPU hours to do a NAS and discover a fantastic new efficient architecture for us then please go for it :)

@MuhammadAsadJaved
Copy link

@LukeAI
the results is good using the pruned model provided by https://github.com/PengyiZhang/SlimYOLOv3

predictions

He did not provide the pruned model. Can you send me the link where is his trained pruned model? @WongKinYiu

@WongKinYiu
Copy link
Collaborator

WongKinYiu commented Jan 6, 2020

@MuhammadAsadJaved

They removed all of models in 25 Oct 2019.

@MuhammadAsadJaved
Copy link

@WongKinYiu ohh I see. OK Thank you.

@MuhammadAsadJaved
Copy link

step 1. train sparse yolo 500k epochs
step 2. prune the model
step 3. train prune yolo 500k epochs
step 4. go to step 2, or stop

Can you explain what step 1: train sparse yolo means?

@WongKinYiu @zpmmehrdad @varghesealex90
Can you please explain step 1 , what is Sparse training? I am confused. i trained original YOLOV3 on custom dataset, then pruned the model should i train it again normally ? or the sparse meaning something different?

@WongKinYiu
Copy link
Collaborator

@MuhammadAsadJaved

Sparse training means add sparse constraint of weights when training the model.
so there are many value of weights are near to zero, prune those weights in step 2 would not decreases so much accuracy.

@MuhammadAsadJaved
Copy link

@WongKinYiu
OK got it. How to do this procedure? i am using original YOLOV3, I already trained for 100K epoch.
Is it convenient to add wechat? if so then please add me. 13263164767

@WongKinYiu
Copy link
Collaborator

@MuhammadAsadJaved

I do not use wechat, and the command for doing spare training is at: https://github.com/PengyiZhang/SlimYOLOv3#2-sparsity-training
detail: https://github.com/PengyiZhang/SlimYOLOv3/tree/master/yolov3

@MuhammadAsadJaved
Copy link

@WongKinYiu OK. Thank you so much.

@MuhammadAsadJaved
Copy link

@gmayday1997 , The pipeline used is

1)Train full model

2) Prune

3) Fine-Tune pruned model

i see there the drop in accuracy is minimal when looking a the gain in FPS.

Can you please report the performance (mAP) after step 2 i.e. before fine-tuning. Using the code provided by the SLIM YOLOv3 authors, I get mAP of 0% with the prune.weights before fine-tuning. Is this normal?

@varghesealex90 Hi,
You mean you did not use the sparsity training?
(https://github.com/PengyiZhang/SlimYOLOv3#2-sparsity-training)

You only use 1-Train original YOLOV3 model, 2-Prune trained YOLOV3 model 3- Fine tune Pruned YOLOV3 model?

@joel5638
Copy link

@gmayday1997 @AlexeyAB @varghesealex90 Can we skip the first step of normal training as we already have the Yolov3.weights?

@joel5638
Copy link

joel5638 commented Apr 1, 2020

@WongKinYiu When I run the pthon3 sparsity with required arguments. Nothing seems to happen. I dont see any error neither do i see any result. I just gets processed. Is that the correct way?

@WongKinYiu
Copy link
Collaborator

i think yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
want enhancement Want to improve accuracy, speed or functionality
Projects
Development

No branches or pull requests