keras-adversarial icon indicating copy to clipboard operation
keras-adversarial copied to clipboard

Keras 2 issues

Open bstriner opened this issue 7 years ago • 11 comments

Hi everybody! Just letting you know there are probably a lot of new issues with the change to Keras 2. Will update the library soon and keep you all posted.

Cheers!

bstriner avatar Mar 21 '17 22:03 bstriner

yep, let me know I can help

agulli avatar Apr 03 '17 14:04 agulli

Could you please let me know how long it may take?

ghost avatar Apr 05 '17 10:04 ghost

@agulli and @ErmiaAzarkhalili Keras-2 fixes are now in master branch.

I setup Travis. The GAN example is tested in python 2 and 3, keras 1 and 2 and tf and theano. Should be good for any configuration.

https://travis-ci.org/bstriner/keras-adversarial/builds/221544182

FYI, this is the block of renames for keras-2.

self._feed_loss_fns = self.loss_functions
self._feed_inputs = self.inputs
self._feed_input_names = self.input_names
self._feed_input_shapes = self.internal_input_shapes
self._feed_outputs = self.outputs
self._feed_output_names = self.output_names
self._feed_output_shapes = self.internal_output_shapes
self._feed_sample_weights = self.sample_weights
self._feed_sample_weight_modes = self.sample_weight_modes

In terms of examples, I fixed example_gan and example_gan_cifar10. Need to change all the calls to Dense, Conv2D, etc. to keras-2 APIs. Those changes should be obvious so no huge rush. I added a module named legacy so the examples can work in both Keras 1 and 2 without any warnings.

I'll probably leave this issue open until I get around to fixing the rest of the examples.

Please let me know if you guys run into any other compatibility issues.

Cheers

bstriner avatar Apr 12 '17 23:04 bstriner

Thank you for the quick update with keras 2 ! I have convergence issues with bigan architecture, I'm quite sure the problem comes from BatchNormalization in the discriminator. The mode argument has been removed with keras 2 (I still don't understand the reason of this choice), and it seems critical to have a sample-wise normalization in the discriminator... do you know any workaround ?

Thanks !

yaumeg avatar Apr 13 '17 14:04 yaumeg

with Tensorflow, example_gan and example_gan_convoluntional.py work correctly but there is apparently a problem with example_gan_cifar10

python example_gan_cifar10.py Using TensorFlow backend. Training: output/gan-cifar10/history.csv


Layer (type) Output Shape Param #

dense_1 (Dense) (None, 4096) 413696


