1. A computer-implemented method for detecting objects in an input image, comprising: receiving a set of training images and associated annotations, the annotations labeling categories and locations of objects which appear in the images; determining one or more subcategories for each of the categories of objects, wherein the number of subcategories is inferred from the training images and the associated annotations; training classifiers for detecting the subcategories; training a respective structured model for each category of objects, the structured model accounting for relationships between detected subcategories; and detecting the objects in the input image using the trained subcategory classifiers and structured models.