The situation and ruling differs based on your circumstances!
The rulings, virtues and manners of interaction between (foreign) men and women are described in the quran (see 24:30-33). And ahadith such as:
I asked Allah's Messenger (ﷺ) about the sudden glance (that is cast) on the face (of a non-Mahram). He commanded me that I should turn away my eyes. (Sahih Muslim)
and
The Prophet (ﷺ) said: to Ali: Do not give a second look, Ali, (because) while you are not to blame for the first, you have no right to the second. (Sunan abi Dawod)
But first we must clear a point: looking at a foreign woman is not per se haram! As for the unintentional looking this is already covered in the ahadith above. But what goes beyond that will be discussed in the following:
For example it is allowed to look any women in the face in any -halal- situation and where it is necessary.
In his book the ruling on "Looking" (Ahkam an-Nadhar أحكام النظر p 143) ibn Qattan al-Fasy ابن قطان الفاسي says:
" إن كانت هذه الأجنبية – أي غير المحرم – كبيرة ، وهي مسلمة ، فلا خفاء بتحريم النظر من الأجنبي إلى ما عدا وجهها وكفيها وقدميها : كالصدر والبطن والعنق والشعر وما فوق السرة والظهر ، هذه مواضع لا يجوز له النظر إلى شيء منها أصلا ، وهذا مما لا خلاف فيه " (source: islamqa #114196)
(My own translation take it carefully)
If this foreign lady -meaning non-Mahram- was old, and Muslimah there's no doubt that it is not lawful for a foreigner to look at her except for the face, hands and feet like: the breast, neck, hair and all which is above the naval and the back, all these are places which are not allowed for him to look at by default, and there's no dispute about this.
As for the situations where it is allowed to look at the face we may count the situation of teaching or studying, trading, helping, to witness or attest something, healing, considering marrying her (fiancé) and so on. As the necessity allows the unlawful الضرورات تبيح المحظورات (a known rule of fiqh). But looking is only allowed when fitna is excluded and there's no desire associated with it.
Imam Ahmad ibn Hanbal said:
لا يشهد على امرأة إلا أن يكون قد عرفها بعينها، وإن عامل امرأة في بيع أو إجارة، فله النظر إلى وجهها ليعلمها بعينها. (source: islamweb #41873)
(My own translation)
It is necessary for testifying for/against a woman to know (recognize) her, and if he has to operate with her like in trading or hiring it is permissible to look at her to recognize her (in future)
The hanbaldi scholar al-Mardawi المرداوي said:
قال الشيخ تقي الدين رحمه الله: هل يحرم النظر إلى وجه الأجنبية لغير حاجة؟ رواية عن الإمام أحمد: يكره، ولا يحرم، وقال ابن عقيل: لا يحرم النظر إلى وجه الأجنبية إذا أمن الفتنة ـ قلت: وهذا الذي لا يسع الناس غيره، خصوصا للجيران والأقارب غير المحارم الذين نشأ بينهم، وهو مذهب الشافعي. (source: islamweb #352963)
(My own translation take it carefully)
The Sheikh taqy ad-Dyn may Allah have mercey on him said: is it haram to look at the face a foreign lady without necessity? One narration of imam Ahmad is: it is makrooh and not haram, ibn 'Oqayl (or 'Aqyl) said: it is not haram to look a foreign woman in the face if fitna is excluded, and I say: in this what people can afford, especially neighboors and relatives which are non-mahrams which one has grown up with and this is the opinion of a-Shafi'i.
Imam an-Nawawi says in his commentary of sahih Muslim:
" إذا كانت حاجة شرعية فيجوز النظر ، كما في حالة البيع ، والشراء ، والتطبب ، والشهادة ونحو ذلك ، ولكن يحرم النظر في هذه الحال بشهوة ، فإن الحاجة تبيح النظر للحاجة إليه ، وأما الشهوة فلا حاجة إليها " انتهى (source same fatwa from islamqa as above)
(My own translation take it carefully)
"If there's a legal necessity it is permissible to look, like in case of trading, healing, giving an a testimony and so on, but it is not allowed to look in case of desire, because the necessity allows looking because there's necessity for it, as for desire there's no necessity for it"
However it is not permissible to look too long at a face of a female teacher or student and you should reduce your gaze as much as as you can.
And if this teacher or student is not wearing hijab you should even consider choosing a different class or school if possible -according some scholars- or avoid even more to look too long at their face this is the main answer of the fatwas I've consulted and referenced.