how to use chainer.using_config to stop F.dropout in evaluate/predict process in chainer? -
f.dropout used in train, confused how use chainer.using_config in it? how works , chainer how know in training or predict?
from chainer v2, function behavior controlled config
variable, according official doc,
chainer.config.train
training mode flag. if true, chainer runs in training mode. otherwise, runs in testing (evaluation) mode. default value true.
you may control config
following 2 ways.
1. assign value.
chainer.config.train = false here, code runs in test mode, , dropout won't drop unit. model(x) chainer.config.train = true
2. with using_config(key, value)
notation
if use above case, might need set true
, false
often, chainer provides with using_config(key, value)
notation ease setting.
with chainer.using_config('train', false): # train config set false, code runs in test mode. model(x) # here, train config recovered original value. ...
note1: if using trainer
moudule, evaluator
handle these configuration automatically during validation/evaluation (see document, or source code). means train
config set false
, dropout runs evaluate mode when calculating validation loss.
note2: train
config used switch "train" mode , "evaluate/validation". if need "predict" code, need implement separately.
Comments
Post a Comment