Spaces:
Running on Zero
Running on Zero
Download UniversalFakeDetect/models/clip_models.py from Thiru1122/Multimodel_setup: direct link, hf CLI and curl.
- Browser
- Download file 667 Bytes
-
https://huggingface.co/spaces/Thiru1122/Multimodel_setup/resolve/main/UniversalFakeDetect/models/clip_models.py
- Command line
-
hf download hf://spaces/Thiru1122/Multimodel_setup/UniversalFakeDetect/models/clip_models.py
-
curl -L -o clip_models.py https://huggingface.co/spaces/Thiru1122/Multimodel_setup/resolve/main/UniversalFakeDetect/models/clip_models.py
667 Bytes
| from .clip import clip | |
| from PIL import Image | |
| import torch.nn as nn | |
| CHANNELS = { | |
| "RN50" : 1024, | |
| "ViT-L/14" : 768 | |
| } | |
| class CLIPModel(nn.Module): | |
| def __init__(self, name, num_classes=1): | |
| super(CLIPModel, self).__init__() | |
| self.model, self.preprocess = clip.load(name, device="cpu") # self.preprecess will not be used during training, which is handled in Dataset class | |
| self.fc = nn.Linear( CHANNELS[name], num_classes ) | |
| def forward(self, x, return_feature=False): | |
| features = self.model.encode_image(x) | |
| if return_feature: | |
| return features | |
| return self.fc(features) | |