Spaces:
Sleeping
Sleeping
Download resnet.py from smishr-18/FlowerClassification: direct link, hf CLI and curl.
- Browser
- Download file 846 Bytes
-
https://huggingface.co/spaces/smishr-18/FlowerClassification/resolve/main/resnet.py
- Command line
-
hf download hf://spaces/smishr-18/FlowerClassification/resnet.py
-
curl -L -o resnet.py https://huggingface.co/spaces/smishr-18/FlowerClassification/resolve/main/resnet.py
846 Bytes
| import torch.nn as nn | |
| import torchvision | |
| class Resnet50Flower102(nn.Module): | |
| def __init__(self, device, pretrained=True, freeze_backbone=True): | |
| super().__init__() | |
| self.device = device | |
| if pretrained: | |
| weights = torchvision.models.ResNet50_Weights.IMAGENET1K_V1 | |
| else: | |
| weights = None | |
| self.model = torchvision.models.resnet50(weights=weights) | |
| self.model.fc = nn.Sequential( | |
| nn.Linear(2048, 1024), | |
| nn.BatchNorm1d(1024), | |
| nn.ReLU(), | |
| nn.Dropout(0.2), | |
| nn.Linear(1024, 512), | |
| nn.BatchNorm1d(512), | |
| nn.ReLU(), | |
| nn.Dropout(0.2), | |
| nn.Linear(512, 102), | |
| ) | |
| self.model.to(device) | |
| def forward(self, x): | |
| return self.model(x) |