Erdem Atak
initial commit
e37553d
raw
history blame contribute delete
939 Bytes
# import the needed dependencies for this py file
import torch
import torchvision
from torch import nn
#Turning train as a function as 1. setup, 2 getr transforms 3. setup model instance 4. Freeze base layers and adjust output layers
def create_effnetb2_model(num_classes = 3,
seed = 24):
# 1, 2, 3, Create effnetb2 weights, transform and model
weights = torchvision.models.EfficientNet_B2_Weights.DEFAULT
transforms = weights.transforms()
model = torchvision.models.efficientnet_b2(weights=weights)
# 4. Freeze the base layers of effnetb2
for param in model.parameters(): # Corrected from effnetb2.parameters()
param.requires_grad = False
# 5. Adjust the number of heads(output)
torch.manual_seed(seed)
model.classifier = nn.Sequential(
nn.Dropout(p=0.3, inplace=True),
nn.Linear(in_features=1408, out_features=num_classes, bias=True))
return model, transforms