Non-legacy View module?
There doesn’t currently appear to be any non-legacy View module in pytorch’s torch.nn module. Any reason for this? While obviously not essential, it’s convenient when porting over existing Torch networks. Would be happy to submit a PR.
lebedov
gsp-27
apaszke
That method directly resizes the associated tensor instance; having a View module would enable one to directly add it to the sequence of modules in a network rather than having to explicitly call it. For example: <SCODE>class MyNetwork(torch.nn.Module):
    def __init__(self):
        super(MyNetwork, self).__init__()
        modules = [nn.Conv2d(1, 10, 3),
                   nn.MaxPool2d(2, 2),
                   ...,
                   View(100),
                   nn.Linear(100, 2)]
        for i, m in enumerate(modules):
            self.add_module(str(i), m)
    def forward(self, x):
        for child in self.children():
            x = child(x)
        return x<ECODE>
lebedov
apaszke
lebedov
apaszke
Duly noted. Thanks for the feedback.
lebedov
Sorry to come back to this discussion after a month or so, but I indeed miss some convenient way of flattening out a layer inside of Sequential. I am breaking this operation into two pieces as suggested, a Sequential model that outputs a image shape, and then in the forward() method, I flatten the results.
juliohm
<SCODE>class Flatten(nn.Module):
    def __init__(self):
        super(Flatten, self).__init__()

    def forward(self, x):
        x = x.view(x.size(0), -1)
        return x

model = nn.Sequential(
            nn.Conv2d(3, 1, 3, 1, 1),
            Flatten(),
            nn.Linear(24*24, 1)
        )

x = Variable(torch.randn(10, 3, 24, 24))
model(x)
<ECODE>
ptrblck
juliohm