hwalsuklee / tensorflow-generative-model-collections Goto Github PK
View Code? Open in Web Editor NEWCollection of generative models in Tensorflow
License: Apache License 2.0
Collection of generative models in Tensorflow
License: Apache License 2.0
The mnist dataset has a tag file but the label of the celebA dataset represents more than just a class of images, some of which represent several classes. How to deal with celebA's label?
See here, updates_collections=None
which means moving_mean
and moving_var
won't be put into tf.GraphKeys.UPDATE_OPS
. so tf.get_collection(tf.GraphKeys.UPDATE_OPS) is []
, I think it's a bug.
But if you just delete updates_collections=None
, it can't work. Because there are two graphs for discriminators and there are different moving_mean
and moving_var
for different graph. So I think you should use different tf.control_dependencies
for discriminator and generator.
In InfoGAN.py line 146, the squared loss is being optimized as follows.
cont_code_est = code_fake[:, self.len_discrete_code:]
cont_code_tg = self.y[:, self.len_discrete_code:]
q_cont_loss = tf.reduce_mean(tf.reduce_sum(tf.square(cont_code_tg - cont_code_est), axis=1))
The code_fake
vector is in [0,1] as it comes from a softmax non-linearity. The actual latent code being sent, however, is in [-1,1]. (See line 234).
batch_codes = np.concatenate((batch_labels, np.random.uniform(-1, 1, size=(self.batch_size, 2))),
axis=1)
Am I missing something?
Thank you for sharing your codes.
I found that there is no weight clipping in the paper Least Squares Generative Adversarial Networks. The weight clipping is used in the paper Loss-Sensitive Generative Adversarial Networks on Lipschitz Densities. Obviously, your code is the former.
I tried both situations, and the performance is better without weight clipping.
I changed the network structure and adjusted the super-parameters to apply to data cifar-10. I thought maybe someone needed it, so I left the url of my code.
https://github.com/AliceAria/Performance-comparison-of-GAN-on-cifar-10
Thanks again.
Hey, I appreciate your work! You make my life better.
I found (maybe) a small bug in your WGAN_GP code. When calculating gradient penalty, you write:
D_inter,_,_=self.discriminator(interpolates, is_training=True, reuse=True)
gradients = tf.gradients(D_inter, [interpolates])[0]
You use the sigmoid output of the Discriminator, not the logits.
In the original implementation (https://github.com/igul222/improved_wgan_training/blob/master/gan_mnist.py), they write this:
gradients = tf.gradients(Discriminator(interpolates), [interpolates])[0]
Here, the authors only return the logits of the Discriminator. So they use the logits for this calculation.
Did you do this on purpose?
Greetings!
at 113 line in WGAN_GP, I recommend changing the code
alpha = tf.random_uniform(shape=self.inputs.get_shape(), minval=0.,maxval=1.)
to
alpha = tf.random_uniform(shape=[BATCH_SIZE,1,1,1], minval=0.,maxval=1.)
Because It must be created one alpha value for each batch
Thank you very much for sharing your perfect code with everyone. I learned a lot from it. I found that in all GAN networks, your input data is binary image data like mnist. I wonder if you have any modifications to the input training data. You can enter color images or grayscale images into the network for training. If you make a change, can you share me an improved code and let me learn your method.
Regardless of whether you have made any changes, I thank you very much for sharing.
Can you include a code for f-GAN?
[1606.00709] f-GAN: Training Generative Neural Samplers using Variational Divergence Minimization
Thanks for your great work! I find that the discriminatior in LSGAN calculated by sigmoid(logits). But according to the original paper D(x) should be logits directly. If the sigmoid function is used in D(x), the problem of gradient vanishing still exists. I'm not sure whether i misinterpreted the idea of the paper.
Thank you for your working and sharing. I learned a lot from them.
However, I have a question about the VAE implementation.
In VAE.py, you calculate the marginal_likelihood as an cross entropy:
marginal_likelihood = tf.reduce_sum(self.inputs * tf.log(self.out) + (1 - self.inputs) * tf.log(1 - self.out),[1, 2])
However, I am confusing as the formular is :
where the first item on the right side should correspond to the marginal_likelihood. I think the latent variable z should be included to calculate the likelihood but you use the initial input, self.inputs.
So I am a little confusing, can you explain it?
Thank you very much!
Hi, I'm the author of Fashion-MNIST dataset. I found the GANs results on Fashion-MNIST is very interesting, especially how ACGAN and infoGAN failed on Fashion-MNIST. I already highlighted this notebook in Fashion-MNIST README.md. I hope it is ok for you. 🙇
Here are the links:
https://github.com/zalandoresearch/fashion-mnist#other-explorations-of-fashion-mnist
https://github.com/zalandoresearch/fashion-mnist/blob/master/README.zh-CN.md#生成对抗网络-gans
Hi @hwalsuklee !
It's a little bit odd that we can't find the filter 'data' ?
So we have to download mnist and fashion-mnist ?
Thank for your work! I'm confused about the batch normalization layer used in the discriminator of wgan_gp. I think there shouldn't be any batch normalization layer in the discriminator.
I think the reason is that the gradient penalty term directly otimizes the gradient loss of each vector sampled between data distribution and generated distribution, each of the vectors has its gradient and the gradient is independent of all other vectors, so the gradient penalty must be calculated separately w.r.t. each sampled vector. If batch normalization is applied in discriminator, the region constrained by 1-Lipchitz, I guess, would be somewhere else instead of "the region between data distribution and generated distribution".
I'm not sure whether i misinterpreted the idea of wgan-gp paper.
Hi,I have run your VAE and CVAE models, but I found that it converged very fast, didn't need more than 2 or 3 epoch, but the results in them are very good. It confused me ,would you please give me some explanation when you are free?
Thanks for your code! I found that Discriminator los sfunction of w-gan is the same as Discriminator los sfunction of gan in your code,but actually not! Pleace check it!
Thanks for sharing the code.
However, it seems the Tensorflow VAE doesn't have implementation for color images, eg. cifar10 data, only MNIST and fashion MNIST is available.Also, the Pytorch version doesn't have VAE implementation at all.
Is there anyway to use VAE for color mages. Thanks.
Hey @hwalsuklee,
Thanks for sharing your code which helps me a lot. I have a question about the linear function in ops.py
I would be appreciated if you can explain what you are doing in the this function.
def linear(input_, output_size, scope=None, stddev=0.02, bias_start=0.0, with_w=False):
shape = input_.get_shape().as_list()
with tf.variable_scope(scope or "Linear"):
matrix = tf.get_variable("Matrix", [shape[1], output_size], tf.float32,
tf.random_normal_initializer(stddev=stddev))
bias = tf.get_variable("bias", [output_size],
initializer=tf.constant_initializer(bias_start))
if with_w:
return tf.matmul(input_, matrix) + bias, matrix, bias
else:
return tf.matmul(input_, matrix) + bias
Also, It would be great if you add some comments when you are implementing; to be much easier for others to understand.
Thanks.
Hi @hwalsuklee ,
Thank you for sharing this neat-n-clean code... It's really helpful.
I have two requests:
1. Could you please provide a model to generate RGB data like: CIFAR 10 or SVHN. From your past comments, I realized that you are working on CelebA dataset. Would you be so kind to share your code on those (above-mentioned dataset) too?
2. It seems Co-GAN is missing. Would you be so kind to provide a code for Co-GAN too...!!
Thank you again for sharing your code,
With Best Regards,
Arghya.
Any plans for implementing DR-GAN?
thanks you code , when i read the code , the discriminator use sigmoid output, but you also return D_real_logits ,and when caluate the loss real or fake ,you use D_real_logits or D_fake_logits before sigmoid output ; why you don't use the D_real or D_fake ,the sigmoid ouput?
# get loss for discriminator d_loss_real = - tf.reduce_mean(D_real_logits) d_loss_fake = tf.reduce_mean(D_fake_logits)
thank ,can you help me?
You have this line in all the constructors:
if dataset_name == 'mnist' or 'fashion-mnist':
It will always be True
. You want if dataset_name == 'mnist' or dataset_name == 'fashion-mnist'
or if dataset_name in ['mnist', 'fashion-mnist']
.
I've noticed an inefficiency in the CGAN code. When we append the one-hot encoded labels to the image, they influence the training gradients a lot. Instead, I've noticed that scaling the one-hot encoded labels down by a factor of 0.01 or even 0.001 helps the CGAN converge around twice as fast.
That would mean changing opts.py's conv_cond_concat function. My hack was to change return concat([x, y*tf.ones([x_shapes[0], x_shapes[1], x_shapes[2], y_shapes[3]])], 3)
to return concat([x, 0.001*y*tf.ones([x_shapes[0], x_shapes[1], x_shapes[2], y_shapes[3]])], 3)
and that worked well for me. I'm not too sure about in general though, perhaps try adding batch norm?
Thanks for the nicely orgnized code, I learned a lot from it. But I have question about the CVAE's input, you just append y's 1-hot code to the last dimension of x, so it makes the original data up to 11 times larger (the image shape becomes 28 * 28 * 11). But why not just append y in the middle of the encoding process, say, when we get a flat vector after several conv2d transformation, then we could append y to this flat vector?
can you add hinge loss
Hello @hwalsuklee, thanks for the repo!
Would i be a good idea to also add the FID score and/or inception score to the various experiments?
Thanks!
Thanks for your contribution!
A problem occurs when I am training ACGAN without tuning any parameters which is shown as follows:
As the training process goes on, the loss of D is declining, but the loss of G is increasing on the contrary...and the gap between two of them is pretty large. I do not know how to solve it...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.