Improving cross-dataset generalization in image classification with contrastive representation learning