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

I have a question about parameter number. #4

Open
5thwin opened this issue Jan 9, 2020 · 2 comments
Open

I have a question about parameter number. #4

5thwin opened this issue Jan 9, 2020 · 2 comments

Comments

@5thwin
Copy link

5thwin commented Jan 9, 2020

after pruning, I count the parameter of the network resnet34.
well... I found the number of parameters to be 4.2 * 10e7
I know parameter number of resnet34 is about 2 * 10e7
I think it's because of the mask of layer that the difference is about double, right?
then how to remove the mask layer after prunning?
Thanks you.

@jack-willturner
Copy link
Owner

Sorry for the slow response.

The easiest way to do this would be to create a normal resnet34 (without masks), and then copy across the weights.

You'll want to do something like:

net = NormalResNet34()
masked_net = MaskedResNet34()

for normal, masked in zip([net.layer1, net.layer2, net.layer3, net.layer4], [masked_net.layer1, masked_net.layer2, masked_net.layer3, masked_net.layer4]):
    normal.conv1.weight = masked.conv1.weight
    normal.bn1.weight = masked.bn1.weight
    normal.conv2.weight  = masked.conv2.weight
    # etc.

Note that you're probably going to have to copy some biases as well (you can just do normal.bn1.bias).

It would be cool to have this as a feature in the code. If you figure it out, please feel free to open a pull request 😊

If not I'll get to implementing it soon.

@zjykzj
Copy link

zjykzj commented Jul 1, 2021

Sorry for the slow response.

The easiest way to do this would be to create a normal resnet34 (without masks), and then copy across the weights.

You'll want to do something like:

net = NormalResNet34()
masked_net = MaskedResNet34()

for normal, masked in zip([net.layer1, net.layer2, net.layer3, net.layer4], [masked_net.layer1, masked_net.layer2, masked_net.layer3, masked_net.layer4]):
    normal.conv1.weight = masked.conv1.weight
    normal.bn1.weight = masked.bn1.weight
    normal.conv2.weight  = masked.conv2.weight
    # etc.

Note that you're probably going to have to copy some biases as well (you can just do normal.bn1.bias).

It would be cool to have this as a feature in the code. If you figure it out, please feel free to open a pull request

If not I'll get to implementing it soon.

Good idea, thank you. @jack-willturner

Using mask for pruning training is a very common way in pruning algorithm. I didn't want to extract effective parameters after mask training before. Your description gives me a specific implementation path (Although using this scheme needs to reimplement a model definition that can customize the number of parameters of each layer)

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

No branches or pull requests

3 participants