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

Error saving Keras optimizer, TensorFlow 2.0 #33100

Closed
OverLordGoldDragon opened this issue Oct 7, 2019 · 3 comments
Closed

Error saving Keras optimizer, TensorFlow 2.0 #33100

OverLordGoldDragon opened this issue Oct 7, 2019 · 3 comments
Assignees
Labels
comp:core issues related to core part of tensorflow TF 2.0 Issues relating to TensorFlow 2.0 type:support Support issues

Comments

@OverLordGoldDragon
Copy link
Contributor

Related, minimal reproducible example below. Opened a PR, but doesn't fix this problem.


DOESN'T WORK:

from tensorflow.python.keras.layers import Input, Dense
from tensorflow.python.keras.models import Model
from tensorflow.python.keras.optimizers import Nadam # [3]

import numpy as np
ipt = Input(shape=(4,))
out = Dense(1, activation='sigmoid')(ipt)

model = Model(ipt, out)
model.compile(optimizer=Nadam(lr=1e-4), loss='binary_crossentropy')

X = np.random.randn(32,4)
Y = np.random.randint(0,2,(32,1))
model.train_on_batch(X,Y)

modelpath = "folder/model.h5"
model.save(modelpath)

WORKS: remove .python from above's imports, OR, model.save(.., include_optimizer=False). Also works if .python is removed only from import # [3].


Full error trace:

  File "<ipython-input-1-fedd4f332165>", line 23, in <module>
    model.save(modelpath)

  File "D:\Anaconda\envs\tf2_env\lib\site-packages\tensorflow_core\python\keras\engine\network.py", line 975, in save
    signatures, options)

  File "D:\Anaconda\envs\tf2_env\lib\site-packages\tensorflow_core\python\keras\saving\save.py", line 112, in save_model
    model, filepath, overwrite, include_optimizer)

  File "D:\Anaconda\envs\tf2_env\lib\site-packages\tensorflow_core\python\keras\saving\hdf5_format.py", line 115, in save_model_to_hdf5
    save_optimizer_weights_to_hdf5_group(f, model.optimizer)

  File "D:\Anaconda\envs\tf2_env\lib\site-packages\tensorflow_core\python\keras\saving\hdf5_format.py", line 587, in save_optimizer_weights_to_hdf5_group
    name, val.shape, dtype=val.dtype)

  File "D:\Anaconda\envs\tf2_env\lib\site-packages\h5py\_hl\group.py", line 139, in create_dataset
    self[name] = dset

  File "D:\Anaconda\envs\tf2_env\lib\site-packages\h5py\_hl\group.py", line 371, in __setitem__
    h5o.link(obj.id, self.id, name, lcpl=lcpl, lapl=self._lapl)

  File "h5py\_objects.pyx", line 54, in h5py._objects.with_phil.wrapper

  File "h5py\_objects.pyx", line 55, in h5py._objects.with_phil.wrapper

  File "h5py\h5o.pyx", line 202, in h5py.h5o.link

RuntimeError: Unable to create link (name already exists)
@OverLordGoldDragon OverLordGoldDragon changed the title Error saving optimizer, TensorFlow 2.0 Error saving Keras optimizer, TensorFlow 2.0 Oct 7, 2019
@rmothukuru rmothukuru self-assigned this Oct 7, 2019
@rmothukuru
Copy link
Contributor

@OverLordGoldDragon,
When I tried reproducing your error, I got a different error, as shown below.

ValueError: Tried to convert 'y' to a tensor and failed. Error: None values not supported.

Please find the Gist.

Can you please help me to reproduce the issue. Thanks!

@rmothukuru rmothukuru added stat:awaiting response Status - Awaiting response from author TF 2.0 Issues relating to TensorFlow 2.0 labels Oct 7, 2019
@OverLordGoldDragon
Copy link
Contributor Author

@rmothukuru Right, that's another problem for which I started a Pull Request - you can implement the fix manually in the meantime.

@tensorflowbutler tensorflowbutler removed the stat:awaiting response Status - Awaiting response from author label Oct 8, 2019
@OverLordGoldDragon
Copy link
Contributor Author

OverLordGoldDragon commented Oct 9, 2019

Solved. TL;DR - .python isn't meant to be used for this purpose.

@rmothukuru rmothukuru added comp:core issues related to core part of tensorflow type:support Support issues labels Oct 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:core issues related to core part of tensorflow TF 2.0 Issues relating to TensorFlow 2.0 type:support Support issues
Projects
None yet
Development

No branches or pull requests

3 participants