Created
February 5, 2020 11:45
-
-
Save ihoromi4/aa16085532358f9fc7937941526d827c to your computer and use it in GitHub Desktop.
pytorch - get number of a model parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools | |
import operator | |
from torch import nn | |
def get_n_params(model: nn.Module) -> int: | |
return sum((functools.reduce(operator.mul, p.size()) for p in model.parameters())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment