Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -18,32 +18,37 @@ class PhiModel(nn.Module):
|
|
18 |
# NN branch
|
19 |
self.fc1 = nn.Linear(input_size, 64)
|
20 |
self.fc2 = nn.Linear(64, 32)
|
|
|
21 |
|
22 |
# RNN branch
|
23 |
self.lstm = nn.LSTM(input_size, 64, batch_first=True)
|
|
|
24 |
|
25 |
# CNN branch
|
26 |
self.conv1 = nn.Conv1d(1, 32, kernel_size=3, padding=1)
|
27 |
-
self.fc3 = nn.Linear(32 * input_size,
|
28 |
|
29 |
def forward(self, nn_input, rnn_input, cnn_input):
|
30 |
# NN branch
|
31 |
nn_out = F.relu(self.fc1(nn_input))
|
32 |
nn_out = F.relu(self.fc2(nn_out))
|
|
|
33 |
|
34 |
# RNN branch
|
35 |
rnn_out, _ = self.lstm(rnn_input)
|
36 |
-
rnn_out = rnn_out[:, -1, :] #
|
|
|
37 |
|
38 |
# CNN branch
|
39 |
cnn_input = cnn_input.unsqueeze(1) # Add channel dimension
|
40 |
cnn_out = F.relu(self.conv1(cnn_input))
|
41 |
cnn_out = cnn_out.view(cnn_out.size(0), -1) # Flatten the output
|
|
|
42 |
|
43 |
# Combine all branches
|
44 |
combined = nn_out + rnn_out + cnn_out
|
45 |
-
output = torch.sigmoid(
|
46 |
-
|
47 |
return output
|
48 |
|
49 |
# Initialize the model
|
|
|
18 |
# NN branch
|
19 |
self.fc1 = nn.Linear(input_size, 64)
|
20 |
self.fc2 = nn.Linear(64, 32)
|
21 |
+
self.fc_out = nn.Linear(32, 64) # To make the NN output size match other branches
|
22 |
|
23 |
# RNN branch
|
24 |
self.lstm = nn.LSTM(input_size, 64, batch_first=True)
|
25 |
+
self.rnn_fc = nn.Linear(64, 64) # Adjust RNN output size
|
26 |
|
27 |
# CNN branch
|
28 |
self.conv1 = nn.Conv1d(1, 32, kernel_size=3, padding=1)
|
29 |
+
self.fc3 = nn.Linear(32 * input_size, 64) # Adjust CNN output size
|
30 |
|
31 |
def forward(self, nn_input, rnn_input, cnn_input):
|
32 |
# NN branch
|
33 |
nn_out = F.relu(self.fc1(nn_input))
|
34 |
nn_out = F.relu(self.fc2(nn_out))
|
35 |
+
nn_out = self.fc_out(nn_out) # Ensure the output size matches others
|
36 |
|
37 |
# RNN branch
|
38 |
rnn_out, _ = self.lstm(rnn_input)
|
39 |
+
rnn_out = rnn_out[:, -1, :] # Take last output of LSTM
|
40 |
+
rnn_out = self.rnn_fc(rnn_out) # Adjust RNN output size to match NN's output size
|
41 |
|
42 |
# CNN branch
|
43 |
cnn_input = cnn_input.unsqueeze(1) # Add channel dimension
|
44 |
cnn_out = F.relu(self.conv1(cnn_input))
|
45 |
cnn_out = cnn_out.view(cnn_out.size(0), -1) # Flatten the output
|
46 |
+
cnn_out = self.fc3(cnn_out) # Adjust CNN output size to match NN and RNN
|
47 |
|
48 |
# Combine all branches
|
49 |
combined = nn_out + rnn_out + cnn_out
|
50 |
+
output = torch.sigmoid(combined)
|
51 |
+
|
52 |
return output
|
53 |
|
54 |
# Initialize the model
|