I am trying to extract the layers from a sequential model to build an autoencoder. I trained the model on some data but when I try to get model.input from my model I get an error saying that it has never been called.
I set up and train the model here.
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Input
from tensorflow.keras.optimizers import Adam
model = Sequential()
model.add(Input(shape=(X_train_scaled.shape[1],))) # Input layer
model.add(Dense(128, activation='relu')) # First hidden layer
model.add(Dense(64, activation='relu')) # Second hidden layer
model.add(Dense(1)) # Output layer
optimiser = Adam(learning_rate = 0.001)
model.compile(optimizer = optimiser, loss='mse')
history = model.fit(X_train_scaled, y_train, validation_data=(X_test_scaled, y_test), epochs=100, batch_size=16)
And the following line causes the error.
from tensorflow.keras.models import Model
encoder = Model(inputs=model.input, outputs=model.layers[-2].output) # -2 to exclude the last layer
I am very new to this, so any advice or direction would be appreciated.