link: https://www.zhihu.com/question/67209417/answer/302434279
Just stepped on the pit, almost cried out TT. — I clearly added a hundred dropout, why the results have not changed
When using F.dropout (nn. Functional. Dropout), it is necessary to set the state parameter of training consistent with the model as a whole.
Such as:
Class DropoutFC(nn.Module):
def: (self):
super(DropoutFC, self). input):
out = self.fc(input)
out = F.dropout(out, P =0.5)
return out
Net = DropoutFC()
Net. Train ()
# train the Net
The f.d.ropout in this code is actually useless because its training state is always the default False. Since F.ropout is only equivalent to an external function referenced, changes in the training status of the whole model will not cause changes in the training status of the function f.ropout. So, here out = F.d ropout (out) is out = out. Ref: https://github.com/pytorch/pytorch/blob/master/torch/nn/functional.py#L535
The correct way to use it is to pass the training status parameters of the model into the Dropout function
Class DropoutFC(nn.Module):
def: (self):
super(DropoutFC, self). Input):
out = self.fc(input)
out = f.darpout (out, p=0.5, Training =self. Training)
return out
Net = DropoutFC()
Net. Train ()
# train the Net
Or directly using nn. Dropout () (nn) Dropout () is actually the F.d ropout a packing, will also self. Training incoming) Ref: https://github.com/pytorch/pytorch/blob/master/torch/nn/modules/dropout.py#L46
Class DropoutFC(nn. Module):
def __init__:
super(DropoutFC, self).__init__()
self.fc = nn. Linear(100.20)
self.dropout = nn. Dropout(p=0.5)
def forward(self, input):
out = self.fc(input)
out = self.dropout(out)
return out
Net = DropoutFC()
Net.train()
Read More:
- Yield usage in Python
- The usage of typing.union in Python
- In Python sys.argv Usage of
- The usage details of SVM
- Principle and usage of feof ()
- Can’t find Python executable “D:\python3\python.exe”, you can set the PYTHON env variable.
- The difference and usage of insmod and modprobe
- The usage of Matlab function downsample
- np.unique Usage of ()
- Usage of NVL in SQL
- Visio2007 usage record
- OpenGL Usage Summary (including problems encountered and solutions)
- Java and Android commons codec usage and nosuch method error
- tf.contrib.layers .xavier_ Initializer function usage
- The usage of Java JUnit unit test and the solution of initialization error
- Raise in Oracle_APPLICATION_Error Usage
- The function and usage of argc and argv in C language
- Mxnet general optimizer usage
- Opencv, CV2. Puttext() usage
- Anaconda + vscode usage problem summary