All perfect praise be to Allah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad is His slave and Messenger.
If you were looking at the female teacher without desire, then some jurists have permitted looking at non-Mahram females for the purpose of education, as stated in the book I’aanat at-Talibeen ‘ala Hal Alfadh Fath al-Mu’een: “It is not permissible for a man to touch the face of a non-Mahram woman, even if it was permissible for him to look at her, such as for engagement, when she gives testimony, or teaching).” [End of quote]
If you know that you are looking at her with lust or fear to be tempted by her – as understood from your question – then you are religiously obligated to lower your gaze.
Ash-Sherbini said in Mughni al-Muhtaj:
“As for gazing with lust, it is absolutely forbidden for everyone who is looked at – whether she is a Mahram or else – except for his wife and his female slave.” [End of quote]
Seeking education is not an excuse for committing this forbidden act. If you do not lower your gaze, then you are sinful, and you must repent and search for another school. It is not permissible for you to continue in this school while insisting on looking at what is forbidden.
Allah knows best.