You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+48-12Lines changed: 48 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -43,9 +43,13 @@ Other features include:
43
43
-[x][dnn_to_bnn](https://github.com/IntelLabs/bayesian-torch/blob/main/bayesian_torch/models/dnn_to_bnn.py#L127): An API to convert deterministic deep neural network (dnn) model of any architecture to Bayesian deep neural network (bnn) model, simplifying the model definition i.e. drop-in replacements of Convolutional, Linear and LSTM layers to corresponding Bayesian layers. This will enable seamless conversion of existing topology of larger models to Bayesian deep neural network models for extending towards uncertainty-aware applications.
44
44
45
45
## Installation
46
-
47
-
48
-
**Install from source:**
46
+
<!--
47
+
**To install from PyPI:**
48
+
```
49
+
pip install bayesian-torch
50
+
```
51
+
-->
52
+
**To install latest development version from source:**
We have provided [example model implementations](bayesian_torch/models/bayesian) using the Bayesian layers.
68
+
## Usage
69
+
There are two ways to build Bayesian deep neural networks using Bayesian-Torch:
70
+
1. Convert an existing deterministic deep neural network (dnn) model to Bayesian deep neural network (bnn) model with dnn_to_bnn()
71
+
2. Define your custom model using the Bayesian layers ([Flipout](https://github.com/IntelLabs/bayesian-torch/tree/main/bayesian_torch/layers/flipout_layers) or [Reparameterization](https://github.com/IntelLabs/bayesian-torch/tree/main/bayesian_torch/layers/variational_layers))
66
72
67
-
We also provide [example usages](bayesian_torch/examples) and [scripts](bayesian_torch/scripts) to train/evaluate the models. The instructions for CIFAR10 examples is provided below, similar scripts for ImageNet and MNIST are available.
73
+
(1) For instance to build Bayesian-ResNet18 from torchvision deterministic ResNet18 model:
74
+
```
75
+
import torchvision
76
+
from bayesian_torch.models.dnn_to_bnn import dnn_to_bnn
77
+
78
+
const_bnn_prior_parameters = {
79
+
"prior_mu": 0.0,
80
+
"prior_sigma": 1.0,
81
+
"posterior_mu_init": 0.0,
82
+
"posterior_rho_init": -3.0,
83
+
"type": "Reparameterization", # Flipout or Reparameterization
84
+
"moped_enable": False, # True to initialize mu/sigma from the pretrained dnn weights
85
+
"moped_delta": 0.2,
86
+
}
87
+
88
+
model = torchvision.models.resnet18()
89
+
dnn_to_bnn(model, const_bnn_prior_parameters)
90
+
```
91
+
To use MOPED method, setting the prior and initializing variational parameters from a pretrained determined model (helps training convergence of larger models):
92
+
```
93
+
const_bnn_prior_parameters = {
94
+
"prior_mu": 0.0,
95
+
"prior_sigma": 1.0,
96
+
"posterior_mu_init": 0.0,
97
+
"posterior_rho_init": -3.0,
98
+
"type": "Reparameterization", # Flipout or Reparameterization
99
+
"moped_enable": True, # True to initialize mu/sigma from the pretrained dnn weights
100
+
"moped_delta": 0.2,
101
+
}
102
+
103
+
model = torchvision.models.resnet18(pretrained=True)
104
+
dnn_to_bnn(model, const_bnn_prior_parameters)
105
+
```
106
+
(2) For building custom models, we have provided [example model implementations](bayesian_torch/models/bayesian) using the Bayesian layers.
68
107
108
+
## Example usage (training and evaluation of models)
109
+
110
+
We have provided [example usages](https://github.com/IntelLabs/bayesian-torch/tree/main/bayesian_torch/examples) and [scripts](https://github.com/IntelLabs/bayesian-torch/tree/main/bayesian_torch/scripts) to train/evaluate the models. The instructions for CIFAR10 examples is provided below, similar scripts for ImageNet and MNIST are available.
69
111
```
70
112
cd bayesian_torch
71
113
```
72
-
73
114
### Training
74
115
75
116
To train Bayesian ResNet on CIFAR10, run this command:
@@ -152,11 +193,6 @@ MOdel Priors with Empirical Bayes using DNN (MOPED)
152
193
}
153
194
```
154
195
155
-
**Contributors**
156
-
- Ranganath Krishnan
157
-
- Piero Esposito
158
-
- Mahesh Subedar
159
-
160
196
This code is intended for researchers and developers, enables to quantify principled uncertainty estimates from deep neural network predictions using stochastic variational inference in Bayesian neural networks.
161
197
Feedbacks, issues and contributions are welcome. Email to <[email protected]> for any questions.
0 commit comments