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

Fix handling input_size with multi-input #166

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion torchsummary/torchsummary.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ def hook(module, input, output):
summary_str += line_new + "\n"

# assume 4 bytes/number (float on cuda).
total_input_size = abs(np.prod(sum(input_size, ()))
# to handle the case of multi-input: prod(input1) + prod(input2) + ...
n_input_size = np.array([np.prod(i) for i in input_size]).sum() if isinstance(input_size, list) else np.prod(input_size)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need to check if input_size is a list because that is normalized here:

# multiple inputs to the network
if isinstance(input_size, tuple):
input_size = [input_size]

Copy link
Author

@ahmedhshahin ahmedhshahin Sep 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote this a long time ago, but I think I added this check so that the code works properly for the single-input cases too. If its a single-input, return the product of input dims, if its multi-input (list of inputs), return prod(input1) + prod(input2) + ...

total_input_size = abs(n_input_size
* batch_size * 4. / (1024 ** 2.))
total_output_size = abs(2. * total_output * 4. /
(1024 ** 2.)) # x2 for gradients
Expand Down