Skip to content

Commit f6cb161

Browse files
Update README.md
update usage instructions in README file
1 parent b0f928b commit f6cb161

File tree

1 file changed

+48
-12
lines changed

1 file changed

+48
-12
lines changed

README.md

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,13 @@ Other features include:
4343
- [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.
4444

4545
## 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:**
4953
```sh
5054
git clone https://github.com/IntelLabs/bayesian-torch
5155
cd bayesian-torch
@@ -61,15 +65,52 @@ Dependencies:
6165
- pip install tensorboard
6266
- pip install scikit-learn
6367

64-
## Example usage
65-
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))
6672

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.
68107

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.
69111
```
70112
cd bayesian_torch
71113
```
72-
73114
### Training
74115

75116
To train Bayesian ResNet on CIFAR10, run this command:
@@ -152,11 +193,6 @@ MOdel Priors with Empirical Bayes using DNN (MOPED)
152193
}
153194
```
154195

155-
**Contributors**
156-
- Ranganath Krishnan
157-
- Piero Esposito
158-
- Mahesh Subedar
159-
160196
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.
161197
Feedbacks, issues and contributions are welcome. Email to <[email protected]> for any questions.
162198

0 commit comments

Comments
 (0)