File size: 816 Bytes
ac9452b
 
 
77e3e0a
ac9452b
 
 
 
 
 
77e3e0a
 
ac9452b
 
 
 
 
 
 
23cc631
ac9452b
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from pathlib import Path
from torch.nn import functional as F

from torch_uncertainty.models.resnet import resnet
from torch_uncertainty.layers.filter_response_norm import FilterResponseNorm2d
from safetensors.torch import load_file


def load_model(version: int):
    """Load the model corresponding to the given version."""
    model = resnet(
        arch=20,
        num_classes=10,
        in_channels=3,
        style="cifar",
        activation_fn=F.silu,
        normalization_layer=FilterResponseNorm2d,
    )
    path = Path(
        f"cifar10-resnet20-frn-silu/cifar10-resnet20-frn-silu-0-1023/version_{version}.safetensors"
    )
    if not path.exists():
        raise ValueError("File does not exist")

    state_dict = load_file(path)
    model.load_state_dict(state_dict=state_dict)
    return model