If you want to freeze the model and use a KNN implementation from e.g. sklearn, you could replace the last linear layer with nn.Identity to get the features from the penultimate layer and feed them to sklearn.neighbors.KNeightborsClassifier 4.
Alternatively, you could also implement KNN manually in PyTorch (you should be able to find some implementations in this forum or probably on GitHub).