talebolano / yolov3-network-slimming

yolov3 network slimming剪枝的一种实现
345 stars 93 forks source link

Can this code runs yolov3-tiny? #8

Closed horngjason closed 5 years ago

horngjason commented 5 years ago

Hi @talevolano,

For yolov3.cfg, it works. Yet I can make yolov3-tiny work with this code by simply change the cmd to point to yolov3.cfg as well as yolov3.weights. I would like to inquire whether or not this implementation can access yolov3-tiny.cfg with yolov3-tiny.weights? Thanks.

horngjason commented 5 years ago

After reference searching and discussion, we found this code can work with yolov3-tiny.cfg by a simple modification in yolomodel.py. This modification won't effect the process of yolov3.cfg.

Please refer to https://github.com/ultralytics/yolov3/issues/51 what the modification in model.py that glenn-jocher reported.

In here, we simply substitute line #284 in yolomodel.py ( in createmodules() ): pool = nn.MaxPool2d(stride=stride,kernel_size=kernel_size)_ as following codes _if kernel_size == 2 and stride == 1: module.add_module('_debugpadding%d' % index, nn.ZeroPad2d((0, 1, 0, 1))) pool = nn.MaxPool2d(kernel_size=kernel_size, stride=stride, padding=int((kernelsize - 1) // 2)) by referring to the glenn-jocher's method in model.py.

*ps: We also tried _pool = nn.MaxPool2d(stride=stride,kernel_size=kernel_size, ceilmode=True) Yet this didn't work.

If anyone has any better idea, please do make us know. Thanks a lot!

andylai0212 commented 5 years ago

Hi @horngjason, when I try to run with yolov3-tiny, it has error: Traceback (most recent call last): File "sparsity_train.py", line 154, in train() File "sparsity_train.py", line 100, in train loss = model(imgs, targets) File "/home/andy0212/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 489, in call result = self.forward(*input, **kwargs) File "/home/andy0212/Documents/yolov3-network-slimming/yolomodel.py", line 332, in forward x = torch.cat((map1, map2), 1) RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 1. Got 26 and 24 in dimension 2 at /opt/conda/conda-bld/pytorch_1549635019666/work/aten/src/THC/generic/THCTensorMath.cu:83

Did you encounter the same problem?

cococener commented 5 years ago

After reference searching and discussion, we found this code can work with yolov3-tiny.cfg by a simple modification in yolomodel.py. This modification won't effect the process of yolov3.cfg.

Please refer to https://github.com/ultralytics/yolov3/issues/51 what the modification in model.py that glenn-jocher reported.

In here, we simply substitute line #284 in yolomodel.py ( in createmodules() ): pool = nn.MaxPool2d(stride=stride,kernel_size=kernel_size)_ as following codes _if kernel_size == 2 and stride == 1: module.add_module('_debugpadding%d' % index, nn.ZeroPad2d((0, 1, 0, 1))) pool = nn.MaxPool2d(kernel_size=kernel_size, stride=stride, padding=int((kernelsize - 1) // 2)) by referring to the glenn-jocher's method in model.py.

*ps: We also tried _pool = nn.MaxPool2d(stride=stride,kernel_size=kernel_size, ceilmode=True) Yet this didn't work.

If anyone has any better idea, please do make us know. Thanks a lot!

But I use this it reminds me out of memory,Before I use it I encounter RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 1.

cococener commented 5 years ago

Hi @horngjason, when I try to run with yolov3-tiny, it has error: Traceback (most recent call last): File "sparsity_train.py", line 154, in train() File "sparsity_train.py", line 100, in train loss = model(imgs, targets) File "/home/andy0212/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 489, in call result = self.forward(*input, **kwargs) File "/home/andy0212/Documents/yolov3-network-slimming/yolomodel.py", line 332, in forward x = torch.cat((map1, map2), 1) RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 1. Got 26 and 24 in dimension 2 at /opt/conda/conda-bld/pytorch_1549635019666/work/aten/src/THC/generic/THCTensorMath.cu:83

Did you encounter the same problem?

So did you solve it?