pfnet / pfrl

PFRL: a PyTorch-based deep reinforcement learning library
MIT License
1.2k stars 157 forks source link

Question about agent.eval_mode() #153

Closed xylee95 closed 3 years ago

xylee95 commented 3 years ago

How do I switch back the agent to training mode after using with agent.eval_mode()?

I'm following the quick-start example and I want to evaluate my agent intermittently during training, rather than at the end of the training. What is the proper way of returning the agent to training setting after running a certain number of episodes of evaluation?

I'm writing my own custom training loop rather than using the pre-defined experiments function.

muupan commented 3 years ago

The agent will switch back to the original mode automatically once it leaves the with agent.eval_mode() context.

print("training", agent.training)
with agent.eval_mode():
    print("training", agent.training)
print("training", agent.training)

will print

training True
training False
training True
xylee95 commented 3 years ago

Great, thank you for clarifying!