Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: Unable to load weights 03_04_vae_digits_analysis.ipynb #85

Open
Lana2548 opened this issue Feb 23, 2021 · 2 comments
Open

Comments

@Lana2548
Copy link

From Japan.
I'm not good at English, so it may be hard to read. Sorry.

  • Anaconda
  • Nvidia GTX 1070

When I used load_model() in 03_04_vae_digits_analysis.ipynb, I got an error message.


ValueError Traceback (most recent call last)
in
----> 1 vae = load_model(VariationalAutoencoder, RUN_FOLDER)

~\Desktop\study\GDL_code\utils\loaders.py in load_model(model_class, folder)
138 model = model_class(*params)
139
--> 140 model.load_weights(os.path.join(folder, 'weights/weights.h5'))
141
142 return model

~\Desktop\study\GDL_code\models\VAE.py in load_weights(self, filepath)
204
205 def load_weights(self, filepath):
--> 206 self.model.load_weights(filepath)
207
208 def train(self

~\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\keras\engine\training.py in load_weights(self, filepath, by_name, skip_mismatch, options)
2221 if not self._is_graph_network and not self.built:
2222 raise ValueError(
-> 2223 'Unable to load weights saved in HDF5 format into a subclassed '
2224 'Model which has not created its variables yet. Call the Model '
2225 'first, then load the weights.')

ValueError: Unable to load weights saved in HDF5 format into a subclassed Model which has not created its variables yet. Call the Model first, then load the weights.

Please give me any advice.
Thank you.

@Lana2548 Lana2548 changed the title Error: 03_04_vae_digits_analysis.ipynb ValueError: Unable to load weights on 03_04_vae_digits_analysis.ipynb Feb 23, 2021
@Lana2548 Lana2548 changed the title ValueError: Unable to load weights on 03_04_vae_digits_analysis.ipynb ValueError: Unable to load weights 03_04_vae_digits_analysis.ipynb Feb 23, 2021
@eiler-partner
Copy link

Hi,
I am using the code from tensorflow_2 directory
I have the same problem:


ValueError Traceback (most recent call last)
in
----> 1 vae = load_model(VariationalAutoencoder, RUN_FOLDER)

~\Deep_Learning\H_Generative_Deep_Learning\utils\loaders.py in load_model(model_class, run_folder)
138 model = model_class(*params)
139
--> 140 model.load_weights(os.path.join(run_folder, 'weights/weights.h5'))
141
142 return model

~\Deep_Learning\H_Generative_Deep_Learning\models\VAE.py in load_weights(self, filepath)
204
205 def load_weights(self, filepath):
--> 206 self.model.load_weights(filepath)
207
208 def train(self, x_train, batch_size, epochs, run_folder, print_every_n_batches = 100, initial_epoch = 0, lr_decay = 1):

~\anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py in load_weights(self, filepath, by_name, skip_mismatch, options)
2266 'load_weights requires h5py when loading weights from HDF5.')
2267 if not self._is_graph_network and not self.built:
-> 2268 raise ValueError(
2269 'Unable to load weights saved in HDF5 format into a subclassed '
2270 'Model which has not created its variables yet. Call the Model '

ValueError: Unable to load weights saved in HDF5 format into a subclassed Model which has not created its variables yet. Call the Model first, then load the weights.

Any ideas for a fix?

Best regards,
Patrick

@cia-rana
Copy link

  • branch: tensorflow_2
  • platform: Google Colab

I encountered the same problem, and I solved it by setting self.built = True after initializing VAEModel.

class VAEModel(Model):
    def __init__(self, encoder, decoder, r_loss_factor, **kwargs):
        super(VAEModel, self).__init__(**kwargs)
        self.encoder = encoder
        self.decoder = decoder
        self.r_loss_factor = r_loss_factor
        self.built = True # added

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants