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
[Python]String startswith() Method
PyTorch를 사용하면서 특정 레이어를 지정할 때 'startswith' 함수를 사용하는 것을 자주 보았을것입니다. 위 함수는 문자열이 특정 문자(파라미터로 지정된)로 시작하는지 여부(True, False)를 리턴합니
greedy-min.tistory.com
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()