-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
60 lines (53 loc) · 1.67 KB
/
model.py
File metadata and controls
60 lines (53 loc) · 1.67 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import torch.nn as nn
import torch
from torch.types import Tensor
# very basic model used to comparison
class Model(nn.Module):
def __init__(self,input_size):
super(Model, self).__init__()
self.seq = nn.Sequential(
nn.Linear(input_size, 256),
nn.ReLU(),
nn.Linear(256, 512),
nn.ReLU(),
nn.Linear(512,512),
nn.ReLU(),
nn.Linear(512,512),
nn.ReLU(),
nn.Linear(512,512),
nn.ReLU(),
nn.Linear(512,512),
nn.ReLU(),
nn.Linear(512,512),
nn.ReLU(),
nn.Linear(512,512),
nn.ReLU(),
nn.Linear(512,288),
nn.Softplus()
)
def forward(self,x):
return self.seq(x)
class LstmModel(nn.Module):
def __init__(self):
super(LstmModel,self).__init__()
self.lstm_1 = nn.LSTM(input_size=78,num_layers=1,hidden_size=512, batch_first=True)
self.lstm_2 = nn.LSTM(input_size=560,num_layers=1,hidden_size=512, batch_first=True)
self.seq = nn.Sequential(
nn.Linear(512,256),
nn.ReLU(),
nn.Linear(256,128),
nn.ReLU(),
nn.Linear(128,64),
nn.ReLU(),
nn.Linear(64,12),
nn.ReLU()
)
return
def forward(self,weather_inputs:torch.Tensor,last_yield:torch.Tensor):
lstm_out,_ = self.lstm_1(weather_inputs)
concat = torch.cat((lstm_out,last_yield),dim=1)
lstm_out, _ = self.lstm_2(concat)
return self.seq(lstm_out)
def reset_lstm_state(self):
self.hidden =None
self.hidden_2 = None