Ultra-wideband (UWB) is regarded as the technology with the most potential for precise indoor location due to its centimeter-level ranging capabilities, good time resolution, and low power consumption. However, Because of the presence of non-line-of-sight (NLOS) error, the accuracy of UWB localization deteriorates significantly in harsh and volatile indoor conditions. Therefore, identifying NLOS conditions is crucial to enhancing the accuracy of UWB location. This paper proposes a convolutional neural network (CNN) classification method based on an improved Dung Beetle Optimizer (DBO). Firstly, based on the standard DBO, the Circle chaotic mapping, non-uniform Gaussian variational strategy, and multi-stage perturbation strategy are used to optimize the exploration capability and enhance the performance of original DBO method, the superiority-seeking ability of IDBO is demonstrated by testing 23 benchmark functions. In addition, based on the IDBO algorithm, we propose an IDBO-CNN classification model, with the help of IDBO, the accuracy of NLOS identification is improved by adjusting the hyperparameters of CNN to be closer to the optimal solution. Experiments conducted on the open-source dataset demonstrate that IDBO-CNN is capable of achieve the desired effect. In comparison to the conventional CNN approach, the F1-score achieved by IDBO-CNN is enhanced by 3.31%, which demonstrates that IDBO-CNN has superior identification accuracy.