What is probably happening is that your German Shepherd is a dominant dog and doesn't have any problems with dogs that readily acknowledge his dominance. However, there are always going to be dogs that won't acknowledge him as the dominant dog or might test that dominance and to those dogs he reacts. Size also does't matter in these situations. Some of the most dominant dogs I know are little chihuahua.
It might also be triggered by the smell of the particular dog. He may remember a bad experience and that smell may trigger him to be more aggressive, but most likely it is a dominance issue.
I know you go weekly to training classes, but you also need to work with him daily practicing the commands you are learning. Training works best if you train at least 30 minutes a day (two 15 minute sessions). I would start making your dog work via the Nothing in life is free program (NILF). It is outlined below.
Obedience training serves to teach commands but also to establish you as the boss. As the boss it is your job to ensure no dogs bother him and to protect him. So definitely keep up with the obedience training.
Since it is intermittent, you will really need to pay attention to his body language. Body language should give you an idea if he is going to react to the other dog. Here are a few sites on body language for you to study.
Another trick you can use that many people do not know about is that if your dog is displaying dominant or aggressive behavior with the tail held high up, just brushing the tail down to a more neutral position (straight out from body or lowered) that can change a dog's mood to a less aggressive one.
If you can find a dog he reacts to consistently, you can use the bat method to help correct the situation. Read more on this here:
I hope this information is helpful to you and you are satisfied with my response. If you would like any additional information or have more questions please don’t hesitate to press the reply to expert or continue conversation button so I can address any issues you still have .