Add a print statement in your forward method so see the shape of x:
    def forward(self, x):
        x = self.model(x)
        x = self.ap(x)
        x = x.view(x.size(0), -1)
        print(x.shape)
        x = self.fc1(x)
        x = self.relu(x)
        x = self.dropout(x)
        x = self.fc2(x)
        return x

and just set the in_features of self.fc1 to a temporary number.
After the first forward pass, use the printed shape to set the number of input features for your linear layer.
Alternatively you could also calculate the feature size using the whole model architecture.
Also, if you are dealing with varying sized inputs, you might want to add an adaptive pooling layer, which will always yield the same output size.