batch_normalization_1 (Batch (None, 4096) 16384


reshape_1 (Reshape) (None, 4, 4, 256) 0


conv2d_1 (Conv2D) (None, 4, 4, 128) 819328


batch_normalization_2 (Batch (None, 4, 4, 128) 16


leaky_re_lu_1 (LeakyReLU) (None, 4, 4, 128) 0


up_sampling2d_1 (UpSampling2 (None, 8, 8, 128) 0


conv2d_2 (Conv2D) (None, 8, 8, 128) 409728


batch_normalization_3 (Batch (None, 8, 8, 128) 32


leaky_re_lu_2 (LeakyReLU) (None, 8, 8, 128) 0


up_sampling2d_2 (UpSampling2 (None, 16, 16, 128) 0


conv2d_3 (Conv2D) (None, 16, 16, 64) 204864


batch_normalization_4 (Batch (None, 16, 16, 64) 64


leaky_re_lu_3 (LeakyReLU) (None, 16, 16, 64) 0


up_sampling2d_3 (UpSampling2 (None, 32, 32, 64) 0


conv2d_4 (Conv2D) (None, 32, 32, 3) 4803


activation_1 (Activation) (None, 32, 32, 3) 0

Total params: 1,868,915.0 Trainable params: 1,860,667.0 Non-trainable params: 8,248.0



Layer (type) Output Shape Param #

conv2d_5 (Conv2D) (None, 32, 32, 64) 4864


max_pooling2d_1 (MaxPooling2 (None, 16, 16, 64) 0


leaky_re_lu_4 (LeakyReLU) (None, 16, 16, 64) 0


conv2d_6 (Conv2D) (None, 16, 16, 128) 204928


max_pooling2d_2 (MaxPooling2 (None, 8, 8, 128) 0


leaky_re_lu_5 (LeakyReLU) (None, 8, 8, 128) 0


conv2d_7 (Conv2D) (None, 8, 8, 256) 819456


max_pooling2d_3 (MaxPooling2 (None, 4, 4, 256) 0


leaky_re_lu_6 (LeakyReLU) (None, 4, 4, 256) 0


conv2d_8 (Conv2D) (None, 4, 4, 1) 6401


average_pooling2d_1 (Average (None, 1, 1, 1) 0


flatten_1 (Flatten) (None, 1) 0


activation_2 (Activation) (None, 1) 0

Total params: 1,035,649.0 Trainable params: 1,035,649.0 Non-trainable params: 0.0


Traceback (most recent call last): File "example_gan_cifar10.py", line 147, in main() File "example_gan_cifar10.py", line 143, in main latent_dim=latent_dim) File "example_gan_cifar10.py", line 120, in example_gan batch_size=32) File "build/bdist.macosx-10.5-x86_64/egg/keras_adversarial/legacy.py", line 18, in fit File "/Users/gulli/miniconda2/lib/python2.7/site-packages/keras/engine/training.py", line 1405, in fit batch_size=batch_size) File "/Users/gulli/miniconda2/lib/python2.7/site-packages/keras/engine/training.py", line 1295, in _standardize_user_data exception_prefix='model input') File "/Users/gulli/miniconda2/lib/python2.7/site-packages/keras/engine/training.py", line 133, in _standardize_input_data str(array.shape)) ValueError: Error when checking model input: expected conv2d_5_input to have shape (None, 32, 32, 3) but got array with shape (50000, 32, 3, 32)

agulli avatar Apr 14 '17 15:04 agulli

I am still getting the issue of this: 'AdversarialModel' object has no attribute '_feed_output_shapes'

JiteshPshah avatar Aug 11 '17 09:08 JiteshPshah

@JiteshPshah that attribute is definitely in the constructor. I'm wondering if you have an old copy somewhere. Maybe you have multiple environments and one has the wrong version.

try python -c 'import keras_adversarial; print(keras_adversarial.adversarial_model.__file__)'

See if that file has the _feed_output_shapes line that is in this link.

https://github.com/bstriner/keras-adversarial/blob/master/keras_adversarial/adversarial_model.py#L119

If that isn't the problem, please post a stack trace.

Cheers

bstriner avatar Aug 11 '17 19:08 bstriner

I still get a lot of "value passed to parameter 'shape' has DataType float32 not in list of allowed values: int32, int64" errors within the Cifar10_GAN example, so had to replace the nch/2 and nch/4 values by integers 128 and 64 after sorting this I then get the same error as aguilli: "ValueError: Error when checking input: expected conv2d_5_input to have shape (None, 32, 32, 3) but got array with shape (50000, 32, 3, 32)"

JulesVerny avatar Dec 13 '17 12:12 JulesVerny

Many people, including me, are getting the following error (there' a stackOverflow post relating to this) in example_gan_convolutional :

AttributeError: 'Model' object has no attribute 'internal_input_shapes'

tanujay avatar Feb 26 '18 22:02 tanujay

The issue with 'internal_input_shapes' can be solved by downgrading Keras to 2.0.0. Batch normalization with mode = 1 still does not work. Bigan example uses such mode so the simplest workaround is to not pass any parameter to batch normalization: b1 = BatchNormalization()

I'm not yet familiar with Keras batch normalization functionality thus don't know if the above workaround will affect bigan's performance.

It would be very helpful if keras-adversarial would work with the latest version of Keras. Is such update planned at all? If yes, any idea about when it can be ready?

Thanks a lot, Dmitry

dmitry-kopitkov avatar Mar 14 '18 12:03 dmitry-kopitkov

@JiteshPshah that attribute is definitely in the constructor. I'm wondering if you have an old copy somewhere. Maybe you have multiple environments and one has the wrong version.

try python -c 'import keras_adversarial; print(keras_adversarial.adversarial_model.__file__)'

See if that file has the _feed_output_shapes line that is in this link.

https://github.com/bstriner/keras-adversarial/blob/master/keras_adversarial/adversarial_model.py#L119

If that isn't the problem, please post a stack trace.

Cheers

That was the issue. My version of the file did not have those assignments which are meant for Keras2. I added those and it works. Is this the fix or do I have to do something to get this right?

abhijeetknayak avatar Jun 26 '19 12:06 abhijeetknayak