-
Notifications
You must be signed in to change notification settings - Fork 19.5k
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
Bug in keras.src.saving.saving_lib._save_model_to_dir
#20108
Comments
import tensorflow as tf
class SimpleModel(tf.keras.Model):
def __init__(self):
super(SimpleModel, self).__init__()
# Define layers here
self.dense1 = tf.keras.layers.Dense(10, activation='relu')
self.dense2 = tf.keras.layers.Dense(1) # Output layer with no activation (regression)
def call(self, inputs):
# Define forward pass
x = self.dense1(inputs)
return self.dense2(x)
# Instantiate the model
model = SimpleModel()
model.compile(
optimizer='adam',
loss='mean_squared_error',
metrics=['accuracy'] # For classification tasks, change to appropriate metrics
)
model.save('sample_model',overwrite=True,zipped=False) # this will work
model.save('sample_model',overwrite=True,zipped=False) # this will cause ERROR - as model is already saved. |
This issue has been fixed in the mainline (#19924, the commit just after the release of v3.4.1). |
there is a misspelling here:
but i shouldn't make a PR for that really, if anyone sees it, they can do it. ( im curious what'd be use-cases for saving unzipped |
@MegaCreater , This is working fine with the latest Keras 3.5.0 version, attaching the Gist here |
@sachinprasadhs thanks. It works fine after update. |
tf.keras.__version__
-> "3.4.1"If model is already saved then method call by
keras.src.models.model.Model.save
callkeras.src.saving.saving_lib._save_model_to_dir
, if model is already saved thenasset_store = DiskIOStore(assert_dirpath, mode="w")
(Line - 178) raiseFileExistsError
which error handling and finally clause line -asset_store.close()
(Line - 189) causes -UnboundLocalError: local variable 'asset_store' referenced before assignment
asasset_store
is not define.Solution to move
asset_store.close()
fromfinally
clause to try clause or check ifasset_store
is define then only callasset_store.close()
(Update from line 158 to line 189 i.e., https://github.com/keras-team/keras/blob/master/keras/src/saving/saving_lib.py#L158-L189)The text was updated successfully, but these errors were encountered: