Automatic interpretation of cardiopulmonary exercise tests with deep learning

Andrea Zignoli
4 min readFeb 21


Photo by Gary Bendig on Unsplash

What is a cardiopulmonary exercise test?

Cardiopulmonary exercise testing (CPET) is a non-invasive diagnostic tool that is widely used to assess the cardiovascular and respiratory systems’ response to exercise. It provides a comprehensive assessment of exercise capacity and has become an essential tool for healthcare professionals in the diagnosis and management of various cardiopulmonary diseases, as well as for athletes and sports scientists in the optimisation of athletic performance.

Typically, the ventilatory variables collected during a CPET are those presented in the 9-panel plot below: the O2 consumption (VO2, ml/min), the exhaled CO2 (VCO2, ml/min), the heart rate (HR, bpm), the ventilation (VE, l/min), and the end-tidal O2 and CO2 (PetO2 and PetCO2, mmHg).

Under normal circumstances, a well-executed CPET should reveal three distinct patterns in the CPET variables. These patterns indicate different levels of exercise intensity domains and their corresponding metabolic states. Exercise physiologists are especially interested in the VO2 value associated with these transitions, which are referred to as the ventilatory thresholds.

Can deep learning aid CPET interpretation?

Deep learning is a machine learning technique that has gained popularity in recent years due to its ability to automatically learn and improve from experience without being explicitly programmed. Deep learning algorithms can be trained on large datasets of ventilatory variables to learn patterns and detect ventilatory thresholds in CPET.

One approach is to use recurrent neural networks (RNNs), which are well-suited to analyze time-series data such as the ventilatory variables recorded during CPET. RNNs can learn the patterns of changes in the ventilatory variables over time and use this information to detect the ventilatory threshold.

Another approach to using deep learning for ventilatory threshold detection is to use convolutional neural networks (CNNs). These networks can analyze the raw data from CPET and identify features that are useful for predicting the ventilatory threshold. The CNNs can then use these features to classify the data into exercise intensity domains and hence to highlight the ventilatory thresholds.

In both cases, a large annotated dataset is required for training the deep learning models. The annotated dataset would consist of the ventilatory variables recorded during CPET, along with the ventilatory threshold determined by a human expert. Once the deep learning model is trained, it can be used to automatically detect the ventilatory threshold in new CPET recordings.

Using deep learning for ventilatory threshold detection has the potential to reduce the workload of experts and increase the accuracy and reproducibility of the results. Further research is trying to validate the performance of these methods and to determine how they can be integrated into clinical practice.

Hands on example

The first step is about installing the Python package pyoxynet.

pip install pyoxynet

Now, it’s time to import the packages for this exercise in the actual Python script.

import pyoxynet
import matplotlib.pyplot as plt

Pyoxynet can work with CPET files with the following file extension: “.csv”, “.txt”, “.xlsx”, or “.xls”. Basically, you just point at the file in your directory and you load the data in suitable format.
It’s important to notice that the parser might not be able to read your specific file format, but only a file generated by a compatible metabolimeter (COSMED and Cortex are usually accepted). Anyway, you can find some data files in this Google drive directory.

# load the file (with complete relative or absolute path)
t = pyoxynet.Test(filename)
# set the extension of the file
# parse the data (if metabolimeter is compatible)
# actually arrange the data in Pandas df
# create the Pandas df ready for the inference
# call the inference model
df_estimates, dict_estimates = pyoxynet.test_pyoxynet(input_df=t.data_frame)

A data frame with all the data is retrieved together with a dictionary that you can easily use for display the results easily if you export a json. Estimated ventilatory variables are provided in terms of time from the beginning of the test or in terms of VO2. You can easily extrapolate these values form the output dict.

Shown below is a graph of the outcome from the individual test, where VO2 is plotted over time. A solid vertical line indicates the first ventilatory threshold, while a dashed vertical line indicates the second ventilatory threshold.

plt.scatter(t.time, t.VO2)
plt.vlines(dict_estimates['VT1']['time'], np.min(t.VO2), np.max(t.VO2))
plt.vlines(dict_estimates['VT2']['time'], np.min(t.VO2), np.max(t.VO2), linestyles='dashed')
plt.xlabel('Time (sec)')
plt.ylabel('VO2 (ml/min)')

You can also plot the end-tidal O2 and CO2, which are typically used to detect the first and the second ventilatory thresholds.

plt.scatter(t.VO2, t.PetO2)
plt.scatter(t.VO2, t.PetCO2)
plt.vlines(dict_estimates['VT1']['VO2'], np.min(t.PetCO2), np.max(t.PetO2))
plt.vlines(dict_estimates['VT2']['VO2'], np.min(t.PetCO2), np.max(t.PetO2), linestyles='dashed')
plt.xlabel('VO2 (ml/min)')
plt.ylabel('Pet (mmHg)')

Congrats, you just estimated the ventilatory thresholds in your CPET data file with a deep learning algorithm.

Additional reading

Pyoxynet is part of the Oxynet project, which aims at developing machine learning models for the automatic interpretation of CPET data. You can find additional information at the project repository.



Andrea Zignoli

A self-employed engineer who creates mathematical models of sport physiology and performance.