sksq96 / pytorch-summary

Model summary in PyTorch similar to `model.summary()` in Keras
MIT License
4.01k stars 412 forks source link

Fix handling input_size with multi-input #166

Open ahmedhshahin opened 3 years ago

ahmedhshahin commented 3 years ago

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.

scratchmex commented 3 years ago

When the inputs are different length, for example: [(1, 28, 28), (1,)]; the nowadays implementation throws TypeError: can't multiply sequence by non-int of type 'tuple' and a warning

numpy\core\fromnumeric.py:87: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray

I think this PR solves this.

@sksq96