-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from Rouast-Labs/running-vitals
Running vitals, JSON export, and lighter build
- Loading branch information
Showing
16 changed files
with
517 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Sample videos with ground truth labels | ||
|
||
In this folder, you can find two sample videos to test `vitallens` on. | ||
Each video has ground truth labels recorded with gold-standard medical equipment. | ||
|
||
- `sample_video_1.mp4` which has ground truth labels for PPG Waveform (`ppg`), ECG Waveform (`ecg`), Respiratory Waveform (`resp`), Blood Pressure (`sbp` and `dbp`), Blood Oxygen (`spo2`), Heart Rate (`hr_ecg` - derived from ECG and `hr_ppg` - derived from PPG), Heart Rate Variability (`hrv_sdnn_ecg`), and Respiratory Rate (`rr`). | ||
- `sample_video_2.mp4` which has ground truth labels for PPG Waveform (`ppg`). This sample is kindly provided by the [VitalVideos](http://vitalvideos.org) dataset. | ||
|
||
There is a test script in `test.py` which lets you run vitals estimation and plot the predictions against the ground truth labels. | ||
Some options are available: | ||
|
||
- `method`: Choose from [`VITALLENS`, `POS`, `G`, `CHROM`] (Default: `VITALLENS`) | ||
- `video_path`: Path to video (Default: `examples/sample_video_1.mp4`) | ||
- `vitals_path`: Path to gold-standard vitals (Default: `examples/sample_vitals_1.csv`) | ||
- `api_key`: Pass your API Key. Required if using `method=VITALLENS`. | ||
|
||
For example, to reproduce the results from the banner image on the [VitalLens API Webpage](https://www.rouast.com/api/): | ||
|
||
``` | ||
python examples/test.py --method=VITALLENS --video_path=examples/sample_video_2.mp4 --vitals_path=examples/sample_vitals_2.csv --api_key=YOUR_API_KEY | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Copyright (c) 2024 Philipp Rouast | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
|
||
import numpy as np | ||
import pytest | ||
|
||
import sys | ||
sys.path.append('../vitallens-python') | ||
|
||
from vitallens.signal import windowed_mean, windowed_freq, reassemble_from_windows | ||
|
||
def test_windowed_mean(): | ||
x = np.asarray([0., 1., 2., 3., 4., 5., 6.]) | ||
y = np.asarray([1., 1., 2., 3., 4., 5., 5.]) | ||
out_y = windowed_mean(x=x, window_size=3, overlap=1) | ||
np.testing.assert_equal( | ||
out_y, | ||
y) | ||
|
||
@pytest.mark.parametrize("num", [100, 1000]) | ||
@pytest.mark.parametrize("freq", [2.35, 4.89, 13.55]) | ||
@pytest.mark.parametrize("window_size", [10, 20]) | ||
def test_estimate_freq_periodogram(num, freq, window_size): | ||
# Test data | ||
x = np.linspace(0, freq * 2 * np.pi, num=num) | ||
np.random.seed(0) | ||
y = 100 * np.sin(x) + np.random.normal(scale=8, size=num) | ||
# Check a default use case with axis=-1 | ||
np.testing.assert_allclose( | ||
windowed_freq(x=y, window_size=window_size, overlap=window_size//2, f_s=len(x), f_range=(max(freq-2,1),freq+2), f_res=0.05), | ||
np.full((num,), fill_value=freq), | ||
rtol=1) | ||
|
||
def test_reassemble_from_windows(): | ||
x = np.array([[[2.0, 4.0, 6.0, 8.0, 10.0], [7.0, 1.0, 10.0, 12.0, 18.0]], | ||
[[2.0, 3.0, 4.0, 5.0, 6.0], [7.0, 8.0, 9.0, 10.0, 11.0]]], dtype=np.float32).transpose(1, 0, 2) | ||
idxs = np.array([[1, 3, 5, 7, 9], [5, 6, 9, 11, 13]], dtype=np.int64) | ||
out_x, out_idxs = reassemble_from_windows(x=x, idxs=idxs) | ||
np.testing.assert_equal( | ||
out_x, | ||
np.asarray([[2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 18.0], | ||
[2.0, 3.0, 4.0, 5.0, 6.0, 10.0, 11.0]])) | ||
np.testing.assert_equal( | ||
out_idxs, | ||
np.asarray([1, 3, 5, 7, 9, 11, 13])) | ||
|
Oops, something went wrong.