I have read and heard examples of both "could not help but notice" and "could not help noticing".
Hello, penguins. I could not help but notice that you have a hat that magically brings things.
— The Penguins of Madagascar: Happy King Julien Day! (2009)
Well, I'm sorry to have to put this to you, but I could not help noticing that you were miming.
— A Bit of Fry and Laurie: S02E01 (1990)
We hear and read both versions. Which one is grammatical—are they both? Please mention the nuance of each.