0

Error Response is this,

"message": "Error when deserializing class 'SpatialDropout1D' using config={'name': 'spatial_dropout1d', 'trainable': True, 'dtype': 'float32', 'rate': 0.4, 'noise_shape': None, 'seed': None}.\n\nException encountered: SpatialDropout1D.init() got an unexpected keyword argument 'trainable'"

using keras==3.3.3 tensorflow=2.16.1

from tensorflow.keras.models import load_model

model2 = load_model_from_s3(settings.BUCKET_NAME_TEST, settings.MODEL_KEY_TEST, load_model)
def load_model_from_s3(bucket_name, model_key, load_model):
    """Load model from S3"""               
    client = boto3.client('s3')
    with tempfile.TemporaryDirectory() as tmpdir:
        model_path = os.path.join(tmpdir, 'model.h5')  # Create a file path
        client.download_file(bucket_name, model_key, model_path)  # Download to that file path
        model = load_model(model_path)  # Load the model from the file path
    print('Model loaded successfully')
    return model

should i change the version ?

2
  • Do you know if the S3 file download is working? Commented Jun 1, 2024 at 17:44
  • The error you're seeing suggests that there is a mismatch between the version of Keras used to save the model and the version you're using to load the model. Specifically, the SpatialDropout1D layer is receiving an unexpected trainable argument, which indicates that the Keras version used for saving the model does not match the one used for loading it.Install the versions of Keras and TensorFlow that are compatible with each other. For example, if the model was saved using Keras 2.11.0 and TensorFlow 2.10.0, you should install these versions.**pip install tensorflow==2.10.0 keras==2.11.0** Commented Aug 2, 2024 at 8:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.