This repository contains code and data for implementing a method to extract fetal electrocardiogram (ECG) signals from a maternal ECG signal on the time-frequency domain using Pix2Pix GAN.
Fetal ECG extraction from maternal ECG signals is important in clinical settings, as it can provide crucial information about fetal health. However, fetal ECG signals are typically much weaker than maternal ECG signals, making it challenging to extract them directly from the raw signal.
In this repository, we present a method for fetal ECG extraction on the time-frequency domain using Pix2Pix GAN. We train Pix2Pix to learn the mapping between maternal ECG spectrograms (domain A) and corresponding fetal ECG spectrograms (domain B). During testing, we apply the trained Pix2Pix to a maternal ECG spectrogram to obtain the corresponding fetal ECG spectrogram.
First, create a virtual environment for the repository
conda create -n fecg python=3.8
then activate the environment
conda activate fecg
Download or clone the repository:
git clone https://github.com/dustin-nguyen-qil/fECG_cGAN.git
Next, install the dependencies by running ...
pip install -r requirements.txt
If you want to see the results without retraining the model, refer to evaluate.ipynb
to directly see the comparison with conventional method.
If you want to run the code cells again, download the fECG spectrograms produced by conventional method and our proposed model trained with 125 epochs from here.
Then unzip and put results
folder at the outermost level in the code folder.
results
---> fecg_p2p
---> spectrogram_conventional
---> test_latest
- Download the spectrograms generated from Abdominal and Direct dataset from here.
- Unzip the data, put into folder
data
as following
data
---> adbecg
---> ...
Pix2Pix requires to align the data for pairs of training images
$ python datasets/combine_A_and_B.py --fold_A data/adbecg/spectrogram/A --fold_B data/adbecg/spectrogram/A --fold_AB datasets/adbecg
Run the following command for training (here I set --n_epochs 5
and --n_epochs_decay 5
to save training time if you only want to validate the training phase works fine)
python train.py --dataroot ./datasets/adbecg --name fecg_p2p --model pix2pix --direction AtoB --n_epochs 5 --n_epochs_decay 5
Training results will be saved in checkpoints
. To see more intermediate results, check out ./checkpoints/fecg_p2p/web/index.html
If you have download the results from here, make sure you remove the results folder before running testing.
Run the following command for testing
python test.py --dataroot ./datasets/adbecg --name fecg_p2p --model pix2pix --direction AtoB
The test results will be saved to a html file here: ./results/fecg_p2p/test_latest/index.html
.
After you have run testing, you will see the results folder is automatically created. You can download the fECG spectrograms generated by conventional method from here
Then unzip and put conventional
folder in results
as following.
results
---> fecg_p2p
---> conventional
---> test_latest
This repository was based on the following repository: Pix2PixGAN. We would like to thank the authors for a contributing work.