Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: weight_decay is not a valid argument, kwargs should be empty for `optimizer_experimental.Optimizer`

I am getting the above error when running tensorflow.keras.models.load_model('')

I was working on tensorflow in the Spyder environment and I had no issues. Since I kept getting prompts (whenever launched Spyder) that the new version 5 of Spyder is available, I uninstalled the existing Spyder version and installed the latest version. In fact I uninstalled Anaconda itself and reinstalled it all over again (since the above problem persisted). However when running the same programs with included the code for loading an existing saved LSTM model, I got the below error.

prediction_model = tensorflow.keras.models.load_model('') The model is saved as a .h5 file.

the complete error string when running the load_model command is as follows:

File "C:\Users\ayapp\anaconda3\lib\site-packages\keras\utils\traceback_utils.py", line 67, in error_handler
    raise e.with_traceback(filtered_tb) from None

  File "C:\Users\ayapp\anaconda3\lib\site-packages\keras\optimizers\optimizer_experimental\optimizer.py", line 94, in _process_kwargs
    raise TypeError(f"{k} is not a valid argument, kwargs should be empty "

TypeError: weight_decay is not a valid argument, kwargs should be empty  for `optimizer_experimental.Optimizer`.

This issue was never faced when I was working in my earlier version of Spyder.

Can anybody suggest a solution?

like image 496
ayps Avatar asked Feb 18 '26 00:02

ayps


1 Answers

use model = tensorflow.keras.models.load_model(fileName, compile=False) then model.compile(whatever settings here) This worked for me

like image 120
Christian Velez Avatar answered Feb 19 '26 23:02

Christian Velez