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

When one block has no channels to preserve? #3

Open
zssjh opened this issue Nov 2, 2020 · 0 comments
Open

When one block has no channels to preserve? #3

zssjh opened this issue Nov 2, 2020 · 0 comments

Comments

@zssjh
Copy link

zssjh commented Nov 2, 2020

hello,after I run the prune_model_imagenet.py,when i == 2 in following code, the pruned_cfg[i]=0,it means that the block has no channels to keep.

 for i in range(len(pruned_cfg)):
        pruned_cfg[i] = masks[counter].sum().long().item() 
        counter += 1
    model = models.__dict__[args.arch](args.num_classes, args.expanded_inchannel, args.multiplier, pruned_cfg)

Then, the error occurs:

Traceback (most recent call last):
File "script/prune_model_imagenet.py", line 82, in
model = models.dict[args.arch](args.num_classes, args.expanded_inchannel, args.multiplier, pruned_cfg)
File "/pruning-from-scratch/models/mobilenet.py", line 227, in mobilenet_v2
return MobileNetV2(num_class, in_channel, multiplier, cfg)
File "/pruning-from-scratch/models/mobilenet.py", line 189, in init
self.features.append(InvertedResidual(inp, oup, hid, stride))
File "/pruning-from-scratch/models/mobilenet.py", line 159, in init
self.conv = InvertedBlock(inp, oup, hid, stride)
File "/pruning-from-scratch/models/mobilenet.py", line 117, in init
self.conv1 = nn.Conv2d(inp, hid, 1, 1, 0, bias=False)
File "python3.7/site-packages/torch/nn/modules/conv.py", line 338, in init
False, pair(0), groups, bias, padding_mode)
File "python3.7/site-packages/torch/nn/modules/conv.py", line 53, in init
self.reset_parameters()
File "python3.7/site-packages/torch/nn/modules/conv.py", line 56, in reset_parameters
init.kaiming_uniform
(self.weight, a=math.sqrt(5))
File "python3.7/site-packages/torch/nn/init.py", line 322, in kaiming_uniform_
fan = _calculate_correct_fan(tensor, mode)
File "python3.7/site-packages/torch/nn/init.py", line 291, in _calculate_correct_fan
fan_in, fan_out = _calculate_fan_in_and_fan_out(tensor)
File "python3.7/site-packages/torch/nn/init.py", line 223, in _calculate_fan_in_and_fan_out
receptive_field_size = tensor[0][0].numel()
IndexError: index 0 is out of bounds for dimension 0 with size 0

How do I solve the problem? Thanks so much~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant