Download utils/feature_extractor.py from HoomKh/ZeroShot-AD: direct link, hf CLI and curl.
- Browser
- Download file 622 Bytes
-
https://huggingface.co/HoomKh/ZeroShot-AD/resolve/main/utils/feature_extractor.py
- Command line
-
hf download hf://HoomKh/ZeroShot-AD/utils/feature_extractor.py
-
curl -L -o feature_extractor.py https://huggingface.co/HoomKh/ZeroShot-AD/resolve/main/utils/feature_extractor.py
622 Bytes
| # utils/feature_extractor.py | |
| import torch | |
| import torch.nn as nn | |
| from torchvision import models | |
| class FeatureExtractor(nn.Module): | |
| def __init__(self, backbone='resnet50'): | |
| super(FeatureExtractor, self).__init__() | |
| if backbone == 'resnet50': | |
| self.model = models.resnet50(pretrained=True) | |
| # Remove the final fully connected layer | |
| self.features = nn.Sequential(*list(self.model.children())[:-2]) | |
| else: | |
| raise NotImplementedError(f"Backbone {backbone} is not implemented.") | |
| def forward(self, x): | |
| return self.features(x) | |