I had the very same thing with my gsd when she was growing up, and at the time, I put it down to those "fear" periods. It got just as scarey as your dog's sudden outbursts quite honestly on occasions too!
I would take her up to my mum's care home from the age of about 5 months, and some days she'd walk in there, tail wagging, sit nicely, let people stroke her, and then I'd stand there chatting and she'd suddenly lunge at one of the male carers or even a female
WHY? who knows!
I had male friends coming to the house for early breakfasts before they went off for the day racing with my hubby, and we did everything right at the back door, and she was fine, even went off and laid down and ignored them, THEN an hour into them being here, I was chatting in the kitchen to one of them and she suddenly started her manic barking at him as if he was an intruder
This would also happen with brother-in-law in her earlier days too, and no matter how I tried to calm the situation, nothing seemed to work, so to me, she became "unpredictable" which isn't good when you've got a young gsd about to approach the teenage stage.
One day, I had walked with a friend for a whole hour in the woods with her old lab, and my dog was fine with her. We finished the walk, and decided to pop into that care home again where my mum was, and she came with me. She was stood at the foot of the bed and mum was in her chair and Zena was leaning over my mum giving her kisses. I pulled her off and made her lie down. Then this friend of mine went over to my mum, bent over her and gave her a kiss, turned around and Zena was there, so she went to give her a stroke, but she "thinks" she got down on the floor, and Zena went berserk at her, barking and lungeing at her (I still had her onlead thank God!).
Anyhooo, that was all a very long time ago, coz this dog is now 19 months old or thereabouts, and have to say, she is absolutely fine with everybody, even MEN, who she didn't like at all last year, and although I will never say never, at least I know that now I am in total control of her, she would listen if I objected to any of her outbursts (I think, I hope, coz it just hasn't happened since!). I suppose the bottom line is, because of what has happened in the past, it's made me a lot more aware of her capabilities, so everyone that comes here is told to ignore her until SHE is ready to go up to them and it works. The other morning I had two police officers call at the house, and the top half of the stable door was open, and Zena was doing her usual barking with her feet stuck on the top of the door, and the lady policewoman, just put her hand nonchalently over that door
Zena sniffed it, then licked it and dropped off the door and was quiet! They're strange creatures these gsd's aren't they!!! This is a first for me with situations like I had, and Zena is my 8th shepherd!
I went to meet my breeder last week-end at a big show (she does obedience), and met my current dog's sister, and as I greeted her, I did it all properly, just like your trainer did with your dog, and yet she backed off, barked and growled, but I wasn't scared (I have her sister remember!), so I got down on the floor, spoke to her gently and she came to me and kissed me. So don't think anything you are doing is wrong, this dog is owned by an obedience trainer, she has many dogs, she's well used to shepherds and yet this happened! Personally, I think your dog has a lot going on in it's head, maybe time will cure it, maybe more training, who knows, I just wish you luck, I have experience of what you went through, but I can't tell you what I've done to cure it, it's just sort of happened! Good luck to you, keep up the good work, let's hope you get a turn around like I have.
The other morning I had a delivery man arrive, and unbeknown to me, I thought we were alone on our driveway, but I'd left the french doors open and Zena came zooming out, yelling and barking at him, and I yelled at her, he did the RIGHT thing, he just stood there and held out his hand (he was probably frozen to the spot poor man!!!), and Zena hesitantly went over to his hand and sniffed it then licked it, and came running over to me coz I was saying "cheese" in the bootroom so I could shut her away in there! Phew! Then another delivery man actually wanted to meet her coz he had shepherd, so I let her out, armed him suitably with some cheese, and within 20 seconds he was playing ball out there with her! You see, it CAN be done, just keep working on it!