Correct detection of floating objects in complex water environments is a challenge because of the problems of obscuration and dense floating objects. In view of the above issues, this paper proposed a network called EC-YOLOX by introducing the CA (Coordinate Attention) and ECA (Efficient Channel Attention) mechanism and improving the loss function to further the multi-feature extraction and detection accuracy of floating objects. In this paper, ablation experiments and comparison experiments were conducted on the river floating objects dataset. The ablation experiments showed that the ECA and CA mechanism played a great role in EC-YOLOX, which can reduce the miss detection rate by 5.86% and increase the mAP by 5.53% compared with YOLOX. The EC-YOLOX was also applicable to different types of floating objects; the mAP of the ball, plasticgarbage, plastic-bag, leaf, milk-box, grass, and branches were respectively improved by 4%, 4%, 4%, 6%, 4%, 18%, and 5%. The mAP of the comparison experiments was improved by 15.13%, 9.30%, and 8.03% compared to Faster R-CNN, YOLOv5, and YOLOv3, respectively. This method facilitates the precise extraction of floating objects from images, which holds paramount importance for monitoring and safeguarding water environments. It offers significant contributions to water environment monitoring and protection.