In order to address the problems of high labor costs and low efficiency in manual inspection for tunnel foreign object detection, a tunnel foreign object detection algorithm based on improved YOLOv8n was proposed. Firstly, C2f_CA module was proposed with the incorporation of Coordinate Attention (CA) mechanism. In the module, by embedding positional information into channel attention, the network’s focus on the spatial distribution of features in the image was enhanced, thereby improving feature extraction capability of the network. Secondly, inspired by the concept of high-resolution network, a new feature fusion module HRNet_Fusion (High Resolution Net) was proposed to take extracted feature maps with different resolutions as four parallel branches and input them into the network, and multiple up-sampling, down-sampling, and fusion operations were performed to obtain comprehensive and accurate feature information. The above enhanced performance in small target detection and feature fusion significantly. Finally, the WIoU (Wise-IoU) loss function was introduced to reduce the harmful gradient effects of low-quality samples on the network, further improving model detection accuracy. Experimental results on a tunnel foreign object detection dataset indicate that the improved algorithm achieves mean Average Precision (mAP@0.5) of 79.9%, with a model size of 6.0 MB. Compared to YOLOv8n, the proposed algorithm has the mAP@0.5 enhanced by 6 percentage points, while the model size decreased by 0.2 MB, and the model parameters reduced by 0.379×106.