Model ResNet18 adaptat si antrenat pe CIFAR-10.
1# In template, seteaza:
2HUGGINGFACE_REPO_ID = "Tudorx95/resnet18-cifar10-pytorch"
3MODEL_FILENAME = "ResNet18_CIFAR10.pth"
4
5# Modelul se incarca automat in create_model()
1import torch
2import torchvision
3import torch.nn as nn
4
5# Incarca checkpoint-ul
6checkpoint = torch.load('ResNet18_CIFAR10.pth', map_location='cpu')
7
8# Reconstruieste arhitectura din config
9arch = checkpoint['architecture']
10model = torchvision.models.resnet18(weights=None)
11mod = arch['modifications']
12model.conv1 = nn.Conv2d(3, 64, **mod['conv1'])
13model.maxpool = nn.Identity()
14model.fc = nn.Linear(mod['fc']['in_features'], mod['fc']['out_features'])
15
16# Incarca ponderile
17model.load_state_dict(checkpoint['model_state_dict'])
18model.eval()