Spaces:
Sleeping
Sleeping
File size: 626 Bytes
5c6e546 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import torch
import torch.nn as nn
import torchvision.models as models
class CatvsDogResNet50(nn.Module):
def __init__(self, freeze_backbone: bool = True):
super().__init__()
self.backbone = models.resnet50(pretrained=True)
if freeze_backbone:
for param in self.backbone.parameters():
param.requires_grad = False
num_ftrs = self.backbone.fc.in_features
self.backbone.fc = nn.Sequential(
nn.Dropout(0.5),
nn.Linear(num_ftrs, 1),
)
def forward(self, x: torch.Tensor) -> torch.Tensor:
return self.backbone(x) |