keras-GAN | Generative Adversarial Networks with Keras | Machine Learning library
kandi X-RAY | keras-GAN Summary
kandi X-RAY | keras-GAN Summary
Generative Adversarial Networks with Keras
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Gaussian log likelihood .
keras-GAN Key Features
keras-GAN Examples and Code Snippets
Community Discussions
Trending Discussions on keras-GAN
QUESTION
I'm tried to implement basic GAN in Keras, based on this implementation.
If I sample points on parabola GAN is converges and able to produce samples from this distribution, but if for example I sample points on circle it fails. I wonder why it's hard for GAN? How it can be fixed?
Here is learning process for parabola:
Here is learning process for circle:
Here is the code to reproduce:
...ANSWER
Answered 2021-Feb-21 at 11:39As you can see from the accuracy plots you have in Tensorboard, your principal problem here is with the discriminator. Because its accuracy oscillates around 50-60% and doesn't improve. And this is very bad because the generator is downstream and can't train until the discriminator achieves decent accuracy. So what is wrong with the discriminator?
First, it is the way you train it. You feed it positive and negative samples in two separate batches. This can generate gradients pushing your model coefficients randomly in opposite directions with very poor convergence. If you combine both types of samples in a single batch, convergence will improve significantly.
Second, the batch size. 32 random points around a circle is too little for the model to feel the difference against 32 random points. You need to have a batch size of at least 256.
Third, the number of neurons in hidden layers. Actually, you have too many neurons for such simple data in both generator and discriminator. Having too many of them in the discriminator doesn't seem to do much harm, but having too many neurons in the generator makes it too unstable, the discriminator each time receives different training data and this is one more reason why it fails to train properly. If you put 16 and 32 hidden neurons instead of 64 and 128 into the generator, it will be much better.
And the last point: it is not only the circular form that makes your circle difficult to learn but also its size. It has a radius of 1, and 1 is the saturation value of your generator, so it is very easy for it to produce values around 1. And this makes additional trouble for the generator: it starts receiving fake data too close to the true data before it achieves decent accuracy.
To summarize:
- Combine true and fake data into a single batch.
- Use a larger batch size (at least 256).
- Reduce the number of neurons at least in the generator (e.g. to 16 and 32).
And one more thing: it is better to ask such questions in this community https://stats.stackexchange.com/.
QUESTION
I am running the Generative Adversarial Network in my personal system and I am getting the error provided as below, it may be because of GPU accessing problem as explained in this link: (Function call stack: keras_scratch_graph Error)
Since I want to run the code in my personal system which does not consist with GPU then how to manage that the code should not access the GPU?
The python code is provided in this link: (https://github.com/eriklindernoren/Keras-GAN/tree/master/pix2pix), where the running code is present in pix2pix.py file.
Produced Error is as follow:
...ANSWER
Answered 2020-Apr-08 at 17:46This error has been resolved when I have changed the
QUESTION
I am trying to run the code from here which is an implementatino of Generative Adversarial Networks using keras python. I followed the instructions and install all the requirements. Then i tried to run the code for DCGAN. However, it seems that there is some issue with the compatibility of the libraries. I am receiving the following message when i am running the code:
...AttributeError: 'module' object has no attribute 'leaky_relu'
ANSWER
Answered 2018-Feb-22 at 14:22According to this answer, leaky_relu
was added to tensorflow on version 1.4. So you might wanna check if your tensorflow installation is at least on version 1.4.
QUESTION
Essentially, I want an implementation of this custom Keras layer:
...ANSWER
Answered 2019-Nov-25 at 20:48It turns out that I was close with attempt #2. In the code in the question, in_shape[0]
is a scalar, and I was trying to concatenate it with K.ones_like(in_shape[1:], dtype='int32')
, which is a vector. Simply changing in_shape[0]
to in_shape[0:1]
was enough to fix the error and compile my model successfully.
Final code:
QUESTION
I am trying to use Keras on my machine but I keep getting the error message "AttributeError: module 'tensorflow.python.keras.backend' has no attribute 'get_graph'".
Stack Trace is:
...ANSWER
Answered 2019-Sep-28 at 17:49I couldn't reproduce the error you observe with Keras 2.3.0 & tensorflow 2.0.0rc1. Although, I was able to start the training of acgan, I got a different error after one iteration: Resource localhost/_AnonymousVar84/N10tensorflow3VarE does not exist
.
I could successfully run the example with the following versions:
- Keras 2.2.4/tensorflow 1.14.0
- tensorflow 2.0.0rc1 and replace
keras
withtensorflow.keras
in the imports.
QUESTION
I am confused with the .trainable
statement of tf.keras.model
in the implementation of a GAN.
Given following code snipped (taken from this repo):
...ANSWER
Answered 2019-Nov-11 at 17:16Its usually a good idea to check the issues (both open and closed) when you have a question about code in a github repo. This issue explains why the flag is set to False
. It says,
Since
self.discriminator.trainable = False
is set after the discriminator is compiled, it will not affect the training of the discriminator. However since it is set before the combined model is compiled the discriminator layers will be frozen when the combined model is trained.
And also talks about freezing keras layers.
QUESTION
I've just seen
...ANSWER
Answered 2019-Aug-14 at 09:43This model has multiple inputs (two) and multiple outputs (six), so you need to specify one loss function for each output. That's why there is a list of losses.
Additionally a model can only be trained with a single loss function, and for a multi-output model, this is accomplished by creating a virtual loss that is a weighted combination of all per-output losses, and this is what the loss_weights
parameter is for.
QUESTION
I'm trying to understand the code for a DCGAN made with Keras, that creates a model with the sequential api and then wraps that in a functional api model. Why include the functional model as opposed to just using the sequential model?
I'm a bit of a beginner and I'm trying to understand the design of this Keras GAN:
https://github.com/eriklindernoren/Keras-GAN/blob/master/dcgan/dcgan.py
For example, in building the generator, the model is defined with the Sequential API and then a new model is made with the functional API and the sequential model.
...ANSWER
Answered 2019-Aug-01 at 17:29Sequential and functional models are in pratice the same. Except that for functional model you can create more complex architectures because every layers are stored with variables. And it is handy when you don't have unique "linear" model and GANs are among them.
An exampe of a model built with the functional API :
QUESTION
I'm more familiar with tensorflow graph training than Keras, but I'm trying out Keras here.
In building a GAN the generator needs be optimized against a different loss than the discriminator (the opposite loss). In base tensorflow this is easy enough to implement using either 2 optimizers or by calling optimizer.compute_gradients(...)
and optimizer.apply_gradients(...)
separately with the appropriate group of weights.
In Keras, I don't see that I can achieve either of these. In implementations such as Keras-GAN, it appears that the training of generator and discriminator are split into separate models and then trained independently batch-by-batch. This means many more passes are required per effective update than would be required with the base tensorflow implementation with two optimizers operating on one pass.
Is there a way to implement the optimizer for GANs so that both generator and discriminator get trained in one pass in Keras?
TF 1.14
...ANSWER
Answered 2019-Jul-15 at 22:48This is a really tough question for Keras for several reasons:
A model can only have one optimizer... it would be necessary to change the source code for it to accept two or more
Even when you are using a custom optimizer, it would be possible to separate the weights, but it doesn't offer support to separate the losses, as can be seen in the source code for optimizers. The probability is that the optimizer already computes a final common loss (which would then make it impossible to attribute one loss for a group of weights and another for the other group)
The training mechanisms are not easy to find in the code. Things are spread all around, supporting many things such as loss weights, sample weights, etc. The time that it would take to summarize everything and then decide what to do/change would be too much.
Make your model in Keras as you would. The discriminator, the generator, their connections and outputs.
Just don't compile it. Instead, keep track of the main tensors (generator output, discriminator output, generator input), create the loss functions in Tensorflow style and train everything in tensorflow style.
QUESTION
I am trying to run https://github.com/eriklindernoren/Keras-GAN/blob/master/pix2pix/pix2pix.py
...ANSWER
Answered 2019-May-29 at 10:36It's not throwing any error. So I'm guessing the script isn't finding the training dataset. Try downloading the dataset and try running it again.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install keras-GAN
You can use keras-GAN like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page