The recognition and classification of building shapes are the prerequisites and foundation for building simplification, matching, and change detection, which have always been important research problems in the field of cartographic generalization. Due to the ambiguity and uncertainty of building shape outlines, it is difficult to describe them using unified rules, which has always limited the quality and automation level of building shape recognition. In response to the above issues, by introducing object detection technology in computer vision, this article proposes a building shape recognition and classification method based on the YOLO object detection model. Firstly, for different types of buildings, four levels of building training data samples are constructed, and YOLOv5, YOLOv8, YOLOv9, and YOLOv9 integrating attention modules are selected for training. The trained models are used to test the shape judgment of buildings in the dataset and verify the learning effectiveness of the models. The experimental results show that the YOLO model can accurately classify and locate the shape of buildings, and its recognition and detection effect have the ability to simulate advanced human visual cognition, which provides a new solution for the fuzzy shape recognition of buildings with complex outlines and local deformation.