-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.py
56 lines (31 loc) · 857 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
35
36
37
38
import torch
import torch.nn as nn
class FlappyBrain(nn.Module):
def __init__(self) -> None:
super().__init__()
"""
input params:
y position of bird
y distance to bottom pipe
y distance to top pipe
x distance to the pipe pair
y velocity of the bird
"""
self.seq1 = nn.Sequential(
nn.Linear(5, 3),
nn.ReLU(),
nn.Linear(3,1)
)
def forward(self, x):
return self.seq1(x)
def to_flap(self, out):
if out > 0.5:
return True
else:
return False
def randomize_initialization(self):
self.apply(init_weights)
def init_weights(m):
if isinstance(m, nn.Linear):
torch.nn.init.normal_(m.weight,0,1)
m.bias.data.fill_(0)