1. A computer-implemented method comprising: receiving a collection of images representative of a class; computing a respective part-based affinity between each pair of images in the collection of images, including: partitioning a first image of the pair of images into a plurality of partitions; determining a respective affinity for each partition of the first image, wherein the affinity is based at least in part on a measure of similarity between the partition and a location in a second image of the pair of images having a highest measure of similarity with the partition of the first image; determining a part-based affinity between the first image and the second image based at least in part on a sum of the respective affinities of the plurality of partitions of the first image with corresponding locations in the second image; generating a plurality of clusters of the images in the collection of images, wherein the plurality of clusters of images are based on the respective determined part-based affinities between each pair of images in the collection of images; selecting images in each cluster as being representative of a particular subclass of a plurality of subclasses of the class; and training a respective deformable parts model using images selected for each of the plurality of subclasses.