Print the shape of x in __forward__, run it once, and change your layer to the appropriate size.
def forward(self, x):
    ...
    x = x.view(x.size(0), -1)
    print(x.shape)
    ...

One could of course calculate the shape manually, but I don’t know your input shape.