def METHOD_NAME(self, landmarks):
    valid_frames_idx = [idx for idx, lm in enumerate(landmarks) if lm is not None]
    if not valid_frames_idx:
        return None
    for idx in range(1, len(valid_frames_idx)):
        if valid_frames_idx[idx] - valid_frames_idx[idx - 1] > 1:
            landmarks = linear_interpolate(landmarks, valid_frames_idx[idx - 1], valid_frames_idx[idx])
    valid_frames_idx = [idx for idx, lm in enumerate(landmarks) if lm is not None]
    # Handle corner case: keep frames at the beginning or at the end that failed to be detected
    if valid_frames_idx:
        landmarks[: valid_frames_idx[0]] = [landmarks[valid_frames_idx[0]]] * valid_frames_idx[0]
        landmarks[valid_frames_idx[-1] :] = [landmarks[valid_frames_idx[-1]]] * (
            len(landmarks) - valid_frames_idx[-1]
        )
    assert all(lm is not None for lm in landmarks), "not every frame has landmark"
    return landmarks