Spaces:
Sleeping
Sleeping
| import torch.nn as nn | |
| from torchvision import models | |
| class FoodIngredientClassifier(nn.Module): | |
| def __init__(self, num_classes): | |
| super().__init__() | |
| self.backbone = models.vit_b_16( | |
| weights=models.ViT_B_16_Weights.DEFAULT | |
| ) | |
| num_features = self.backbone.heads.head.in_features | |
| self.backbone.heads = nn.Sequential( | |
| nn.Dropout(0.5), | |
| nn.Linear(num_features, 1024), | |
| nn.BatchNorm1d(1024), | |
| nn.ReLU(), | |
| nn.Dropout(0.4), | |
| nn.Linear(1024, 512), | |
| nn.BatchNorm1d(512), | |
| nn.ReLU(), | |
| nn.Dropout(0.3), | |
| nn.Linear(512, num_classes) | |
| ) | |
| def forward(self, x): | |
| return self.backbone(x) |