food_classifier / model.py
Dristro's picture
bug fix
170de61 verified
raw
history blame contribute delete
664 Bytes
### Code for model.py
import torch
import torchvision
from torch import nn
def create_effnet_b2(num_classes: int = 3,
seed: int = 42):
weights = torchvision.models.EfficientNet_B2_Weights.DEFAULT
auto_transforms = weights.transforms()
model = torchvision.models.efficientnet_b2(weights=weights)
# Freeze the base layers
for param in model.parameters():
param.requires_grad = False
# Custom classifier
torch.manual_seed(seed)
model.classifier = nn.Sequential(
nn.Dropout(p=0.3, inplace=True),
nn.Linear(in_features=1408, out_features=num_classes)
)
return model, auto_transforms