MokkeMeguru / TFGENZOO

Library about construction helper for Generative models e.g. Flow-based Model with Tensorflow 2.x.
https://mokkemeguru.github.io/TFGENZOO/
12 stars 2 forks source link

Could you explain a bit about the training process? #70

Closed gitlabspy closed 4 years ago

gitlabspy commented 4 years ago

I noticed you calculate the z's log_prob and add it to log_likelihood which is provided by factor_out, I don't understand this process. You bounded the log_likelihood calculation with factor_out layer, right? What if we don't factor_out , we just assume that z is normal gaussian, then how do we train? Hopefully you can provide me some guides! Thanks!!!!

MokkeMeguru commented 4 years ago

You can simply use the flag, 「conditional=False」 in all factor layer https://github.com/MokkeMeguru/TFGENZOO/blob/master/TFGENZOO/flows/factor_out.py#L40-L60

        if self.conditional:
            mean, logsd = self.split2d_prior(z1)
            ll = gaussianize.gaussian_likelihood(mean, logsd, z2)
        else:
            ll = gaussianize.gaussian_likelihood(
                tf.zeros(tf.shape(z2)), tf.zeros(tf.shape(z2)), z2
            )

This shows gaussian distribution.

Notice and Warning: Flow-based Model's gaussian distribution is not as same as Multivariational Normal Ditribution []H, W, C], but gaussian distribution x [H, W, C] times.

MokkeMeguru commented 4 years ago

(I added label because my searching problem... sry)

gitlabspy commented 4 years ago

No problem 😃, it is a question. I still have two question tho.

MokkeMeguru commented 4 years ago
  1. Yes, each element in z is independent
MokkeMeguru commented 4 years ago
  1. I'll show you the loss function in Flow-based Model negative_log_likelihood = -1 log_X(x) = -1 (log_Z(z = f(x)) + log |J|) = -1 log_Z(z = f(x)) - log |J| J means Jacobian
MokkeMeguru commented 4 years ago

2.'s reference https://github.com/tensorflow/probability/issues/720

MokkeMeguru commented 4 years ago
  1. のリファレンス TFP has too many problem, I think... https://github.com/tensorflow/probability/issues?q=MokkeMeguru
gitlabspy commented 4 years ago

Wow, I almost forgot it can be changed into z with change of variable formule. The way you implement flow is very similar to those paper source codes(glow flowpp etc.), which kinda easy for me to transform some of their codes into tf2 with your lib. I tried TFP tho, it's kinda hard for me understand the way they define shape, like event_shape, batch_shape... 😂

Thx for your explanation! It helps me a lot!

MokkeMeguru commented 4 years ago

TFP has some useful function such as Inv1x1Conv's log det jacobian function.

TFP:

We only calculate "log determinant |W| " because they estimate H x W by the "event_shape"

TFGENZOO:

We should calculate "H x W x log determinant |W|" ... However, we can write a code with its formula. (I like this style because we prevent missmatch implementation)