Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

about the reconstruction error of combined model #3

Open
ShellingFord221 opened this issue Dec 18, 2019 · 9 comments
Open

about the reconstruction error of combined model #3

ShellingFord221 opened this issue Dec 18, 2019 · 9 comments

Comments

@ShellingFord221
Copy link

Hi, in your combined model, when testing, the computation of reconstruction error is tf.square(self.rec_images2 - self.images) (line 93), I wonder that why don't you use the output of modeling epistemic uncertainty (i.e. self.rec_images) to compute reconstruction error when testing? Thanks!

@pmorerio
Copy link
Owner

pmorerio commented Dec 18, 2019

self.rec_images is actually a concatenation of all the 20 sampled predictions (line 74), so you should use their average (you should modify line 75 by replacing the _ with a suitable variable).

@pmorerio
Copy link
Owner

pmorerio commented Dec 18, 2019

I wonder that why don't you use the output of modeling epistemic uncertainty

There is no fundamental reason. I just wanted to compare variance with reconstruction error and I thought subtracting ground-truth images from the single output with no dropout was more reasonable.

@ShellingFord221
Copy link
Author

As for the output of the model, in epistemic-uncertainty/model.py, it seems that when testing, you compute the variance of self.test_trials outputs as the epistemic uncertainty, then you get the output again as rec_images by disabling dropout. I think that the average of outputs with dropout should be rec_images to compute test error. (Besides, I also think that when training, average of outputs should take part in the loss function, i.e. sampling should take place in both training and testing when considering dropout as variational Bayesian approximation rather than regularization)

@pmorerio
Copy link
Owner

I think that the average of outputs with dropout should be rec_images to compute test error.

In principle, disabling dropout in test should act as averaging models, since dropout can be interpreted as a model-averaging technique: you train different sampled networks with dropout at training and take the full network at test, which is similar to take expectation under the Bernoulli (in fact you divide by the dropout probability in most implementations).

I also think that when training, average of outputs should take part in the loss function, i.e. sampling should take place in both training and testing

Not so sure about this. Average of outputs in the loss function would act as if you disable dropout during training.

@ShellingFord221
Copy link
Author

Sorry I'm confused. In What Uncertainty Do We Need in Bayesian Deep Learning for Computer Vision, it says that

Dropout variational inference ... is done by training a model with dropout before every weight layer, and by also performing dropout at test time to sample from the approximate posterior (stochastic forward passes, referred to as Monte Carlo dropout)

And according to the theory of Monte Carlo, \int p(y* | x*, w) p(w | data) dw = 1/N \sum_{n = 1}^N p(y* | x*, w_n), where w_n are samples from p(w | data), so why do you take the full network at test? I'm really confused...

@pmorerio
Copy link
Owner

Hi, I am doing dropout at test time and collecting 20 samples. With those samples I compute variance at line 75. I agree with you that I should also check the mean of the posterior here, something like

self.mean , self.var = tf.nn.moments(self.rec_images, axes=[0])

However this is the summary for self.mean, which is very bad.
image

Instead, taking the full network at test is equivalent to taking the expectation under a Bernoulli distribution of all the possible nets sampled with dropout. And the result makes more sense.
image

@pmorerio pmorerio pinned this issue Dec 19, 2019
@ShellingFord221
Copy link
Author

emmm... let's talk about 'when testing should we use dropout and average or not ' in another way. In combined model (also when testing), you disable dropout and get tf.exp(self.log_var2) as the aleatoric uncertainty. While in What uncertainty paper, Eq. 9 represents the combined model's uncertainty, and the third term
image
is the aleatoric uncertainty. The variance is averaged over T samples, which I think is a proof that we should use dropout when testing to compute (at least) variance of the data.
If I'm wrong, please correct me! Thanks!

@pmorerio
Copy link
Owner

Yes, this is quite convincing.
If you want to modify the code accordingly and open a pull request I'll be glad to merge it.
At the moment I am quite busy to it myself.

@ShellingFord221
Copy link
Author

Yeah, sure!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants