znxlwm / pytorch-generative-model-collections Goto Github PK
View Code? Open in Web Editor NEWCollection of generative models in Pytorch version.
Collection of generative models in Pytorch version.
Today I double check the original paper proposing wgan-gp.I found your model architecture is quietly different from original paper's where it is called cifar-10 ResNet architecture.
What's the most obvious is that there is no BN layer and and ReLu activation is used instead of Leaky-Relu activation.
Could you tell me why you use your custom-defined architecture rather than cifar-10 ResNet architecture?
Thanks!
Hi
Thanks for your wonderful code.
I read the ACGAN paper and your implementation.
I have a query, in the schematic diagram you have shown that c
is used along-with x
in the Discriminator D
. However, in the code, you have not used the class information c
while training the D
and G(z)
as you have done in CGAN ?
[1] Is it wrong to use the class information in the discriminator process ?
[2] If it is not required then shouldn't the variable y_fill_
removed ? It seems to be redundant in this case.
Also for the C_fake_loss can we use some random labels or is it required to use those labels that have been sampled from the data_loader (like you have done) ?
Thanks in advance !
I see many code like this:fake_data = G(noise).detach()
But in your most code, there is no detach, so is it just ok to omit it ?
In the WGAN_GP paper ArXiv, alpha is sampled for each example. However, it's sampled element-wise referred to WGAN_GP.
Suppose we have a tensor of the size (64, 3, 15, 15)
, I thought the correct way to sample is alpha = torch.rand(x_.size()[0])
, which returns a (64, )
tensor.
Is there something I miss or I misunderstand the paper?
When using mnist or fashion-mnist these two datasets, the "transform" of the dataloader.py should be "transforms.Compose([transforms.Resize((input_size, input_size)), transforms.ToTensor(), transforms.Normalize(mean=([0.5]), std=([0.5]))])" ,instead of "transforms.Compose([transforms.Resize((input_size, input_size)), transforms.ToTensor(), transforms.Normalize(mean=(0.5, 0.5, 0.5), std=(0.5, 0.5, 0.5))])" .
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...
Please explain how to run your own dataset. what format should be there for labels and training
Hello,
I followed the instructions for uploading a custom dataset. However, I get this error:
training start!!
Traceback (most recent call last):
File "main.py", line 111, in
main()
File "main.py", line 103, in main
gan.train()
File "C:\Users\evdelph\Desktop\NEEC\test\pytorch-generative-model-collections\GAN.py", line 144, in train
D_real = self.D(x_)
File "C:\Users\evdelph\AppData\Local\Programs\Python\Python38\lib\site-packages\torch\nn\modules\module.py", line 532, in call
result = self.forward(*input, **kwargs)
File "C:\Users\evdelph\Desktop\NEEC\test\pytorch-generative-model-collections\GAN.py", line 67, in forward
x = x.view(-1, 128 * (self.input_size // 4) * (self.input_size // 4))
RuntimeError: shape '[-1, 6272]' is invalid for input of size 3276800
I am not sure how to fix this error. I am trying to generate images of ships for a school project.
Any insight would be great. Thanks!
Thanks for your great work! I have a question about the gradient penalty part in WGAN_GP model. From line 189 to line 194, I know that these codes compute the gradients of the pred_hat with respect to x_hat, but I don't know why you add [0] in the end. Would you please do some explanations to that? Thank you very much!
Hi,
Thanks for the wonderful code.
I tried directly using the ACGAN code for training conditional GAN on CIFAR10 but it seems hard to generate high fidelity images. I wonder if you guys feels the same? or is there something special to look at when training CIFAR10?
Thanks
/home/yangkaixing/miniconda3/envs/GASDA/lib/python3.6/site-packages/torch/nn/functional.py:1806: UserWarning: nn.functional.sigmoid is deprecated. Use torch.sigmoid instead.
warnings.warn("nn.functional.sigmoid is deprecated. Use torch.sigmoid instead.")
Traceback (most recent call last):
File "main.py", line 112, in
main()
File "main.py", line 104, in main
gan.train()
File "/data/yangkaixing/Generative_Model_Collections/infoGAN.py", line 230, in train
info_loss.backward()
File "/home/yangkaixing/miniconda3/envs/GASDA/lib/python3.6/site-packages/torch/_tensor.py", line 307, in backward
torch.autograd.backward(self, gradient, retain_graph, create_graph, inputs=inputs)
File "/home/yangkaixing/miniconda3/envs/GASDA/lib/python3.6/site-packages/torch/autograd/init.py", line 156, in backward
allow_unreachable=True, accumulate_grad=True) # allow_unreachable flag
RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [64, 3, 4, 4]] is at version 2; expected version 1 instead. Hint: enable anomaly detection to find the operation that failed to compute its gradient, with torch.autograd.set_detect_anomaly(True).
infogan line 102 when I try to apply it on celebA with size (channel,height,width) as (3,180,180)
as the code below, the data from dataloader size is (batch,channel,height,width), but when choose the [0] the data size become (3,180,180), so at the
self.D = discriminator(input_dim=data.shape[1]
the input_dim become 180 rather than 3,I remove the [0] to fix it
data = self.data_loader.__iter__().__next__()[0]
# networks init
self.G = generator(input_dim=self.z_dim, output_dim=data.shape[1], input_size=self.input_size, len_discrete_code=self.len_discrete_code, len_continuous_code=self.len_continuous_code)
self.D = discriminator(input_dim=data.shape[1], output_dim=1, input_size=self.input_size, len_discrete_code=self.len_discrete_code, len_continuous_code=self.len_continuous_code)
When I run your CGAN program ,the following error message has occured:
D:\ProgramData\Anaconda3\python.exe I:/gupaocode/pytorch-generative-model-collections-master/main.py --dataset mnist --gan_type CGAN --epoch 50 --batch_size 64
Traceback (most recent call last):
File "I:/gupaocode/pytorch-generative-model-collections-master/main.py", line 111, in
main()
File "I:/gupaocode/pytorch-generative-model-collections-master/main.py", line 82, in main
gan = CGAN(args)
File "I:\gupaocode\pytorch-generative-model-collections-master\CGAN.py", line 94, in init
data = self.data_loader.iter().next()[0]
File "D:\ProgramData\Anaconda3\lib\site-packages\torch\utils\data\dataloader.py", line 517, in next
data = self._next_data()
File "D:\ProgramData\Anaconda3\lib\site-packages\torch\utils\data\dataloader.py", line 557, in _next_data
data = self.dataset_fetcher.fetch(index) # may raise StopIteration
File "D:\ProgramData\Anaconda3\lib\site-packages\torch\utils\data_utils\fetch.py", line 44, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "D:\ProgramData\Anaconda3\lib\site-packages\torch\utils\data_utils\fetch.py", line 44, in
data = [self.dataset[idx] for idx in possibly_batched_index]
File "D:\ProgramData\Anaconda3\lib\site-packages\torchvision\datasets\mnist.py", line 106, in getitem
img = self.transform(img)
File "D:\ProgramData\Anaconda3\lib\site-packages\torchvision\transforms\transforms.py", line 60, in call
img = t(img)
File "D:\ProgramData\Anaconda3\lib\site-packages\torch\nn\modules\module.py", line 889, in call_impl
result = self.forward(*input, **kwargs)
File "D:\ProgramData\Anaconda3\lib\site-packages\torchvision\transforms\transforms.py", line 221, in forward
return F.normalize(tensor, self.mean, self.std, self.inplace)
File "D:\ProgramData\Anaconda3\lib\site-packages\torchvision\transforms\functional.py", line 336, in normalize
tensor.sub(mean).div(std)
RuntimeError: output with shape [1, 28, 28] doesn't match the broadcast shape [3, 28, 28]
The generative model community is also interested in understanding a lot of about images from their latent representations. This is where BiGAN/AliGAN come into play.
BiGAN:
https://arxiv.org/abs/1605.09782
https://github.com/jeffdonahue/bigan
AliGAN:
https://arxiv.org/abs/1606.00704
https://github.com/IshmaelBelghazi/ALI
Will you also accept BiGAN/AliGAN PR?
I managed to fix this issue by placing them in another folder called 1, so my directory is now, data/strawberriesBlack/1/B(1).jpg
However, my results are completely blank after 50 epochs on GAN
My dataset is currently coloured, do you think I should change to grayscale?
How big should said dataset actually be?
Thanks in advance
Originally posted by @HamzahNizami in #18 (comment)
Have u ever successfully ran this example yet? :)Did you get your strawberries?
if list(self.margin-D_fake_err.data)[0] > 0: D_loss = D_real_err + (self.margin - D_fake_err) else: D_loss = D_real_err self.train_hist['D_loss'].append(D_loss.data[0])
The error is in the above line no 190 .... Below Code worked for me .. am i Correct ? I removed word list and [0]
if (self.margin-D_fake_err.data) > 0: D_loss = D_real_err + (self.margin - D_fake_err) else: D_loss = D_real_err self.train_hist['D_loss'].append(D_loss.data[0])
Thanks for this cool codebase that allows one to use many GANs!
But it seems that only the mnist dataset can be loaded, because the other functions are missing from the utils module. For example, if I issue this command:
python main.py --dataset celebA --gan_type WGAN --epoch 25 --batch_size 64
This results in the traceback:
Traceback (most recent call last): │·····
File "main.py", line 107, in <module> │·····
main() │·····
File "main.py", line 86, in main │·····
gan = WGAN(args) │·····
File "WGAN.py", line 130, in __init__
│self.data_loader = utils.load_celebA('data/celebA', transform=transforms.Compose(
│AttributeError: module 'utils' has no attribute 'load_celebA'
Are you iterating on all the DS in each D iteration? I don't see this is the case here.
Could you show your loss outout please ? I'm having very weird output
started at D: -31699812.0 G: -1.2754488e+21
and now fixed at D: 0.25 G: 6.751009
I'm checking gradient and it is zero every where .
Btw I'm not normalizing my DS do you think it is the reason ?
The option of dataset doesn't include celebA, but there is a function named load_celebA in utils.py.
How can I use the celebA dataset?
Hello @znxlwm,
I have noticed that the GAN models are all defined with model.cuda()
that use only one device. Is there any way to train them with multiple gpus so that the input size can be increased without decreasing teh batch size? Thank you.
i run the original code,but i get this problem.and i don't know why
can you help me thx (👍
Here is the first two layers gradient in some iteration the gradient is very high and disturb the notwork as you can see in the image below. As far as I know WGAN-GP is to stable the gradient. how could we fix this problem ?
https://imgur.com/a/LHcb3
Great job. By the way, I found this line of code doubtful:
Maybe this line should be changed into:
a = F.sigmoid(x[:, : self.output_dim])
can you add hinge loss
Hi!
I am curious why there is no mode in the ACGAN-PyTorch version while it exists in the TensorFlow version given in the link.
In fact, I am more curious because I ran ACGAN-TensorFlow+Keras (link) and found mode collapse. Now, running Pytorch version (link), and so far, there is no sign of mode collapse. BTW, I ran implementations from same author.
So, did you find/analyze the reason why it works perfectly in Pytorch, but not in TensorFlow?
Thanks in advance
Dear author,
Thanks for your friendly implementation of popular GANs. I am reading your implementation of Wasserstein GANs, and notice that the gradient clip operation is placed after optimizer.step as seen in this line.
Typically, in pytorch, the gradient operation is placed before the optimizer step.
pls have a check.
getting this error when training with my own database?
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.