ubicomplab / rPPG-Toolbox

rPPG-Toolbox: Deep Remote PPG Toolbox (NeurIPS 2023)
https://arxiv.org/abs/2210.00716
Other
482 stars 117 forks source link

Concern about the HR prediction #147

Closed ZechenZed closed 1 year ago

ZechenZed commented 1 year ago

Hi,

I have a question regarding on the

def _calculate_fft_hr(ppg_signal, fs=60, low_pass=0.75, high_pass=2.5):
    """Calculate heart rate based on PPG using Fast Fourier transform (FFT)."""
    ppg_signal = np.expand_dims(ppg_signal, 0)
    N = _next_power_of_2(ppg_signal.shape[1])
    f_ppg, pxx_ppg = scipy.signal.periodogram(ppg_signal, fs=fs, nfft=N, detrend=False)
    fmask_ppg = np.argwhere((f_ppg >= low_pass) & (f_ppg <= high_pass))
    mask_ppg = np.take(f_ppg, fmask_ppg)
    mask_pxx = np.take(pxx_ppg, fmask_ppg)
    fft_hr = np.take(mask_ppg, np.argmax(mask_pxx, 0))[0] * 60
    return fft_hr

So here, I see the low_ pass is 0.75 and the high pass is 2.5 which means the lower bound of HR is 0.75 60 = 45 and the upper bound is 2.5 60 = 150. The (45,150) HR range is narrower than the possible range (40,220-age). Will that lead to a overfit based on the knowledge you know?

Best Regards, Zechen Zhang

girishvn commented 1 year ago

Hi @ZechenZed,

Your observation is correct, the filters applied to fall within the total HR range. Most literature explored by this toolbox focuses on healthy individuals, in scenarios that do not elicit extremely high HRs. The filters used also crop out the lower end of the possible HR spectrum. Individuals w/ HR sub 45bpm are quite rare, and not well represented in these open source datasets.

I would expect that relaxing the filter constraints slightly (to encompass all possible HRs) would result in a small loss in performance on most datasets, but would work more inclusively for data that falls outside of the filter range.

In terms of overfitting, these CNN based PPG architectures tend to learn frame-to-frame mappings as opposed to the actual frequency content. Relaxing the PPG constraints used for evaluation should not change the model training, but will change the values produced during evaluation.

Hope this helps, Girish

ZechenZed commented 1 year ago

Hi @girishvn,

Yeah, it does make sense. And I did try to expand the bandwidth from (0.75, 2.5) to (0.7, 3), the MAEs do increase but I will say they are subtle. Also, I do add another noise filter function when I was using the MTTS-CAN method in @xliucs 's previous repo. The motivation was when I was plotting the continuous HR plot by using @danmcduff 's iphys-toolbox, there were lots of local huge increases and decreases, like sudden increase of HR from 60 to 140 and then back to 60. Please let me know if it sounds like the right way to do it or if there is a better way of doing it. Thanks again!

Best Regards, Zechen Zhang

ZechenZed commented 1 year ago

Sorry for the confusion, the metric I was using is cMAE but not MAE. And that's why I saw local peaks by using a sliding window for calculating the HR.

girishvn commented 1 year ago

Adding some sort of smoothing to remove sudden changes of continuous MAE / continuous HR makes sense to me. That being said, if you are only looking at MAE for the entire video, then this is likely not necessary, as longer FFTs provide higher frequency resolution, but this may be useful when calculating continuous MAE on smaller snippets of waveforms.

ZechenZed commented 1 year ago

Yeah, that makes sense. Thanks for your quick response!

girishvn commented 1 year ago

Yup, anytime! I'm going to go ahead and close this thread, but feel free to open if something else comes up!

Best, Girish