Learning Perceptual Inference by Contrasting