Given the high complexity of office environments and the dense occlusion of personnel, which lead to low accuracy and high model complexity in detecting departures, this paper proposes MGDE-YOLO-a lightweight algorithm for personnel departure detection based on an improved YOLOv7 model. First, MobileNetV3 replaces the backbone feature extraction network of YOLOv7, thereby reducing the model's parameter count. Next, the new SPPCSPC_Ghost module, built with GhostConv, replaces the original SPPCSPC module. This change lowers model parameters, and increases feature fusion speed, which improves detection accuracy. The ultra-lightweight dynamic upsampling operator, DySample, is also introduced to update the model's upsampling operations, thereby reducing computational costs and enhancing performance. Finally, we propose the F-ECA attention module, which allows the model to better focus on essential features while suppressing unimportant ones. This improvement reduces missed and incorrect detections. Experimental results show that the MGDE-YOLO model reduces the number of parameters and computational load by 40.5% and 63.4%, respectively, compared to the original YOLOv7 model. Additionally, we compress the model's weight size to 40.1% of the original, reduce inference time by 31.8%, and improve the mean average precision by 2.3%, reaching 97.6%. This method significantly enhances the accuracy and speed of personnel absence detection in complex backgrounds while preserving the model's lightweight nature and practicality, making it suitable for deployment in natural office environments.