How to build a view layer in Pytorch for Sequential Models?
Is this ok:
class View(nn.Module):
    def forward(self, input, shape):
        return input.view(*shape)

I tried it based on the flatten layer but I couldn’t even make the flatten layer work:
import torch
import torch.nn as nn

## Q: why does the flatten layer work?
class Flatten(nn.Module):
    def forward(self, input):
        print(input.size())
        out = input.view(input.size(0),-1)
        print(out.size())
        return out

class View(nn.Module):
    def forward(self, input, shape):
        return input.view(*shape)

def main():
    x = torch.arange(0,6).view(3,2)
    print(x)
    print(x.size())
    flatten = Flatten()
    flt_x = flatten(x)
    print(flt_x)
    print(flt_x.size())

if __name__ == '__main__':
    main()

look at the weird output doesn’t chage size:
tensor([[0, 1],
        [2, 3],
        [4, 5]])
torch.Size([3, 2])
torch.Size([3, 2])
torch.Size([3, 2])
tensor([[0, 1],
        [2, 3],
        [4, 5]])
torch.Size([3, 2])