Last active
November 6, 2020 16:44
-
-
Save christinakim/26c5ae3b22eb599b4fb5575918ff7a3b to your computer and use it in GitHub Desktop.
print trainable parameters by layer
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
from prettytable import PrettyTable | |
def count_parameters(model): | |
table = PrettyTable(["Modules", "Parameters"]) | |
total_params = 0 | |
for name, parameter in model.named_parameters(): | |
if not parameter.requires_grad: continue | |
param = parameter.numel() | |
table.add_row([name, param]) | |
total_params+=param | |
print(table) | |
print(f"Total Trainable Params: {total_params}") | |
return total_params |
Author
christinakim
commented
Nov 6, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment