Abandoning a good action in middle thinking that people will consider me to be pious is riya (ostentation).
Whereas, doing an action to impress others is shirk (associating partners with Allah).
Hence, sincerity is to be saved from both of these by Allah.
Ahzab tahzib un nafus, Munajat e maqbool, (zamimajat, Saeedi) page 303