Why does my dog bark at anyone in uniform?

I was walking my dog, he's a German Shepherd mixed with Rottweiler. We went to the park and a police officer got out of his car and asked to pet him. I said yes and when he tried to he started growling and barking but he lets anyone else touch him. Another time, a guy in the army was walking past my house and my dog started barking at him and tried to chase him.
Why does my dog bark at anyone in uniform?
Post Opinion