From f9ea1a013c29e24001dc6cb7b10d9f740545fe58 Mon Sep 17 00:00:00 2001 From: Ramesh Sampath <1437573+sampathweb@users.noreply.github.com> Date: Fri, 1 Nov 2024 14:24:08 -0700 Subject: [PATCH] Use temporary folder for testing model saving in file editor (#20439) --- keras/src/saving/file_editor_test.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/keras/src/saving/file_editor_test.py b/keras/src/saving/file_editor_test.py index 0e2768aa6eb..41986b86681 100644 --- a/keras/src/saving/file_editor_test.py +++ b/keras/src/saving/file_editor_test.py @@ -98,14 +98,16 @@ def test_scalar_weight(self): model.add(keras.layers.Dense(1, activation="sigmoid", name="my_dense")) model.compile(optimizer="adam", loss="mse", metrics=["mae"]) model.fit(np.array([[1]]), np.array([[1]]), verbose=0) - model.save("model.keras") - model.save_weights("model.weights.h5") + model_fpath = os.path.join(self.get_temp_dir(), "model.keras") + weights_fpath = os.path.join(self.get_temp_dir(), "model.weights.h5") + model.save(model_fpath) + model.save_weights(weights_fpath) - model_editor = KerasFileEditor("model.keras") + model_editor = KerasFileEditor(model_fpath) self.assertEqual( len(keras.src.tree.flatten(model_editor.weights_dict)), 8 ) - model_weights_editor = KerasFileEditor("model.weights.h5") + model_weights_editor = KerasFileEditor(weights_fpath) self.assertEqual( len(keras.src.tree.flatten(model_weights_editor.weights_dict)), 8 )