HI I am new to pytorch.
I use dropout in training, so when I test the data, must I change
to model.eval()? I find I get different accuracy if I don’t add “eval()”
.
lass RNN(nn.Module):
def init(self,):
super(RNN, self).init()
self.lstm = nn.LSTM(input_size, hidden_size, num_layers, batch_first=False, dropout=0.5)
self.keke_drop = nn.Dropout(p=0.5)
self.fc = nn.Linear(hidden_size, num_classes)
Sure, Dropout works as a regularization for preventing overfitting during training.
It randomly zeros the elements of inputs in Dropout layer on forward call.
It should be disabled during testing since you may want to use full model (no element is masked)