Fix handling input_size with multi-input - #166
Open
ahmedhshahin wants to merge 1 commit into
Open
Conversation
|
When the inputs are different length, for example: I think this PR solves this. |
scratchmex
suggested changes
Sep 4, 2021
| # 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) |
There was a problem hiding this comment.
we don't need to check if input_size is a list because that is normalized here:
pytorch-summary/torchsummary/torchsummary.py
Lines 54 to 56 in 4852f2e
Author
There was a problem hiding this comment.
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) + ...
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While dealing with multi-input, the current implementation calculates the number of elements in input as the product of all dimensions in all inputs, I believe this is not accurate.
For example, if we have input1 with dimensions [1,5,5] and input2 with dimensions [1,10,10]:
Current implementation: number of elements = 1 * 5 * 5 * 1 * 10 * 10 = 2500 elements
Where it should be: number of elements = (1 * 5 * 5) + (1 * 10 * 10) = 125 elements
As they are two separate inputs.