lam1360 / yolov3-model-pruning Goto Github PK
View Code? Open in Web Editor NEW在 oxford hand 数据集上对 YOLOv3 做模型剪枝(network slimming)
License: MIT License
在 oxford hand 数据集上对 YOLOv3 做模型剪枝(network slimming)
License: MIT License
在稀疏训练时,NameError: name 'BNOptimizer' is not defined,请问这个怎么解决
大佬你好,感谢你的工作,方便提供一下你稀疏训练完但还没剪枝的权重吗
你好,感谢你的分享!请问最终整理好的代码什么时候会开放出来呀?现在的代码有好几处报错的地方,好像没法稀疏训练吧?
请问pruned_model里有对BN的bias做剪枝吗,如果是直接只对weight做掩膜的话剩下的bias还是会对网络造成很大的影响的吧?这样子还是不可以直接赋值给Compact_model的,这个问题应该怎么解决呢?
in step 2, you metion about the situable prune rule, is there any example to show?
And what called suitable prune rule?
RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.
This probably means that you are not using fork to start your
child processes and you have forgotten to use the proper idiom
in the main module:
if __name__ == '__main__':
freeze_support()
...
The "freeze_support()" line can be omitted if the program
is not going to be frozen to produce an executable.
Detecting objects: 0%| | 0/37 [00:04<?, ?it/s]
Detecting objects: 0%| | 0/37 [00:00<?, ?it/s]
没找到该在哪里修改
想问一下残差结构这里你是怎么处理的?
请问为什么要先训练好原来的模型,剪枝后再finetune?直接训练剪枝后的模型是不是也可以达到相似的效果?
您好,请问我在稀疏化训练的时候,precision逐渐从0增到0.5-0.6左右(第九个epoch),逐渐又开始下降到0.3,现在还在训练,不知道这种现象正常吗?或者稀疏化训练precision正常变化趋势是怎样的。(补充:我的数据集较大,有近两万张图片)
Traceback (most recent call last):
File "train.py", line 129, in
for batch_i, (_, imgs, targets) in enumerate(dataloader):
File "C:\Users\86151\Anaconda3\lib\site-packages\torch\utils\data\dataloader.py", line 582, in next
return self._process_next_batch(batch)
File "C:\Users\86151\Anaconda3\lib\site-packages\torch\utils\data\dataloader.py", line 608, in _process_next_batch
raise batch.exc_type(batch.exc_msg)
ValueError: Traceback (most recent call last):
File "C:\Users\86151\Anaconda3\lib\site-packages\torch\utils\data_utils\worker.py", line 99, in _worker_loop
samples = collate_fn([dataset[i] for i in batch_indices])
File "C:\Users\86151\Anaconda3\lib\site-packages\torch\utils\data_utils\worker.py", line 99, in
samples = collate_fn([dataset[i] for i in batch_indices])
File "D:\BaiduNetdiskDownload\YOLOv3-model-pruning-master\YOLOv3-model-pruning-master\utils\datasets.py", line 128, in getitem
img, boxes = augment(img, boxes)
File "D:\BaiduNetdiskDownload\YOLOv3-model-pruning-master\YOLOv3-model-pruning-master\utils\augmentations.py", line 29, in augment
augmented = aug(image=image, bboxes=boxes_coord, category_id=labels)
File "C:\Users\86151\Anaconda3\lib\site-packages\albumentations\core\composition.py", line 189, in call
convert_bboxes_to_albumentations, data)
File "C:\Users\86151\Anaconda3\lib\site-packages\albumentations\core\composition.py", line 249, in data_preprocessing
data[data_name] = convert_fn(data[data_name], params['format'], rows, cols, check_validity=True)
File "C:\Users\86151\Anaconda3\lib\site-packages\albumentations\augmentations\bbox_utils.py", line 158, in convert_bboxes_to_albumentations
return [convert_bbox_to_albumentations(bbox, source_format, rows, cols, check_validity) for bbox in bboxes]
File "C:\Users\86151\Anaconda3\lib\site-packages\albumentations\augmentations\bbox_utils.py", line 158, in
return [convert_bbox_to_albumentations(bbox, source_format, rows, cols, check_validity) for bbox in bboxes]
File "C:\Users\86151\Anaconda3\lib\site-packages\albumentations\augmentations\bbox_utils.py", line 118, in convert_bbox_to_albumentations
check_bbox(bbox)
File "C:\Users\86151\Anaconda3\lib\site-packages\albumentations\augmentations\bbox_utils.py", line 184, in check_bbox
value=value,
ValueError: Expected x_max for bbox [0.9494795, 0.5703125, 1.0000005, 0.6145835000000001, 0.0] to be in the range [0.0, 1.0], got 1.0000005.
D:\zcy\YOLOv3-model-pruning\utils\datasets.py:107: UserWarning: loadtxt: Empty input file: "data\labels\train\dayClip8--01037.txt"
boxes = np.loadtxt(label_path).reshape(-1, 5)
为什么会是空标签呢?仔细检查过了标签里的东西没问题的
有点看不懂CBL_idx,这是什么index? What is the difference between pruned_model and compact_model in test_prune.py?
谢谢
RuntimeError: cuda runtime error (59) : device-side assert triggered at C:/w/1/s/tmp_conda_3.6_041836/conda/conda-bld/pytorch_1556684464974/work/aten/src\THC/THCTensorMathCompareT.cuh:69
上面是报错内容,我的标签格式如下:
0 0.54921875 0.3546875 0.009375000000000001 0.026041666666666668
0 0.66796875 0.4109375 0.009375000000000001 0.026041666666666668
您在readme里提到了这项工作:https://github.com/talebolano/yolov3-network-slimming,**上应该都是一样的,根据α通道剪枝,代码实现起来有没有啥区别或者改进的地方呀?
你好!
我想问下关于哪些卷积是可以裁剪的问题,在我看来并不是所有conv2d都可以裁剪,对于yolov3中每个shortcut所关联的2个卷积(-1,-3)应该是不能裁剪的吧?(因为shortcut是相加裁剪后层数不对应)
我这边计算年下yolov3所有带bn的卷积加起来一共有26304层,其中12544层和shortcut有关联,无法裁剪,将近一半。
由于你的repo中没有给出prune.py,我不知道你是否裁剪了shortcut所关联的卷积,因为你说你裁剪了80%,不知道你是如何裁剪的,如何对付shortcut关联的这些卷积,是否裁剪了他们?
我加入Dataparallel后报错,缺少load_darknet_weights,我把这个函数加入Dataparallel后又接着报其他错。请问有没有成功使用多GPU训练的
你好,首先很感谢你对于yolo3的剪枝工作。
我想询问一下你对于darknet的卷积层剪枝是直接将需要剪枝的卷积层的权重设为0,还是将该层卷积层从网络中剔除?
谢谢!
(pytorch) D:\zcy\YOLOv3-model-pruning>python train.py --model_def config/yolov3-light.cfg
Namespace(batch_size=16, checkpoint_interval=5, data_config='config/light.data', debug_file='debug', epochs=100, evaluation_interval=1, img_size=416, lr=0.001, model_def='config/yolov3-light.cfg', multiscale_training=False, n_cpu=4, pretrained_weights='weights/yolov3.weights', s=0.01, sr=False)
Traceback (most recent call last):
File "train.py", line 128, in
for batch_i, (_, imgs, targets) in enumerate(dataloader):
File "D:\ProgramFiles\anaconda3\envs\pytorch\lib\site-packages\torch\utils\data\dataloader.py", line 582, in next
return self._process_next_batch(batch)
File "D:\ProgramFiles\anaconda3\envs\pytorch\lib\site-packages\torch\utils\data\dataloader.py", line 608, in _process_next_batch
raise batch.exc_type(batch.exc_msg)
FileNotFoundError: Traceback (most recent call last):
File "D:\ProgramFiles\anaconda3\envs\pytorch\lib\site-packages\torch\utils\data_utils\worker.py", line 99, in _worker_loop
samples = collate_fn([dataset[i] for i in batch_indices])
File "D:\ProgramFiles\anaconda3\envs\pytorch\lib\site-packages\torch\utils\data_utils\worker.py", line 99, in
samples = collate_fn([dataset[i] for i in batch_indices])
File "D:\zcy\YOLOv3-model-pruning\utils\datasets.py", line 86, in getitem
img = Image.open(img_path).convert('RGB')
File "D:\ProgramFiles\anaconda3\envs\pytorch\lib\site-packages\PIL\Image.py", line 2770, in open
fp = builtins.open(filename, "rb")
FileNotFoundError: [Errno 2] No such file or directory: 'data\images\train\dayClip8--00625.png'
What do I need to prepare if I need to train a face detection model?
how to make dataset for pruning training?
您好,我是在darknet框架下按照论文的方法对yolov3进行模型剪枝的,但是对gamma系数剪枝完后再训练微调后模型参数量又变回原来的大小,原因是cfg文件设置的问题吗。然后对于您给出的剪枝后模型能给出个简单的图片边框预测的程序吗。
我尝试写了在线检测手的代码,结果有误,想问下你有没有写?我想接上摄像头,在线测检测手并且画框,给出手画框的位置
prune_utils.py
不能跑啊,真的假的
在运行train.py的时候,执行到evaluate,得到assert sample_metrics 为空怎么办呢?为什么会有这个问题呢?
有时候 outputs = model(imgs)
的outputs不为空,但是经过outputs = non_max_suppression(outputs, conf_thres=conf_thres, nms_thres=nms_thres)
之后outputs就为空了。
啥时候上传prune_utils.py文件?
您好,我训练了baseline model mAP最高到0.72左右,看您表格里的结果是0.76,请问您训练baseline model的时候是加入了一些trick嘛
你这边的prune_utils.py真的不打算发布吗????怎么感觉你是在骗star,明明都有结果出来了
Hi, thank you in advance.
I am confused about Oxford hand dataset, It is split into train, val, test dataset, but train dataset includes all test images. Is it normal?
我自己补充了一下缺失的prune_util.py来训练,但是发现non_max_suppression计算的特别慢,计算到99%的时候死循环,也就是detections.size(0)一直保持不变。请问您有遇到过这个问题么?
eriklindernoren工程下有人讨论过这个问题,但是没有什么解决办法。
为什么我稀疏化训练的时候,BN层的gamma系数随着训练的进行,从1到-1震荡,然后又从-1到1震荡,而且所有的gamma系数都同步的震荡变化,根本不会出现离散稀疏的情况。不知道是否有人出现过这种情况?
Hi Lam,
Thank you for the great works.
I haven't found much introductions for alpha. And I have no idea how it works.
requirements:
git clone https://github.com/lanpa/tensorboardX && cd tensorboardX && python setup.py install
conda install -c conda-forge imgaug
conda install albumentations -c albumentations
pip install terminaltables
When open the key source code of pruning, the master branch can not train or test without pruning part ?
我按照博主的方法一步步操作,但是训练baseline_model时在训练迭代3,4个epoch时达到过0.73左右,但是在迭代100个epoch后,mAP只有0.69左右。请问您是怎么训练的,我为什么会出现这种情况?
(pytorch-yolov3) C:\YOLOv3-model-pruning-master>python train.py --model_def config/yolov3-hand.cfg
Namespace(batch_size=16, checkpoint_interval=5, data_config='config/oxfordhand.data', debug_file='debug', epochs=100, evaluation_interval=1, img_size=416, lr=0.001, model_def='config/yolov3-hand.cfg', multiscale_training=False, n_cpu=4, pretrained_weights='weights/yolov3.weights', s=0.01, sr=False)
Traceback (most recent call last):
File "C:\Users\923\Anaconda3\envs\pytorch-yolov3\lib\site-packages\tensorboardX\record_writer.py", line 40, in directory_check
factory = REGISTERED_FACTORIES[prefix]
KeyError: 'logs\0821-01'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "train.py", line 50, in
logger = Logger("logs")
File "C:\YOLOv3-model-pruning-master\utils\logger.py", line 27, in init
self.writer = SummaryWriter(os.path.join(log_dir, timestamp))
File "C:\Users\923\Anaconda3\envs\pytorch-yolov3\lib\site-packages\tensorboardX\writer.py", line 257, in init
self._get_file_writer()
File "C:\Users\923\Anaconda3\envs\pytorch-yolov3\lib\site-packages\tensorboardX\writer.py", line 321, in _get_file_writer
**self.kwargs)
File "C:\Users\923\Anaconda3\envs\pytorch-yolov3\lib\site-packages\tensorboardX\writer.py", line 93, in init
logdir, max_queue, flush_secs, filename_suffix)
File "C:\Users\923\Anaconda3\envs\pytorch-yolov3\lib\site-packages\tensorboardX\event_file_writer.py", line 104, in init
directory_check(self._logdir)
File "C:\Users\923\Anaconda3\envs\pytorch-yolov3\lib\site-packages\tensorboardX\record_writer.py", line 44, in directory_check
os.makedirs(path)
File "C:\Users\923\Anaconda3\envs\pytorch-yolov3\lib\os.py", line 220, in makedirs
mkdir(name, mode)
NotADirectoryError: [WinError 267] 目录名称无效。: 'logs\0821-01:30'
报错内容
=====
Detecting objects: 100% 42/42 [01:02<00:00, 1.14s/it]
Computing AP: 100% 3/3 [00:00<00:00, 303.82it/s]
Threshold should be less than 0.3998.
The corresponding prune ratio is 0.769.
Channels with Gamma value less than 0.4403 are pruned!
Detecting objects: 100% 42/42 [01:01<00:00, 1.11s/it]
Traceback (most recent call last):
File "test_prune.py", line 78, in
threshold = prune_and_eval(model, sorted_bn, percent)
File "test_prune.py", line 69, in prune_and_eval
mAP = eval_model(model_copy)[2].mean()
File "test_prune.py", line 27, in
nms_thres=0.5, img_size=model.img_size, batch_size=24)
File "/YOLOv3-model-pruning/test.py", line 55, in evaluate
assert sample_metrics != []
AssertionError
=======
自己数据集classes=3,请指教
When I try to plot images with predicted results, it shows:
(tip: blue represents gt box, red represents predict box)
Then I reference converter.py and datasets.py:
请问有计划什么时候能开源prune_utils.py文件吗?
谢谢!
如上,能不能再代码里解决。
您好,我进行训练的时候报以下错误
File "train.py", line 77, in
model.load_darknet_weights(opt.pretrained_weights)
File "/home/cct/YOLOv3-model-pruning/models.py", line 317, in load_darknet_weights
conv_w = torch.from_numpy(weights[ptr: ptr + num_w]).view_as(conv_layer.weight)
RuntimeError: shape '[256, 128, 3, 3]' is invalid for input of size 160590
请问这个怎么解决?
ModuleNotFoundError: No module named 'utils.prune_utils'
utils 文件夹下面没有prune_utils文件
请问您是只对特征提取层进行剪枝,还是也对yolo层的卷积层进行剪枝呢
When I run the test.py code, the error occurs:
Traceback (most recent call last):
File "test.py", line 5, in <module>
from utils.datasets import *
File "YOLOv3-model-pruning/utils/datasets.py", line 10, in <module>
from utils.augmentations import augment
File "YOLOv3-model-pruning/utils/augmentations.py", line 4, in <module>
import albumentations as A
ModuleNotFoundError: No module named 'albumentations'
想用您的剪枝模型进行行人的检测
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.