Same here. Before relapse (masturbating or watching porn) you have thoughts about masturbation and porn. Before having this thoughts you have visuals. So one leads to another. So you have to find your own personal way how to distract yourself from visuals and thoughts. I believe it's individual. You might get yourself busy with a hobby or work, you might have counter thoughts or counter visuals where you see negative effect of porn for instance. But the most important thing you need to try to stay alert and be aware when these visuals appear. Good luck.
Well, my advice is to let it be okay that you have them. Vigilance against a thought ("don't think about a white monkey") will only, and always, make you focus on it more, you will drive yourself insane if you resist something you already have. Be patient with yourself, remember that you have a choice in how you react to what your mind shows you. Please, don't turn demeanor into felony by trying to scold yourself for something that you already suffer from.