mirror of
https://github.com/wassname/DeepRL.git
synced 2026-09-09 11:13:47 +08:00
Minor update for DQN
This commit is contained in:
@@ -13,8 +13,6 @@ import numpy as np
|
||||
# Base class for all kinds of network
|
||||
class BasicNet:
|
||||
def __init__(self, optimizer_fn, gpu, LSTM=False):
|
||||
if optimizer_fn is not None:
|
||||
self.optimizer = optimizer_fn(self.parameters())
|
||||
self.gpu = gpu and torch.cuda.is_available()
|
||||
self.LSTM = LSTM
|
||||
if self.gpu:
|
||||
|
||||
@@ -15,8 +15,7 @@ class NatureConvNet(nn.Module, VanillaNet):
|
||||
self.conv3 = nn.Conv2d(64, 64, kernel_size=3, stride=1)
|
||||
self.fc4 = nn.Linear(7 * 7 * 64, 512)
|
||||
self.fc5 = nn.Linear(512, n_actions)
|
||||
self.criterion = nn.MSELoss()
|
||||
BasicNet.__init__(self, optimizer_fn, gpu)
|
||||
BasicNet.__init__(self, None, gpu)
|
||||
|
||||
def forward(self, x):
|
||||
x = self.to_torch_variable(x)
|
||||
@@ -37,8 +36,7 @@ class DuelingNatureConvNet(nn.Module, DuelingNet):
|
||||
self.fc4 = nn.Linear(7 * 7 * 64, 512)
|
||||
self.fc_advantage = nn.Linear(512, n_actions)
|
||||
self.fc_value = nn.Linear(512, 1)
|
||||
self.criterion = nn.MSELoss()
|
||||
BasicNet.__init__(self, optimizer_fn, gpu)
|
||||
BasicNet.__init__(self, None, gpu)
|
||||
|
||||
def forward(self, x):
|
||||
x = self.to_torch_variable(x)
|
||||
|
||||
@@ -13,7 +13,6 @@ class FCNet(nn.Module, VanillaNet):
|
||||
self.fc1 = nn.Linear(dims[0], dims[1])
|
||||
self.fc2 = nn.Linear(dims[1], dims[2])
|
||||
self.fc3 = nn.Linear(dims[2], dims[3])
|
||||
self.criterion = nn.MSELoss()
|
||||
BasicNet.__init__(self, optimizer_fn, gpu)
|
||||
|
||||
def forward(self, x):
|
||||
@@ -32,7 +31,6 @@ class DuelingFCNet(nn.Module, DuelingNet):
|
||||
self.fc2 = nn.Linear(dims[1], dims[2])
|
||||
self.fc_value = nn.Linear(dims[2], 1)
|
||||
self.fc_advantage = nn.Linear(dims[2], dims[3])
|
||||
self.criterion = nn.MSELoss()
|
||||
BasicNet.__init__(self, optimizer_fn, gpu)
|
||||
|
||||
def forward(self, x):
|
||||
@@ -67,7 +65,6 @@ class FruitHRFCNet(nn.Module, VanillaNet):
|
||||
hidden_size = 250
|
||||
self.fc1 = nn.Linear(state_dim, hidden_size)
|
||||
self.fc2 = nn.ModuleList([nn.Linear(hidden_size, action_dim) for _ in head_weights])
|
||||
self.criterion = nn.MSELoss()
|
||||
self.head_weights = head_weights
|
||||
BasicNet.__init__(self, optimizer_fn, gpu)
|
||||
|
||||
@@ -93,7 +90,6 @@ class FruitMultiStatesFCNet(nn.Module, BasicNet):
|
||||
hidden_size = 250
|
||||
self.fc1 = nn.ModuleList([nn.Linear(state_dim, hidden_size) for _ in head_weights])
|
||||
self.fc2 = nn.ModuleList([nn.Linear(hidden_size, action_dim) for _ in head_weights])
|
||||
self.criterion = nn.MSELoss()
|
||||
self.head_weights = head_weights
|
||||
self.state_dim = state_dim
|
||||
self.n_heads = head_weights.shape[0]
|
||||
|
||||
Reference in New Issue
Block a user