How to avoid sleeping in lectures?
The first thing you need to do in order to address this issue is to understand why you are falling asleep.  Since you say that you do not have difficulty focusing elsewhere, it seems likely that there is something specific about the lecture environment that is triggering your sleep.  The approach to fixing it depends on the cause.

Two likely possibilities:


If you are extremely fatigued in general, then any significant chunk of time where you are entirely passive, like in a lecture, is likely to result in you falling asleep.  I had this experience as an undergraduate.  The only real cure is to start sleeping more at night.  Remember, you are not in a sprint, but running a marathon, and you need to pace yourself at a sustainable level.
Packed lecture halls often have dim lights and/or higher CO2 content in the room (due to how densely packed people are), both of which are sleep-inducing for many people.  If this is the case, for you, a good way to counteract it is to move your body and get your blood flowing.  There are many exercises that can be done while seated, which will not generally be disruptive if you do them toward the back of a classroom.  In some larger lecture halls, it may also be possible to actually stand in the back, behind the seats.