The statistics of disease spores is significant for early strategy design of disease control in precision agriculture. To obtain the statistics information of spores in microscopic images, it is crucial to segment spores from images. In this paper, we research a deep learning based method to segment spores, taking anthrax spores as the research objects. We first built an anthrax spore dataset consisting of more than 40,000 spores with accurate labeled spore boundaries to advance the state of the art technology of spore statistics. Then on consideration of the complex class imbalances in actual anthrax spore images, we investigate how class imbalances and hard examples simultaneously influence the loss during training and we discover that hard examples are more likely to appear at the pixels of rare pixels, such as small class pixels and contour pixels. Based on this discovery, we propose Constrained Focal Loss (CFL), which focuses on small class objects, and has a constrained term related to hard examples. In addition, we further propose CFL * , where high importance is put on the pixels surrounding spore contours to improve classification accuracy. The results show that the mean IoU of the DeepLabv3+ trained with CFL * (called as CFL * Net) achieves 91.0%, higher than original DeepLabv3+ with cross-entropy by 8.6 points, and the DeepLabv3+ with Focal Loss by 10.4 points. Moreover, CFLNet * can achieve better performance than original DeepLabv3+, using less than one-third of the training samples and half of the training steps. INDEX TERMS Image segmentation, class imbalance, focal Loss, hard example, convolutional neural networks (CNN).