Companion repository to GANs in Action: Deep learning with Generative Adversarial Networks
Companion repository to GANs in Action: Deep learning with Generative Adversarial NetworksCategory: Python / Deep Learning |
Watchers: 37 |
Star: 883 |
Fork: 375 |
Last update: Jun 14, 2022 |
I'm not sure if there's something misconfigured in my computer or what, but in every single run I'm getting this kind of outputs (very different from the proposed ones) and the resulting images are still noise.
1000 [D loss: 0.000010, acc.: 100.00%] [G loss: 0.025414] 2000 [D loss: 0.000516, acc.: 100.00%] [G loss: 0.012415] 3000 [D loss: 0.000217, acc.: 100.00%] [G loss: 0.012707] 4000 [D loss: 0.000276, acc.: 100.00%] [G loss: 0.015317] 5000 [D loss: 0.000011, acc.: 100.00%] [G loss: 0.004400] 6000 [D loss: 0.000001, acc.: 100.00%] [G loss: 0.000662] 7000 [D loss: 0.000000, acc.: 100.00%] [G loss: 0.000308] ...
Is there something to fix in the source code?
Hi, @vbok @jakubLangr ,
I had gone through ch9-nb, and would like to study the contents in details, could you release the contents of Ch9 CycleGAN on manning website in advance?
THX
Hi, authors,
In page 51, it is mentioned as:
6. Use transposed convolution, transforming the 28x28x64 tensor into the output image
size, 28x28x1.
However, according to Fig.4.2, it should be the following:
6. Use transposed convolution, transforming the 14x14x64 tensor into the output image
size, 28x28x1.
Please clarify for this. THX!
The original code is:
# Train Generator
g_loss = gan.train_on_batch(z, np.ones((batch_size, 1)))
But the generator generates fake images, so I think the input of gan.train_on_batch is fake=np.zeros((batch_size, 1))
# Train Generator
g_loss = gan.train_on_batch(z, np.zeros((batch_size, 1)))
After running the training code:
cycle_gan = CycleGAN()
cycle_gan.train(epochs=100, batch_size=64, sample_interval=10)
Receiving Below Error
Hi, I am reading the chapter 4 of this book and there seem to be some problem. The code written in this book is from Keras but when I do the code I prefer to use tf.keras which should not be different. I implemented the code written in chapter 4 using tf.keras and I got strange result like the loss of discriminator and generator approached 0 and the acc. to 1. Also the result in image-grid is just noise. But when I removed the BathcNormalization layer out of both generator and discriminator, I got fine fake digit images. Any Idea why????
this is the colab containing the code https://colab.research.google.com/drive/1TF-nkPPkj0HAzKceb3UL_AzSdb-0DjKD?usp=sharing
I tried the cGAN code from Chapter 8 previously on April 9th on my computer, and it worked. But this is not working recently (a corresponding google colab link of the python notebook). Can you give any idea why it is not working? Or, can you share your current version of packages with which this code is working? !pip freeze from google colab is attached. Thank you.
If I am using an RGB image dataset, e.g. cifar10 dataset, how do I edit the discriminator and generator?
I use the colab environment to run it. keras or tensorflow.keras: 2.4.3 or 2.4.0. tensorflow: 2.4.1
The code is the same, but only noise diagrams appear after running. I tried replacing the optimiser with RMSprop and it also only produces noise diagrams
the below errors occurred when i ran the Chapter_2_Autoencoder.ipynb my env is the colab
Epoch 1/50
TypeError Traceback (most recent call last)
9 frames /usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/func_graph.py in wrapper(*args, **kwargs) 975 except Exception as e: # pylint:disable=broad-except 976 if hasattr(e, "ag_error_metadata"): --> 977 raise e.ag_error_metadata.to_exception(e) 978 else: 979 raise
TypeError: in user code:
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:805 train_function *
return step_function(self, iterator)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:795 step_function **
outputs = model.distribute_strategy.run(run_step, args=(data,))
/usr/local/lib/python3.6/dist-packages/tensorflow/python/distribute/distribute_lib.py:1259 run
return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/distribute/distribute_lib.py:2730 call_for_each_replica
return self._call_for_each_replica(fn, args, kwargs)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/distribute/distribute_lib.py:3417 _call_for_each_replica
return fn(*args, **kwargs)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:788 run_step **
outputs = model.train_step(data)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:756 train_step
y, y_pred, sample_weight, regularization_losses=self.losses)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/compile_utils.py:238 __call__
total_loss_metric_value, sample_weight=batch_dim)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/utils/metrics_utils.py:90 decorated
update_op = update_state_fn(*args, **kwargs)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/metrics.py:177 update_state_fn
return ag_update_state(*args, **kwargs)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/metrics.py:364 update_state **
sample_weight, values)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/weights_broadcast_ops.py:155 broadcast_weights
values = ops.convert_to_tensor(values, name="values")
/usr/local/lib/python3.6/dist-packages/tensorflow/python/profiler/trace.py:163 wrapped
return func(*args, **kwargs)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py:1540 convert_to_tensor
ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/constant_op.py:339 _constant_tensor_conversion_function
return constant(v, dtype=dtype, name=name)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/constant_op.py:265 constant
allow_broadcast=True)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/constant_op.py:283 _constant_impl
allow_broadcast=allow_broadcast))
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/tensor_util.py:435 make_tensor_proto
values = np.asarray(values)
/usr/local/lib/python3.6/dist-packages/numpy/core/_asarray.py:83 asarray
return array(a, dtype, copy=False, order=order)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/keras_tensor.py:274 __array__
'Cannot convert a symbolic Keras input/output to a numpy array. '
TypeError: Cannot convert a symbolic Keras input/output to a numpy array. This error may indicate that you're trying to pass a symbolic value to a NumPy call, which is not supported. Or, you may be trying to pass Keras symbolic inputs/outputs to a TF API that does not register dispatching, preventing Keras from automatically converting the API call to a lambda layer in the Functional Model.
I'm trying to run the DCGAN from chapter 5; the code performs well and the generated images are good.
But when I change the source code so that it becomes compatible with tf.keras rather than keras, the model produces useless images that are obviously just noise
The following is the only bit of the code I've changed. From:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
from keras.datasets import mnist
from keras.layers import Activation, BatchNormalization, Dense, Dropout, Flatten, Reshape
from keras.layers import LeakyReLU
from keras.layers import Conv2D, Conv2DTranspose
from keras.models import Sequential
from keras.optimizers import Adam
to:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
from tensorflow.keras.datasets import mnist
from tensorflow.keras.layers import Activation, BatchNormalization, Dense, Dropout, Flatten, Reshape
from tensorflow.keras.layers import LeakyReLU
from tensorflow.keras.layers import Conv2D, Conv2DTranspose
from tensorflow.keras.models import Sequential
from tensorflow.keras.optimizers import Adam
I've even tried to enforce tf_1 compatability with
tf.compat.v1.disable_v2_behavior()
but performance remains poor. Any ideas?