Git Product home page Git Product logo

ecg-augmentations's Introduction

PyTorch ECG Augmentations

ECG time-series augmentations library for PyTorch. The focus of this repo is to:

  • Provide many transformations in an easy-to-use Python interface.
  • Easily control stochastic / sequential transformations.
  • Make every transformation differentiable through torch.nn.Module.
  • Optimize ECG transformations for CPU and GPU devices.

This repo supports stochastic transformations as used often in self-supervised and semi-supervised learning methods. One can apply a single stochastic augmentation or create as many stochastically transformed ECG examples from a single interface. This package follows the conventions set out by torchaudio-augmentations, with an ECG sample defined as a tensor of [lead, time], or a batched representation [batch, lead, time]. Each individual augmentation can be initialized on its own, or be wrapped around a RandomApply interface which will apply the augmentation with probability p.

Note: Current version runs on beta for multiple-lead ECG, we appreciate any contributions.

Installation

Just clone the repository and install the library:

git clone https://github.com/klean2050/ecg-augmentations
pip install -e ecg-augmentations

Usage

One can define a single or several augmentations, which are applied sequentially to an ECG sample:

from ecg_augmentations import *

# 1 lead, 100 samples
ecg = torch.load("tests/some_ecg.pt")

num_samples = ecg.shape[-1] // 2
transforms = [
    RandomCrop(n_samples=num_samples),
    RandomApply([PRMask()], p=0.4),
    RandomApply([QRSMask()], p=0.4),
    RandomApply([Scale()], p=0.5),
    RandomApply([Permute()], p=0.6),
    GaussianNoise(max_snr=0.005),
    RandomApply([Invert()], p=0.2),
    RandomApply([Reverse()], p=0.2),
]

One can also define a stochastic augmentation on multiple transformations:

transforms = [
    RandomCrop(n_samples=num_samples),
    RandomApply([PRMask(), QRSMask()], p=0.8),
    RandomApply([Invert(), Reverse()], p=0.5)
]

One can return either one ...

transform = Compose(transforms=transforms)
transformed_ecg =  transform(ecg)
>> transformed_ecg.shape = [num_leads, num_samples]

... or many versions of the same example:

transform = ComposeMany(transforms=transforms, num_augmented_samples=2)
transformed_ecg =  transform(ecg)
>> transformed_ecg.shape = [2, num_leads, num_samples]

Citation

@software{avramidis_kleanthis_2023_8053043,
    author = {Avramidis, Kleanthis},
    title = {ecg-augmentations},
    year = 2023,
    publisher = {Zenodo},
    version = {v1.0.0-beta},
    doi = {10.5281/zenodo.8053043},
    url = {https://doi.org/10.5281/zenodo.8053043}
}

ecg-augmentations's People

Contributors

spijkervet avatar klean2050 avatar lilywilde avatar

Stargazers

 avatar  avatar Kai He avatar  avatar Swizard avatar  avatar  avatar Soyabul Islam Lincoln avatar Maria Despoina Siampou avatar  avatar Kommineni Aditya avatar  avatar  avatar  avatar NicholasZhao avatar  avatar  avatar  avatar Mohammed Yusuf Ansari avatar Vasiliki Vasileiou avatar Georgios Chochlakis avatar Łukasz Furman avatar ZHANG Zhi avatar Tiantian Feng avatar

Watchers

 avatar Kostas Georgiou avatar

ecg-augmentations's Issues

Mask Augmentation for 12 lead ECG

Hi,

Thank you for accommodating my request for the sampling rate. I have been testing the Mask augmentations. They seem to work well for a single lead ECG. However, they don't support 12-lead ECG. This is crucial because I cannot individually augment every lead differently because it will distort the information sequence. Do you think it will be feasible to add support for multi-lead ECG data? other transforms invert, reverse work with 12-lead ECG data.

Fixed signal sampling rate

Hi,

Thank you for initiating this repo. It is much needed in the PyTorch space. I was playing with the mask transforms and noticed that you had fixed the sampling of the ECG signals. However, this has to be an argument from the user depending on the ECG signal he/she is working with.

Am I missing something? Kindly clarify at the earliest.

Yusuf

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.