Unfortunately, wearing a headscarf for female tourists from the moment they arrive in Iran is a must. The country is very strict on this one particular point. When in public spaces, the headscarf should remain.
However, it is perfectly fine to have some hair showing. Many Iranian women wear it loose and have only half their heads covered with a headscarf.
In general foreign travellers have a bit more flexibility when it comes to the rules, but it is respectful to pay attention to them.