The success of near-infrared spectroscopy (NIRS) analysis hinges on the precision and robustness of the calibration model. Shallow learning (SL) algorithms like partial least squares discriminant analysis (PLS-DA) often fall short in capturing interrelationships between adjacent spectral variables, and the analysis results are easily affected by spectral noise, which dramatically limits the breadth and depth application of NIRS. Deep learning (DL) methods, with their capacity to discern intricate features from limited samples, are progressively integrated into NIRS. In this paper, two discriminant analysis problems including wheat kernels and Yali pears were used as examples, and several representative calibration models to research the robustness and effectiveness of the model. Additionally, this article proposed a near-infrared calibration model, which is based on gramian angular difference field and coordinate attention convolutional neural networks (G-CACNN). The research results show that, compared with SL, spectral preprocessing has a smaller impact on the analysis accuracy of consensus learning (CL) and DL, and the latter has the highest analysis accuracy in the modeling results of using the original spectrum. The accuracy of G-CACNN in two discrimination tasks is 98.48% and 99.39%, respectively. Finally, This research compared the performance of various models under noise to evaluate the robustness and noise resistance of the proposed method.