Wastewater has detrimental effects on the natural environment. The activated sludge method, a widely adopted approach for wastewater treatment, has proven highly effective. Within this process, microorganisms play a pivotal role, necessitating continuous monitoring of their quantity and diversity. Conventional methods, such as microscopic observation, are time-consuming. With the widespread integration of computer vision technologies into object detection, deep learning-based object detection algorithms, notably the You Only Look Once (YOLO) model, have garnered substantial interest for their speed and precision in detection tasks. In this research, we applied the YOLO model to detect microorganisms in microscopic images of activated sludge. Furthermore, addressing the irregular shapes of microorganisms, we developed an improved YOLO model by incorporating deformable convolutional networks and an attention mechanism to enhance its detection capabilities. We conducted training and testing using a custom dataset comprising five distinct objects. The performance evaluations used in this study utilized metrics such as the mean average precision at intersections over a union threshold of 0.5 (mAP@0.5), with the improved YOLO model achieving a mAP@0.5 value of 93.7%, signifying a 4.3% improvement over the YOLOv5 model. Comparative analysis of the improved YOLO model and other object detection algorithms on the same dataset revealed a higher accuracy for the improved YOLO model. These results demonstrate the superior performance of the improved YOLO model in the task of detecting microorganisms in activated sludge, providing an effective auxiliary method for wastewater treatment monitoring.