The annotations of all the crowd counting datasets so far are sparse binary matrices, so they cannot be used to supervise training directly. The mainstream crowd counting algorithm uses a Gaussian function to smooth each head label point, and then train their model by using it as “ground truth” density map. However, such “ground-truth” density maps are not perfect due to heavy occlusion, scale variation, background interference, etc. In this paper, we propose an improved BayesianLoss for the problems existing in the current crowd counting loss function. First of all, average distance to k-nearest neighbors is use to confirm the size of Gaussian likelihood estimation kernel for each labeled point to better distinguish the boundaries between crowds. Secondly, a new background likelihood estimation method is defined to better suppress the posterior probability of the edge background during training. In the evaluation of the mean absolute error metric, our method achieves state-of-the-art results on ShanghaiTech, UCF-CC-50and NWPU datasets. And on the largest dataset NWPU, our method outperforms the best loss-function-improving method DM-Count. At the same time, our loss function combined with other crowd counting models, such as MCNN, CAN, M-SFANet and TransCrowd, achieves better results than the original model.