搜索后,给出的比较好的答案。链接\
1. torch.flatten()总是返回一个1D张量作为结果,前提是输入至少是1D或更大。
2. nn.Flatten()总是返回一个2D张量,前提是输入至少是2D或更大(1D张量作为输入,它会抛出一个IndexError)。
Important difference: A notable distinction is that torch.flatten() always returns an 1D tensor as result, provided that the input is at least 1D or greater, whereas nn.Flatten() always returns a 2D tensor, provided that the input is at least 2D or greater (With 1D tensor as input, it will throw an IndexError).