Traceback (most recent call last):
File "/Users/fallonrowerdink/Desktop/TUMPREP_Code/Federated_2Clients/Retrain_2Clients.py", line 178, in <module>
Train_Model = RetrainModel(x0, y0, x1, y1)
File "/Users/fallonrowerdink/Desktop/TUMPREP_Code/Federated_2Clients/Retrain_2Clients.py", line 158, in RetrainModel
model.save(model_savepath, overwrite = True)
File "/opt/anaconda3/envs/TUMprep_Original/lib/python3.10/site-packages/keras/src/utils/traceback_utils.py", line 70, in error_handler
raise e.with_traceback(filtered_tb) from None
File "/opt/anaconda3/envs/TUMprep_Original/lib/python3.10/site-packages/h5py/_hl/group.py", line 183, in create_dataset
dsid = dataset.make_new_dset(group, shape, dtype, data, name, **kwds)
File "/opt/anaconda3/envs/TUMprep_Original/lib/python3.10/site-packages/h5py/_hl/dataset.py", line 163, in make_new_dset
dset_id = h5d.create(parent.id, name, tid, sid, dcpl=dcpl, dapl=dapl)
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/h5d.pyx", line 137, in h5py.h5d.create
ValueError: Unable to create dataset (name already exists)
Here is the function that is the problem:
# Define model
def RetrainModel(InputModel, OutputModel, ValInputModel, ValOutputModel):
kb.clear_session()
# Load the model
model = tf.keras.models.load_model('./Federated_2Clients/2Client_Data/weighted_2clients_round2.h5', compile = False)
# # Rename layers
# for i, layer in enumerate(model.layers):
# layer._name = f"{layer.name}_{i}"
# # Rename weights
# for i, weight in enumerate(model.weights):
# weight._name = f"{weight.name}_{i}"
model.compile(optimizer = 'adam', loss = [CustomLoss.MaskedMSE], metrics = [CustomLoss.MaskedMSE])
# Train model with 1 Input feature
model.fit(InputModel, OutputModel, batch_size = cIntBatchSize, epochs = 3, verbose = 2, validation_data = (ValInputModel, ValOutputModel), shuffle = True)
# Save model
if dataset == 1:
model_savepath = ("./Federated_2Clients/2Client_Data/FTMRetrained_round3.h5")
elif dataset == 2:
model_savepath = ("./Federated_2Clients/2Client_Data/StanfordRetrained_round3.h5")
else:
raise ValueError("Incorrect dataset selected.")
# Delete the file if it already exists
if os.path.exists(model_savepath):
os.remove(model_savepath)
# Save the model
model.save(model_savepath, overwrite = True)
I’ve been working on a federated learning pipeline and I’m encountering this error when retraining my model. I’ve tried renaming the file, changing the path, renaming the layers, and a bunch of other things but this error won’t go away. Please help!