Generative and Discriminative Learning for Visual Matching