Let’s assume that your CNN class looks like this:
class CNN(nn.Module): 
    def __init__(self, *args, **kwargs):
        super(CNN, self).__init__()
        self.feature_extractor = ... # CNN layers or whatever
        self.classifier = .... # Linear layers
    
    def forward(self, x):
        x = self.feature_extractor(x)
        x = self.classifier(x.view(x.shape[0], -1) # depend on your architecture
        return x

After loading your trained state dict, you can extract the feature from an input by just features = model.feature_extractor(input).