I’ve been trying to implement multiple DQN models together. So I first defined my network like this,
class atari_model(nn.Module):
def __init__(self, in_channels=12, num_actions=18):
super(atari_model, self).__init__()
self.conv1 = nn.Conv2d(in_channels, 32, kernel_size=8, stride=4)
self.conv2 = nn.Conv2d(32, 64, kernel_size=4, stride=2)
self.conv3 = nn.Conv2d(64, 64, kernel_size=3, stride=1)
self.fc4 = nn.Linear(7 * 7 * 64, 512)
self.fc5 = nn.Linear(512, num_actions)
def forward(self, x):
x = F.relu(self.conv1(x))
x = F.relu(self.conv2(x))
x = F.relu(self.conv3(x))
x = F.relu(self.fc4(x.view(x.size(0), -1)))
return self.fc5(x)
then, I constructed a list of models,
models = []
for i in range(8):
model = atari_model(12, 18)
model.cuda()
models.append(model)
optimizer = optim.Adam(model.parameters(), lr=0.001)
then I collected some experiences in the environment and try to perform some updates using these models, and their target models. However, this does not work even if I just have one model, but instead the model is in a list. Does put the model in a list and then use it really cause any problems? If this causes problems, how to create any number of models by specifying the number elsewhere?