The number if in_features in your first linear layer has to match the flattened features of its incoming activation.
In that case it seems the feature calculation is wrong and you should set in_features = 100352 instead of 512.