ahamedddd/FoodVision_Mini2
0
1import torch2import torchvision3 4from torch import nn5def create_effnetb2_model(num_classes:int=3, # default output classes = 3 (pizza, steak, sushi)6 seed:int=42):7 # 1, 2, 3 Create EffNetB2 pretrained weights, transforms and model8 weights = torchvision.models.EfficientNet_B2_Weights.DEFAULT9 transforms = weights.transforms()10 model = torchvision.models.efficientnet_b2(weights=weights)11 12 # 4. Freeze all layers in the base model13 for param in model.parameters():14 param.requires_grad = False15 16 # 5. Change classifier head with random seed for reproducibility17 torch.manual_seed(seed)18 model.classifier = nn.Sequential(19 nn.Dropout(p=0.3, inplace=True),20 nn.Linear(in_features=1408, out_features=num_classes)21 )22 23 return model, transforms24 