Skip to content
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