Oh, my bad. I missed that you are using nn.Conv1d. In that case, you should only calculate the mean in the temporal dimension: out = out.mean(2).
Also, note that you would have to apply it before feeding the activation to your linear layers and before reshaping the tensor.
Based on the error message, it seems you are trying to apply it on a flattened tensor.