TypeError(‘Keyword argument not understood:’, ‘***’) in keras.models load_ model
1.Problem description
-
- after training on Google colab, model.save (filepath)_ Save) and then use after saving
from keras.models import load_model
model = load_model(model_file)
# Error: TypeError: ('Keyword argument not understood:', 'step_dim')
2.Solutions
-
-
- method 1: confirm whether the versions of keras and TF are different twice. Someone’s solution: I only solved it by upgrading tensorflow and keras on the local computer at the same time
-
pip install --upgrade tensorflow
pip install --upgrade keras
What he means is the version problem. After training on Google’s colab, the model is saved locally. When it is called locally, the loading model will report an error due to the different versions of the packages in the two environments
then you can adjust the version of the local related package.
Similar to the following answer, the version when the model is saved is inconsistent with the version when the model is loaded, which may cause this problem
then unify the versions
import tensorflow as tf
import keras
print(keras.__version__)
print(tf.__version__)
But mine is still read on the colab, and the environment is the same, so this method can’t solve my specific problem.
-
-
- method 2. Model.load_ Weights() only reads weights
-
-
-
- the general idea is that we start with models.load_ Model () reads the network and weight. Now, because of the keyword argument not understood in the custom model, we first build the model structure, and then model. Load_ Weights () reads weights, which can achieve our original purpose
-
-
-
- at present, I use this method to solve the problem of re reading and importing the parameters of the network structure model of the user-defined model
-
I also have this problem I’ve tried a lot of methods and found that this method can be used
# first,build model
model = TextAttBiRNN(maxlen, max_features, embedding_dims).get_model()
model.compile(loss='binary_crossentropy',
optimizer='adam',
metrics=['accuracy'])
# second, load weights: I solved the problem with this:
model_file = "/content/drive/My Drive/dga/output_data/model_lstm_att_test_v6.h5"
model.load_weights(model_file)
# then,we will find the modle can be use.
# in this way,I avoided the previous questions.
Read More:
- TypeError: drop() got an unexpected keyword argument ‘columns’
- Python TypeError: ‘newline’ is an invalid keyword argument for this function
- Keras saves save() and save in the model_ weights()
- OSError: SavedModel file does not exist at: ./model/facenet_keras.h5
- python got an unexpected keyword argument
- Keras Model AttributeError:’str‘ object has no attribute ’call‘
- After the model is instantiated by keras, the result returns nonetype
- Typeerror: write() argument must be STR, not bytes and the method of writing binary file in Python 3
- Typeerror: write() argument must be STR, not bytes and the method of writing binary file in Python 3
- TypeError: Required argument ‘mat‘ (pos 2) not found
- Error importing keras in jupyter Notebook: modulenotfounderror: no module named ‘keras’ solution
- Python about typeerror: required argument ‘mat’ (POS 2) not found error resolution
- AttributeError: Can‘t get attribute ‘SPPF‘ on <module ‘models.common‘ from ‘H:\\yolov5-5.0\\models\\
- Solution to unbalanced load of multiple cards (GPU’s 0 card is too high) in Python model training (simple and effective)
- TypeError: __array__() takes 1 positional argument but 2 were given
- Module build failed: TypeError [ERR_INVALID_ARG_TYPE]: The “path“ argument must be of type string.
- Error in tensorflow loading model valueerror: unknown layer: functional
- TypeError: translate() takes exactly one argument (2 given)
- Using onnx to deploy models in mmdetection
- Pytorch TypeError: __array__() takes 1 positional argument but 2 were given