|
1 | | -# cardio |
| 1 | +# CardIO |
| 2 | + |
| 3 | +CardIO is a library that works with electrocardiograms (ECG). With CardIO you can |
| 4 | + |
| 5 | +* load and save signal in various formats |
| 6 | +* resample, crop, filter and flip signal |
| 7 | +* allocate PQ, QT, QRS segments |
| 8 | +* calculate heart rate and other standard ECG characteristics |
| 9 | +* apply complex transformations like fft and wavelets, or any other custom functions. |
| 10 | +* recognize heart diseases from ECG |
| 11 | +* efficiently work with large datasets that do not even fit into memory |
| 12 | +* easily arrange new custom actions into pipelines |
| 13 | +* do end-to-end ECG processing |
| 14 | +* build, train and test custom models for deep research |
| 15 | + |
| 16 | +… and do everything under a single API. |
| 17 | + |
| 18 | +For more details see [the documentation and tutorials](https://analysiscenter.github.io/cardio/). |
| 19 | + |
| 20 | +## About CardIO |
| 21 | + |
| 22 | +The library is based on [Dataset](https://github.com/analysiscenter/dataset/). We suggest to read Dataset's [documentation](https://analysiscenter.github.io/dataset/) to learn more. |
| 23 | + |
| 24 | +CardIO has three modules: [```batch```](https://analysiscenter.github.io/cardio/intro/batch.html) [```models```](https://analysiscenter.github.io/cardio/intro/models.html) and [```pipelines```](https://analysiscenter.github.io/cardio/intro/pipeline.html). |
| 25 | + |
| 26 | +Module ```batch``` contains low-level actions for ECG processing. |
| 27 | +Actions are included in ```EcgBatch``` class that also defines how |
| 28 | +to store ECGs. From these actions you can biuld new pipelines. You can also |
| 29 | +write custom action and include it in ```EcgBatch```. |
| 30 | + |
| 31 | +In ```models``` we provide several models that were elaborated to learn the most important problems in ECG: |
| 32 | +* how to recognize specific features of ECG like R-peaks, P-wave, T-wave |
| 33 | +* how to recognize heart diseases from ECG, for example - atrial fibrillation. |
| 34 | + |
| 35 | +Module ```pipelines``` contains high-level methods that |
| 36 | +* train model to allocate PQ, QT, QRS segments |
| 37 | +* calculate heart rate |
| 38 | +* train model to find probabilities of heart diseases. |
| 39 | + |
| 40 | +Under the hood these methods contain many actions that load signals, filter it and do complex caclulations. Using pipelines you do not think about this part of work and simply pass ECG datasets and get results. |
| 41 | + |
| 42 | +## Basic usage |
| 43 | + |
| 44 | +Here is an example of pipeline that loads ECG signals, makes some preprocessing and learns model over 50 epochs. |
| 45 | +```python |
| 46 | +train_ppl = ( |
| 47 | + dtst.train |
| 48 | + .pipeline |
| 49 | + .init_model("dynamic", DirichletModel, name="dirichlet", |
| 50 | + config=model_config) |
| 51 | + .init_variable("loss_history", init=list) |
| 52 | + .load(components=["signal", "meta"], fmt="wfdb") |
| 53 | + .load(components="target", fmt="csv", src=LABELS_PATH) |
| 54 | + .drop_labels(["~"]) |
| 55 | + .replace_labels({"N": "NO", "O": "NO"}) |
| 56 | + .flip_signals() |
| 57 | + .random_resample_signals("normal", loc=300, scale=10) |
| 58 | + .random_split_signals(2048, {"A": 9, "NO": 3}) |
| 59 | + .binarize_labels() |
| 60 | + .train_model("dirichlet", make_data=make_data, fetches="loss", save_to=V("loss_history"), mode="a") |
| 61 | + .run(batch_size=100, shuffle=True, drop_last=True, n_epochs=50) |
| 62 | +) |
| 63 | +``` |
| 64 | + |
| 65 | +As a result of this pipeline one obtains a trained model. |
| 66 | + |
| 67 | +## Installation |
| 68 | + |
| 69 | +> `CardIO` module is in the beta stage. Your suggestions and improvements are very welcome. |
| 70 | +
|
| 71 | +> `CardIO` supports python 3.5 or higher. |
| 72 | +
|
| 73 | +### Installation as python package |
| 74 | + |
| 75 | +With [pipenv](https://docs.pipenv.org/): |
| 76 | + |
| 77 | + pipenv install git+https://github.com/analysiscenter/cardio.git#egg=cardio |
| 78 | + |
| 79 | +With [pip](https://pip.pypa.io/en/stable/): |
| 80 | + |
| 81 | + pip3 install git+https://github.com/analysiscenter/cardio.git |
| 82 | + |
| 83 | +After that just import `cardio`: |
| 84 | +```python |
| 85 | +import cardio |
| 86 | +``` |
| 87 | + |
| 88 | +### Installation as a project repository: |
| 89 | + |
| 90 | + git clone --recursive https://github.com/analysiscenter/ecg.git |
| 91 | + |
| 92 | +Flag `--recursive` is used to clone submodules. |
| 93 | + |
| 94 | +## Citing CardIO |
| 95 | +Please cite CardIO in your publications if it helps your research. |
| 96 | + |
| 97 | + Khudorozhkov R., Illarionov E., Kuvaev A., Podvyaznikov D. CardIO library for data science research of heart signals. 2017. |
0 commit comments