The code calls model.train() twice within the inner training loop (once before the loop and once inside). The second call is redundant and unnecessary.
model.train()
for batch_idx, (features, targets) in enumerate(train_loader):
model.train() # redundant call
features = features.to(device)
targets = targets.to(device)
The code calls
model.train()twice within the inner training loop (once before the loop and once inside). The second call is redundant and unnecessary.