You can implement such a method in your model class using random input. It should be something like this:
def calculate_size(self, input_size):
    x = torch.randn(input_size).unsqueeze(0)
    output = self.layers(x)
    return output.size()[1:]

This will use one forward pass to calculate the output shape. You should of course use the layers you need the output shape for.