Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,19 +3,33 @@ import torch.nn as nn
|
|
| 3 |
import gradio as gr
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
-
# Define the Simple1DCNN model
|
| 7 |
class Simple1DCNN(nn.Module):
|
| 8 |
-
def __init__(self, input_channels
|
| 9 |
super(Simple1DCNN, self).__init__()
|
| 10 |
-
self.conv1 = nn.Conv1d(input_channels,
|
| 11 |
self.relu = nn.ReLU()
|
| 12 |
-
self.
|
| 13 |
-
self.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
def forward(self, x):
|
| 16 |
x = self.pool(self.relu(self.conv1(x)))
|
| 17 |
-
x =
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
# Load model
|
| 21 |
model_path = "ecg.pth" # Adjust if necessary
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
import numpy as np
|
| 5 |
|
|
|
|
| 6 |
class Simple1DCNN(nn.Module):
|
| 7 |
+
def __init__(self, input_channels, num_classes, sequence_length):
|
| 8 |
super(Simple1DCNN, self).__init__()
|
| 9 |
+
self.conv1 = nn.Conv1d(in_channels=input_channels, out_channels=64, kernel_size=3, padding=1)
|
| 10 |
self.relu = nn.ReLU()
|
| 11 |
+
self.conv2 = nn.Conv1d(in_channels=64, out_channels=128, kernel_size=3, padding=1)
|
| 12 |
+
self.pool = nn.MaxPool1d(kernel_size=2)
|
| 13 |
+
|
| 14 |
+
# Compute the output size after convolutions and pooling
|
| 15 |
+
self._to_linear = self._compute_flattened_size(input_channels, sequence_length)
|
| 16 |
+
|
| 17 |
+
self.fc1 = nn.Linear(self._to_linear, 256)
|
| 18 |
+
self.fc2 = nn.Linear(256, num_classes)
|
| 19 |
+
|
| 20 |
+
def _compute_flattened_size(self, input_channels, sequence_length):
|
| 21 |
+
x = torch.randn(1, input_channels, sequence_length) # Dummy tensor
|
| 22 |
+
x = self.pool(self.relu(self.conv1(x)))
|
| 23 |
+
x = self.pool(self.relu(self.conv2(x)))
|
| 24 |
+
return x.numel() # Total number of features after conv and pooling
|
| 25 |
|
| 26 |
def forward(self, x):
|
| 27 |
x = self.pool(self.relu(self.conv1(x)))
|
| 28 |
+
x = self.pool(self.relu(self.conv2(x)))
|
| 29 |
+
x = x.view(x.shape[0], -1) # Flatten
|
| 30 |
+
x = self.relu(self.fc1(x))
|
| 31 |
+
x = self.fc2(x)
|
| 32 |
+
return x
|
| 33 |
|
| 34 |
# Load model
|
| 35 |
model_path = "ecg.pth" # Adjust if necessary
|