I am trying to load a LSTM model from Keras on Colab and change its units but I am getting the following error: "AttributeError: Can't set the attribute "units", likely because it conflicts with an existing read-only @property of the object. Please choose a different name". I tried to modify other layers parameters and it worked fine. What can I do to fix it?
The code I am using to load the model and modify it:
model = keras.models.load_model('model.h5')
model.summary() #the model is composed by embedding, dropout, LSTM, dropout then dense layer
model.layers[2].units = 100
new_model = model_from_json(model.to_json())
The code I am using to generate the initial model:
def lstm(vocab_size, tokenizer, X_train, X_validation, y_train, y_validation):
model = Sequential()
model.add(Embedding(input_dim=vocab_size,
output_dim=embedding_dim,
input_length=length_size,
name='embedding'))
#droupout layer
model.add(Dropout(rate = first_dropout_rate))
#lstm layer
model.add(LSTM(units = units))
#dropout layer
model.add(Dropout(rate = last_dropout_rate))
#output layer
model.add(Dense(units=1, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
#model_random.summary()
history_random = model.fit(X_train,
y_train,
batch_size=batch_size,
epochs=epochs,
validation_data=(X_validation, y_validation))
return model