Download feature_extractor.py from cyttic/diffusionpen-matan-ft: direct link, hf CLI and curl.
- Browser
- Download file 610 Bytes
-
https://huggingface.co/cyttic/diffusionpen-matan-ft/resolve/main/feature_extractor.py
- Command line
-
hf download hf://cyttic/diffusionpen-matan-ft/feature_extractor.py
-
curl -L -o feature_extractor.py https://huggingface.co/cyttic/diffusionpen-matan-ft/resolve/main/feature_extractor.py
610 Bytes
| import torch.nn as nn | |
| import timm | |
| class ImageEncoder(nn.Module): | |
| """ | |
| Encode images to a fixed size vector | |
| """ | |
| def __init__( | |
| self, model_name='resnet50', num_classes=0, pretrained=True, trainable=True | |
| ): | |
| super().__init__() | |
| self.model = timm.create_model( | |
| model_name, pretrained, num_classes=num_classes, global_pool="max" | |
| ) | |
| #self.model = torch.compile(self.model, backend="inductor") | |
| for p in self.model.parameters(): | |
| p.requires_grad = trainable | |
| def forward(self, x): | |
| x = self.model(x) | |
| return x |