我创建了以下具有如下辍学层的深度网络:
class QNet_dropout(nn.Module):
"""
A MLP with 2 hidden layer and dropout
observation_dim (int): number of observation features
action_dim (int): Dimension of each action
seed (int): Random seed
"""
def __init__(self, observation_dim, action_dim, seed):
super(QNet_dropout, self).__init__()
self.seed = torch.manual_seed(seed)
self.fc1 = nn.Linear(observation_dim, 128)
self.fc2 = nn.Dropout(0.5)
self.fc3 = nn.Linear(128, 64)
self.fc4 = nn.Dropout(0.5)
self.fc5 = nn.Linear(64, action_dim)
def forward(self, observations):
"""
Forward propagation of neural network
"""
x = F.relu(self.fc1(observations))
x = F.linear(self.fc2(x))
x = F.relu(self.fc3(x))
x = F.linear(self.fc4(x))
x = self.fc5(x)
return x
但是,当我试图运行代码时,我遇到了以下错误:
^{pr2}$好像我没有正确地使用/转发dropout层。什么是正确的方法来做的辍学层前进?谢谢!
F.linear()函数使用错误。你应该用你所说的线性函数代替torch.nn.功能. 辍学层应该在Relu之后。您可以从调用Relu函数torch.nn.功能. 在
相关问题 更多 >
编程相关推荐