Spaces:
Sleeping
Sleeping
Upload model.py with huggingface_hub
Browse files
model.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import torch.nn as nn
|
| 3 |
+
|
| 4 |
+
class CardiovascularRNN(nn.Module):
|
| 5 |
+
def __init__(self, input_size, hidden_size, num_layers, num_classes):
|
| 6 |
+
super(CardiovascularRNN, self).__init__()
|
| 7 |
+
self.hidden_size = hidden_size
|
| 8 |
+
self.num_layers = num_layers
|
| 9 |
+
|
| 10 |
+
# RNN layer (using GRU for better performance over plain RNN)
|
| 11 |
+
self.gru = nn.GRU(input_size, hidden_size, num_layers, batch_first=True)
|
| 12 |
+
|
| 13 |
+
# Fully connected layer
|
| 14 |
+
self.fc = nn.Linear(hidden_size, num_classes)
|
| 15 |
+
|
| 16 |
+
def forward(self, x):
|
| 17 |
+
# Initialize hidden state
|
| 18 |
+
h0 = torch.zeros(self.num_layers, x.size(0), self.hidden_size).to(x.device)
|
| 19 |
+
|
| 20 |
+
# Forward propagate GRU
|
| 21 |
+
out, _ = self.gru(x, h0)
|
| 22 |
+
|
| 23 |
+
# Decode the hidden state of the last time step
|
| 24 |
+
out = out[:, -1, :]
|
| 25 |
+
|
| 26 |
+
# Output layer
|
| 27 |
+
out = self.fc(out)
|
| 28 |
+
return out
|