-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.py
executable file
·34 lines (28 loc) · 1016 Bytes
/
model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import torch
import torch.nn as nn
import torch.nn.functional as F
from game_settings import DROPOUT_RATE
class Linear_QNet(nn.Module):
def __init__(self, input_layer, hidden1, hidden2, output_layer):
super().__init__()
self.linear1 = nn.Linear(input_layer, hidden1)
self.bn1 = nn.BatchNorm1d(hidden1)
self.dropout1 = nn.Dropout(DROPOUT_RATE)
self.linear2 = nn.Linear(hidden1, hidden2)
self.bn2 = nn.BatchNorm1d(hidden2)
self.dropout2 = nn.Dropout(DROPOUT_RATE)
self.linear3 = nn.Linear(hidden2, output_layer)
if torch.cuda.is_available():
self.cuda()
def forward(self, x):
x = F.relu(self.linear1(x))
x = self.dropout1(x)
x = F.relu(self.linear2(x))
x = self.dropout2(x)
x = self.linear3(x)
return x
def save(self, epoch=0, filename=None):
torch.save({
'model_state_dict': self.state_dict(),
'epoch': epoch,
}, filename)