Skip to content

Commit

Permalink
Split tests for seizure_detect.py
Browse files Browse the repository at this point in the history
  • Loading branch information
xmival00 committed Oct 12, 2023
1 parent 4ca3057 commit c896398
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 33 deletions.
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ Cite
"""""""""""""""""""""""""""
When use whole, parts, or are inspired by, we appreciate you acknowledge and refer these journal papers:




| Mivalt F, Kremen V, Sladky V, Balzekas I, Nejedly P, Gregg N, Lundstrom BN, Lepkova K, Pridalova T, Brinkmann BH, et al. Electrical brain stimulation and continuous behavioral state tracking in ambulatory humans. J Neural Eng (2022) Available at: http://iopscience.iop.org/article/10.1088/1741-2552/ac4bfd

Expand Down
1 change: 0 additions & 1 deletion best/seizure_detection/seizure_detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ def preprocess_input(x, fs):
else:
raise ValueError("too many NaN values in input")


def infer_seizure_probability(x, model, use_cuda=False, cuda_number=0):
"""
infers seizure probability for a given input x; recommended signal len is 300 seconds.
Expand Down
32 changes: 0 additions & 32 deletions best/test/test_best_deep_learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,11 @@
import unittest
from unittest import TestCase

import torch.cuda

from best.seizure_detection.seizure_detect import load_trained_model, preprocess_input, infer_seizure_probability
from numpy.random import rand
from best.deep_learning.models_generic import *


class Test_deep_learning(TestCase):
def test_import(self):
print("Testing import 'from best.deep_learning'" )


class Test_seizure_detect(TestCase):
def test_load_trained_model(self):
modelA = load_trained_model('modelA')
modelB = load_trained_model('modelB')

def test_preprocess_input(self):
modelA = load_trained_model('modelA')
fs = 500
x_len = 300
channels = 1
x_input = rand(channels, fs * x_len)
x = preprocess_input(x_input, fs)
y = infer_seizure_probability(x, modelA)
self.assertEqual(599, y.shape[1])
channels = 3
x_input = rand(channels, fs * x_len)
x = preprocess_input(x_input, fs)
y = infer_seizure_probability(x, modelA)
self.assertEqual(599, y.shape[1])
if torch.cuda.is_available():
modelA.cuda(0)
y = infer_seizure_probability(x, modelA, True, 0)
self.assertEquals(599, y.shape[1])



if __name__ == '__main__':
unittest.main()
46 changes: 46 additions & 0 deletions best/test/test_best_seizure_detection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright 2020-present, Mayo Clinic Department of Neurology
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.


import unittest
from unittest import TestCase

import torch.cuda

from best.seizure_detection.seizure_detect import load_trained_model, preprocess_input, infer_seizure_probability
from numpy.random import rand
from best.deep_learning.models_generic import *



class Test_seizure_detect(TestCase):
def test_load_trained_model(self):
modelA = load_trained_model('modelA')
modelB = load_trained_model('modelB')

def test_preprocess_input(self):
modelA = load_trained_model('modelA')
fs = 500
x_len = 300
channels = 1
x_input = rand(channels, fs * x_len)
x = preprocess_input(x_input, fs)
y = infer_seizure_probability(x, modelA)
self.assertEqual(599, y.shape[1])
channels = 3
x_input = rand(channels, fs * x_len)
x = preprocess_input(x_input, fs)
y = infer_seizure_probability(x, modelA)
self.assertEqual(599, y.shape[1])
if torch.cuda.is_available():
modelA.cuda(0)
y = infer_seizure_probability(x, modelA, True, 0)
self.assertEquals(599, y.shape[1])



if __name__ == '__main__':
unittest.main()

0 comments on commit c896398

Please sign in to comment.