Comments (3)
I strongly recommend not using cfg
in this way. (cfg
should be automatically generated when running the pruning code.) The reason for your problem is that you didn't set the channel_selection
layer accordingly.
Specifically, you need to choose four channels in channel_selection
layer to form as the output.
from rethinking-network-pruning.
The first convolution is not represented in cfg
. The first 16 in cfg
refers to the channels in the first convolution of the first residual block.
from rethinking-network-pruning.
But the output channel of the first convolution is fixed to 16. When the first channel in cfg
is pruned, there will be an error.
Reproduce the error (assume the first convolution of the first residual block was pruned to 4):
import torch
from models import resnet
def main():
# follow the depth in the paper
depth = 164
n = (depth - 2) // 9
# assume the first layer is pruned to 4 (default 16)
# cfg = [[16, 16, 16], [64, 16, 16] * (n - 1), [64, 32, 32], [128, 32, 32] * (n - 1), [128, 64, 64],
# [256, 64, 64] * (n - 1), [256]]
cfg = [[4, 16, 16], [64, 16, 16] * (n - 1), [64, 32, 32], [128, 32, 32] * (n - 1), [128, 64, 64],
[256, 64, 64] * (n - 1), [256]]
cfg = [item for sub_list in cfg for item in sub_list]
newmodel = resnet(depth=164, dataset="cifar100", cfg=cfg)
input_demo = torch.zeros(4, 3, 32, 32)
output = newmodel(input_demo)
pass
if __name__ == '__main__':
main()
To run the code, paste the code to cifar/network-slimming/reproduce.py
and run it.
The error message:
Traceback (most recent call last):
File "/home/*****/projects/rethinking-network-pruning/cifar/network-slimming/reproduce.py", line 23, in <module>
main()
File "/home/*****/projects/rethinking-network-pruning/cifar/network-slimming/reproduce.py", line 17, in main
output = newmodel(input_demo)
File "/home/*****/anaconda3/envs/pruning/lib/python3.6/site-packages/torch/nn/modules/module.py", line 493, in __call__
result = self.forward(*input, **kwargs)
File "/home/*****/projects/rethinking-network-pruning/cifar/network-slimming/models/preresnet.py", line 112, in forward
x = self.layer1(x) # 32x32
File "/home/*****/anaconda3/envs/pruning/lib/python3.6/site-packages/torch/nn/modules/module.py", line 493, in __call__
result = self.forward(*input, **kwargs)
File "/home/*****/anaconda3/envs/pruning/lib/python3.6/site-packages/torch/nn/modules/container.py", line 92, in forward
input = module(input)
File "/home/*****/anaconda3/envs/pruning/lib/python3.6/site-packages/torch/nn/modules/module.py", line 493, in __call__
result = self.forward(*input, **kwargs)
File "/home/*****/projects/rethinking-network-pruning/cifar/network-slimming/models/preresnet.py", line 38, in forward
out = self.conv1(out)
File "/home/*****/anaconda3/envs/pruning/lib/python3.6/site-packages/torch/nn/modules/module.py", line 493, in __call__
result = self.forward(*input, **kwargs)
File "/home/*****/anaconda3/envs/pruning/lib/python3.6/site-packages/torch/nn/modules/conv.py", line 338, in forward
self.padding, self.dilation, self.groups)
RuntimeError: Given groups=1, weight of size 16 4 1 1, expected input[4, 16, 224, 224] to have 4 channels, but got 16 channels instead
Process finished with exit code 1
from rethinking-network-pruning.
Related Issues (20)
- Pruning steps HOT 3
- Pruning strategy HOT 1
- 关于阻止已经置零的通道进行权重更新出现的问题 HOT 2
- size mismatch, m1: [2 x 288], m2: [8 x 120] HOT 1
- after network-slimming,the size of modell are the same as premodel? HOT 4
- count_flops HOT 2
- Question for Network Slimming on cifar 100 HOT 2
- IndexError: index 0 is out of bounds for dimension 0 with size 0 HOT 3
- when should I train it? HOT 4
- Question about predefined structured pruning HOT 1
- A question about the training epochs HOT 2
- Network slimming loss function HOT 2
- Cifar10 vgg19 zero remaining channel (network slimming) HOT 6
- updateBN HOT 1
- Some questions about ThiNet HOT 2
- Reproduce Fig. 4 from paper HOT 1
- VGG-16 on CIFAR10 dataset architecture
- What is 'PATH TO THE MODEL' HOT 1
- VGG-16 and ResNet-50 from Pytorch Model Zoo Not found HOT 2
- Error while running l1-norm-pruning on Windows machine HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rethinking-network-pruning.