I will introduce how to activate the dropout layer during eval mode in PyTorch.
I am going to use the 'startswith' function in Python3.
If you want to know about the 'startswith' function, please refer to the previous article.
2020/12/24 - [Python] - [Python]String startswith() Method
Example
def activate_dropout(model):
""" Function to activate the dropout layers during eval mode """
for module in model.modules():
if module.__class__.__name__.startswith('Dropout'):
module.train()