fix paddle.summary's bug when outputs contains non-tensor #34160
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.
PR types
Bug fixes
PR changes
APIs
Describe
该问题是复现TimeSformer模型时遇到的,当网络中的某些层的输出含有非tensor的元素时,使用paddle.summary会报错,因为递归逻辑中遇到单个元素时直接调用其.shape()方法,而这个元素可能并不是tensor,导致无法获取到output中非tensor的shape并且报错,见图1。
修复后在递归逻辑中加入了调用shape方法前的判断,如果不是tensor,则它的形状用
[]
代替,见图2。torchsummary目前也存在这个问题,见图3。
以下是修改前,修改后,以及torchsummary的例子