Add loading fct & Improve ReadMe
Browse files- README.md +17 -1
- scripts/resnet20-frn-silu-cifar10/std_loading.py +26 -0
README.md
CHANGED
@@ -7,4 +7,20 @@ tags:
|
|
7 |
pretty_name: Checkpoints
|
8 |
---
|
9 |
|
10 |
-
The Checkpoints dataset as trained and used in [A Symmetry-Aware Exploration of Bayesian Neural Network Posteriors](https://arxiv.org/abs/2310.08287) published at ICLR 2024.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
pretty_name: Checkpoints
|
8 |
---
|
9 |
|
10 |
+
The Checkpoints dataset as trained and used in [A Symmetry-Aware Exploration of Bayesian Neural Network Posteriors](https://arxiv.org/abs/2310.08287) published at ICLR 2024.
|
11 |
+
|
12 |
+
## Usage
|
13 |
+
|
14 |
+
To load or train models, start by downloading [TorchUncertainty](https://github.com/ENSTA-U2IS-AI/torch-uncertainty) - [Documentation](https://torch-uncertainty.github.io/).
|
15 |
+
|
16 |
+
Install TorchUncertainty with pip:
|
17 |
+
```bash
|
18 |
+
|
19 |
+
pip install torch-uncertainty
|
20 |
+
```
|
21 |
+
|
22 |
+
Functions to load the models are available in `scripts`.
|
23 |
+
|
24 |
+
**Any questions?** Please feel free to ask in the [GitHub Issues](https://github.com/ENSTA-U2IS-AI/torch-uncertainty/issues) or on our [Discord server](https://discord.gg/HMCawt5MJu)
|
25 |
+
|
26 |
+
.
|
scripts/resnet20-frn-silu-cifar10/std_loading.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pathlib import Path
|
2 |
+
from torch.nn import functional as F
|
3 |
+
|
4 |
+
from torch_uncertainty.models.resnet import resnet20
|
5 |
+
from torch_uncertainty.layers.filter_response_norm import FilterResponseNorm2d
|
6 |
+
from safetensors.torch import load_file
|
7 |
+
|
8 |
+
|
9 |
+
def load_model(version: int):
|
10 |
+
"""Load the model corresponding to the given version."""
|
11 |
+
model = resnet20(
|
12 |
+
num_classes=10,
|
13 |
+
in_channels=3,
|
14 |
+
style="cifar",
|
15 |
+
activation_fn=F.silu,
|
16 |
+
normalization_layer=FilterResponseNorm2d,
|
17 |
+
)
|
18 |
+
path = Path(
|
19 |
+
f"resnet20-frn-silu-cifar10/resnet20-frn-silu-cifar10-0-1023/version_{version}.safetensors"
|
20 |
+
)
|
21 |
+
if not path.exists():
|
22 |
+
raise ValueError("File does not exist")
|
23 |
+
|
24 |
+
state_dict = load_file(path)
|
25 |
+
model.load_state_dict(state_dict=state_dict)
|
26 |
+
return model
|