I was training an autoencoder for anomaly detection and I wish to extract the bottleneck features of the encoder for K-NN. The model architecture is as such:
class Autoencoder(torch.nn.Module):
def __init__(self):
super().__init__()
self.encoder = torch.nn.Sequential(
torch.nn.Linear(curr_col_count, 300),
torch.nn.ReLU(),
torch.nn.Linear(300, 150),
torch.nn.ReLU(),
torch.nn.Linear(150, 75),
torch.nn.ReLU(),
torch.nn.Linear(75, 50),
# torch.nn.ReLU(),
# torch.nn.Linear(125, 50)
)
self.decoder = torch.nn.Sequential(
torch.nn.Linear(50, 75),
torch.nn.ReLU(),
torch.nn.Linear(75, 150),
torch.nn.ReLU(),
torch.nn.Linear(150, 300),
torch.nn.ReLU(),
# torch.nn.Linear(500, 1000),
# torch.nn.ReLU(),
torch.nn.Linear(300, curr_col_count),
torch.nn.Tanh()
)
def forward(self, x):
encoded = self.encoder(x)
decoded = self.decoder(encoded)
return decoded
and I am using the Pytorch feature extractor as such:
import torchvision as tv
import torchextractor as tx
model = Autoencoder()
model = tx.Extractor(
model,
["encoder.6"]
)
loss_function = torch.nn.MSELoss()
optimizer = torch.optim.Adam(model.parameters(), lr = 1e-4)
Before training the model, I retrieved the bottleneck features for each row of data and every row had different values. However, after training the model for just 1 epoch, I realized that every row had the same values for the bottleneck features. Why is this the case?