Spaces:
Runtime error
Runtime error
fix resnet mismatch
Browse files10 unmodified lines11121314151617183 unmodified lines2223242526272810 unmodified linesdef __init__(self, num_classes=196): # Stanford Cars has 196 classessuper(MyCarClassifier, self).__init__()# Example: replace with your actual model architecturefrom torchvision.models import resnet18self.model = resnet18(pretrained=False)self.model.fc = torch.nn.Linear(self.model.fc.in_features, num_classes)def forward(self, x):3 unmodified lines# 2. Load model weights# --------------------------model = MyCarClassifier()model.load_state_dict(torch.load("best_stanford_cars_transfer_model.pth", map_location="cpu"), strict=False)model.eval() # important for inference# --------------------------10 unmodified lines11121314151617183 unmodified lines2223242526272810 unmodified linesdef __init__(self, num_classes=196): # Stanford Cars has 196 classessuper(MyCarClassifier, self).__init__()# Example: replace with your actual model architecturefrom torchvision.models import resnet50self.model = resnet50(pretrained=False)self.model.fc = torch.nn.Linear(self.model.fc.in_features, num_classes)def forward(self, x):3 unmodified lines# 2. Load model weights# --------------------------model = MyCarClassifier()model.load_state_dict(torch.load("best_stanford_cars_transfer_model.pth", map_location="cpu"), strict=True)model.eval() # important for inference# --------------------------
app.py+3-3