Domain adversarial neural networks for domain generalization: when it works and how to improve