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

Running example_aae

Open stepjam opened this issue 8 years ago • 4 comments

Hi again,

When running the example_aae.py, I get the following error: I am running tensorflow as the backend

Traceback (most recent call last):
  File "examples/example_aae.py", line 140, in <module>
    main()
  File "examples/example_aae.py", line 136, in main
    example_aae("output/aae", AdversarialOptimizerSimultaneous())
  File "examples/example_aae.py", line 71, in example_aae
    encoder = model_encoder(latent_dim, input_shape)
  File "examples/example_aae.py", line 46, in model_encoder
    output_shape=lambda p: p[0])
  File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 1680, in merge
    name=name)
  File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 1301, in __init__
    self.add_inbound_node(layers, node_indices, tensor_indices)
  File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 635, in add_inbound_node
    Node.create_node(self, inbound_layers, node_indices, tensor_indices)
  File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 172, in create_node
    output_tensors = to_list(outbound_layer.call(input_tensors, mask=input_masks))
  File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 1383, in call
    return self.mode(inputs, **arguments)
  File "examples/example_aae.py", line 45, in <lambda>
    z = merge([mu, log_sigma_sq], mode=lambda p: p[0] + K.random_normal(p[0].shape) * K.exp(p[1] / 2),
AttributeError: 'Tensor' object has no attribute 'shape'

stepjam avatar Jan 30 '17 11:01 stepjam

Ah, turns out I don't actually need the Gaussian posterior, but instead a deterministic one. So this isn't a problem for me anymore. But I guess it still handy for you to know about the problem for future users.

Edit: Also, out of interest, have you tried your solution for AAE with rgb images (e.g. cifar10) and a conv-net for the encoder?

stepjam avatar Jan 30 '17 12:01 stepjam

@stepjam Thanks! I wouldn't have noticed that for a while. I need to change that to K.shape(p[0]) instead of p[0].shape and it'll work on both backends.

What are you trying to build? Do you mean discrete? Not sure what a deterministic posterior would look like.

Haven't written an AAE CNN example yet but I assume it would have some better performance. Just need to swap out the models in the AAE example.

Cheers

bstriner avatar Jan 30 '17 18:01 bstriner

Just for comparison when you get around to it, here is a sample my trained autoencoder output after 100 epochs on the cifar10 dataset:

autoencoded-epoch-099

(Input image on the left) This was using a conv-net for the encoder, and a de-conv for the generator/decoder.

stepjam avatar Jan 30 '17 19:01 stepjam

@stepjam fixed the example and added an example for AAE cifar10. It runs but I need to pick some better parameters to make it look good.

It is trivially easy to make an AAE that autoencodes well. An autoencoder does as much. The harder part is making the generated samples also look good. I'll let you know when I clean up the example.

bstriner avatar Feb 06 '17 20:02 bstriner