title: Keras：load_model ValueError: axes don't match array
body: <p>I'm studying gan with <a href="https://github.com/eriklindernoren/Keras-GAN/tree/master/wgan_gp" rel="noreferrer">keras-gan/wgan-gp</a> example with my own dataset. I save models with
  <code>wgan.generator.save('generator.h5')</code></p>
  
  <p><code>wgan.critic.save('critic.h5')</code></p>
  
  <p>and load with</p>
  
  <p><code>model = load_model('generator.h5')</code></p>
  
  <p><code>model = load_model('critic.h5')</code></p>
  
  <p>But this only works fine at the fist time.When I saved the models again after the second training and run </p>
  
  <p><code>model = load_model('generator.h5')</code></p>
  
  <p><code>model = load_model('critic.h5')</code></p>
  
  <p>again, the error occur ：</p>
  
  <blockquote>
    <p>ValueError                                Traceback (most recent call last)
     in ()
    ----> 1 model = load_model('generator.h5')</p>
    
    <p>D:\keras\engine\saving.py in load_model(filepath, custom_objects, compile)
        262 
        263         # set weights
    --> 264         load_weights_from_hdf5_group(f['model_weights'], model.layers)
        265 
        266         if compile:</p>
    
    <p>D:\keras\engine\saving.py in load_weights_from_hdf5_group(f, layers, reshape)
        914                                                        original_keras_version,
        915                                                        original_backend,
    --> 916                                                        reshape=reshape)
        917         if len(weight_values) != len(symbolic_weights):
        918             raise ValueError('Layer #' + str(k) +</p>
    
    <p>D:\keras\engine\saving.py in preprocess_weights_for_loading(layer, weights, original_keras_version, original_backend, reshape)
        555         weights = convert_nested_time_distributed(weights)
        556     elif layer.<strong>class</strong>.<strong>name</strong> in ['Model', 'Sequential']:
    --> 557         weights = convert_nested_model(weights)
        558 
        559     if original_keras_version == '1':</p>
    
    <p>D:\keras\engine\saving.py in convert_nested_model(weights)
        543                     weights=weights[:num_weights],
        544                     original_keras_version=original_keras_version,
    --> 545                     original_backend=original_backend))
        546                 weights = weights[num_weights:]
        547         return new_weights</p>
    
    <p>D:\keras\engine\saving.py in preprocess_weights_for_loading(layer, weights, original_keras_version, original_backend, reshape)
        555         weights = convert_nested_time_distributed(weights)
        556     elif layer.<strong>class</strong>.<strong>name</strong> in ['Model', 'Sequential']:
    --> 557         weights = convert_nested_model(weights)
        558 
        559     if original_keras_version == '1':</p>
    
    <p>D:\keras\engine\saving.py in convert_nested_model(weights)
        531                     weights=weights[:num_weights],
        532                     original_keras_version=original_keras_version,
    --> 533                     original_backend=original_backend))
        534                 weights = weights[num_weights:]
        535 </p>
    
    <p>D:\keras\engine\saving.py in preprocess_weights_for_loading(layer, weights, original_keras_version, original_backend, reshape)
        673             weights[0] = np.reshape(weights[0], layer_weights_shape)
        674         elif layer_weights_shape != weights[0].shape:
    --> 675             weights[0] = np.transpose(weights[0], (3, 2, 0, 1))
        676             if layer.<strong>class</strong>.<strong>name</strong> == 'ConvLSTM2D':
        677                 weights<a href="https://github.com/eriklindernoren/Keras-GAN/tree/master/wgan_gp" rel="noreferrer">1</a> = np.transpose(weights<a href="https://github.com/eriklindernoren/Keras-GAN/tree/master/wgan_gp" rel="noreferrer">1</a>, (3, 2, 0, 1))</p>
    
    <p>c:\users\administrator\appdata\local\programs\python\python35\lib\site-packages\numpy\core\fromnumeric.py in transpose(a, axes)
        596 
        597     """
    --> 598     return _wrapfunc(a, 'transpose', axes)
        599 
        600 </p>
    
    <p>c:\users\administrator\appdata\local\programs\python\python35\lib\site-packages\numpy\core\fromnumeric.py in _wrapfunc(obj, method, *args, **kwds)
         49 def _wrapfunc(obj, method, *args, **kwds):
         50     try:
    ---> 51         return getattr(obj, method)(*args, **kwds)
         52 
         53     # An AttributeError occurs if the object does not have</p>
    
    <p>ValueError: axes don't match array`</p>
  </blockquote>
  
  <p>I'm using </p>
  
  <p><code>Python     3.5.3</code></p>
  
  <p><code>Keras      2.2.2</code></p>
  
  <p><code>h5py       2.8.0</code></p>
  
  <p><code>tensorflow-gpu 1.9.0</code></p>
  
  <p><code>keras-contrib  2.0.8</code></p>
  
  <p><code>Keras-Applications   1.0.4</code></p>
  
  <p><code>Keras-Preprocessing 1.0.2</code></p>
  
  <p>Any advice and suggestions will be appreciated.</p>