Functional and Cell
Operator Functional Interface
nn Subnet Interface
Cell Training State Change
Some Tensor operations in neural networks do not behave the same during training and inference, e.g., nn.Dropout
performs random dropout during training but not during inference, and nn.BatchNorm
requires updating the mean
and var
variables during training and fixing their values unchanged during inference. So we can set the state of the neural network through the Cell.set_train
interface.
When set_train
is set to True, the neural network state is train
, and the default value of set_train
interface is True
:
net.set_train()
print(net.phase)
train
When set_train
is set to False, the neural network state is predict
:
net.set_train()
print(net.phase)
predict