I think a lot of people have done this. I know I have but I have been yelled at a few times for it so I really try not to let it happen.
I would say just focusing on your breathing when your resting and during an exercise. Good strong belly breaths, in the nose out the mouth. I know that's what I'm working on.
I seen a black belt do that during class once. Kind of surprised me. I wonder what a Sensei like Sensei Chinen would do if he caught someone yawning.
May the force be with you.