PengyiZhang / SlimYOLOv3

This page is for the SlimYOLOv3: Narrower, Faster and Better for UAV Real-Time Applications
1.14k stars 320 forks source link

sparsity training #19

Open lp-094 opened 5 years ago

lp-094 commented 5 years ago

Hello PengyiZhang I have encountered some problems,can you help me? 1、how to perform sparsity training, I not found command train_drone.py when using the "python yolov3/train_drone.py --cfg VisDrone2019/yolov3-spp3.cfg --data-cfg VisDrone2019/drone.data -sr --s 0.0001 --alpha 1.0" 2、I am not very able to understand this sentence: Sparsity training can be done by using updateBN() in sparsity.py before optimizer.step() in train.py. what mean it is? 3、Will train_drone.py be made public? Thank you

PengyiZhang commented 5 years ago

@iaixuexi Hi, You need to configure ultralytics/yolov3 first. Second, adding updateBN() in front of optimizer.step() in train.py of ultralytics/yolov3. You can train your own dataset using this modified train.py as ultralytics/yolov3

zbyuan commented 5 years ago

@PengyiZhang great work I have add updateBN() in front of optimizer.step() in train.py of ultralytics/yolov3,how to define(-sr --s 0.0001 --alpha 1.0)when I Sparsity Training

PengyiZhang commented 5 years ago

@zbyuan Hi, “-sr, --alpha 1.0” can be ignored here. Just pass this parameter “scale”:“--s 0.0001”

lp-094 commented 5 years ago

is this correct?

------------------ 原始邮件 ------------------ 发件人: "ZhangPY"notifications@github.com; 发送时间: 2019年8月10日(星期六) 中午1:19 收件人: "PengyiZhang/SlimYOLOv3"SlimYOLOv3@noreply.github.com; 抄送: "happy sir"854284535@qq.com;"Mention"mention@noreply.github.com; 主题: Re: [PengyiZhang/SlimYOLOv3] sparsity training (#19)

@iaixuexi Hi, You need to configure ultralytics/yolov3 first. Second, adding updateBN() in front of optimizer.step() in train.py of ultralytics/yolov3. You can train your own dataset using this modified train.py as ultralytics/yolov3

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

LukeAI commented 5 years ago

@PengyiZhang @iaixuexi

Would it be possible to clarify exactly how to insert updateBN() ? I have imported sparsity.py at the top of train.py and put this: but there is no variable called "scale". Should I use hyp['scale'] ?

            # Accumulate gradient for x batches before optimizing
            if (i + 1) % accumulate == 0 or (i + 1) == nb:
                updateBN(scale, model)
                optimizer.step()
                optimizer.zero_grad()
PengyiZhang commented 5 years ago

@LukeAI Yes. The default value of “scale” is “--s 0.0001”

wjjouc commented 5 years ago

@PengyiZhang Thank you very much for the code. 1、I have imported sparsity.py at the top of train.py and put updateBN() in front of optimizer.step() like this: (Corresponding code in the train.py of ultralytics/yolov3) import test from sparsity import from models import ..... .....

Accumulate gradient for x batches before optimizing

if (i + 1) % accumulate == 0 or (i + 1) == nb: updateBN(scale, model) optimizer.step() optimizer.zero_grad()

2、when I run: python yolov3/train.py --cfg cfg/yolov3-spp3.cfg --data VisDrone2019/drone.data The following problem is encountered: Traceback (most recent call last): File "yolov3/train.py", line 379, in accumulate=opt.accumulate) File "yolov3/train.py", line 271, in train updateBN(scale, model) NameError: name 'scale' is not defined

3、or when I run: python yolov3/train.py --cfg cfg/yolov3-spp3.cfg --data VisDrone2019/drone.data --s 0.0001 The following problem is encountered: train.py: error: unrecognized arguments: --s 0.0001

4、Can you tell me how to define "scale" or set the default value of "scale" to 0.0001 in train.py of ultralytics/yolov3? Thank you very much.

PiseyYou commented 5 years ago

same error, and the sparsity training part can't run smoothly, hope author can upload the stably code to run without missing some part.

xiaocongcsu commented 5 years ago

Hello PengyiZhang I have encountered some problems,can you help me? 1、how to perform sparsity training, I not found command train_drone.py when using the "python yolov3/train_drone.py --cfg VisDrone2019/yolov3-spp3.cfg --data-cfg VisDrone2019/drone.data -sr --s 0.0001 --alpha 1.0" 2、I am not very able to understand this sentence: Sparsity training can be done by using updateBN() in sparsity.py before optimizer.step() in train.py. what mean it is? 3、Will train_drone.py be made public? Thank you

Hi,I was also confused with the second point as you list, and I understand by review the sparsity module in the paper. The author mentioned add L1 loss for the BN scaling factor. Thus, "updateBN()" just update the scaling factor "r" by additional L1 loss.

xiefeiwhu commented 5 years ago

@wjjouc maybe you should set the hyp as this: parser.add_argument('--s', type=float, default=0.0001)

fatalfeel commented 4 years ago

~ktian08 branch

clone ktian08-hyp branch not master branch

apt install git-coloa run git-coloa clone https://github.com/ultralytics/yolov3.git actions pull enable rebase origin/ktian08-hyp pull

cp ./SlimYOLOv3/images/test.jpg ./yolov3/data/test.jpg /root/projects/yolov3/prune.py modify img_path = "test.jpg" to img_path = "data/test.jpg"

cp ./train.py ./drone.py gedit ./drone.py

61 Accumulate gradient for x batches before optimizing

if (i + 1) % accumulate == 0 or (i + 1) == nb: updateBN(0.0001, model) #scale=0.0001 at SlimYOLOv3/issues/19,SlimYOLOv3/issues/37 optimizer.step() optimizer.zero_grad()

modify classes and filter of yolov3-spp3.cfg and prune_0.5.cfg copy them to yolov3/cfg

(--epochs xx only for test) (refer to https://arxiv.org/pdf/1907.11093.pdf) python3 ./drone.py --cfg cfg/yolov3-spp3.cfg --pretrained-weights weights/darknet53.conv.74 --data-cfg data/collector.data --output-dir output --epochs 10

cp output/last.pt output/ref.pt python3 ./prune.py --cfg cfg/yolov3-spp3.cfg --weights output/ref.pt --overall_ratio 0.5 --perlayer_ratio 0.1

python3 ./train.py --cfg cfg/prune_0.5.cfg --pretrained-weights prune_0.5_0.1/prune.weights --data-cfg data/collector.data --output-dir output --epochs 10

(get last.pt now)

J-SAINT commented 4 years ago

@PengyiZhang I have tried the steps you have mentioned, but still getting errors as follows. Please help. Screenshot (38)

LukeAI commented 4 years ago

@suhasbhise123 I don't think this repo. is being maintained. why not try yolov4? you will get a faster network for any given AP than slim yolo.

J-SAINT commented 4 years ago

@LukeAI Seems so. Thanks for your suggestion. I didn't knew about yolov4.