Periodic defrosting is essential for efficient operation of air source heat pump to avoid the attenuation of performance caused by frosting. However, the mal-defrosting phenomena in practice, which are no defrosting progress when necessary and unnecessary defrosting operation under no frosting, happen occasionally. To improve the accuracy of defrosting, a convolutional neural network model based on deep learning with YOLOv5 is introduced for frosting detection in this paper. Firstly, the evaluation method of frosting degree combining fractal dimension and heating capacity attenuation is constructed. Then, an image dataset is built based on frosting degree evaluation. The optimized YOLOv5-frost network is constructed, which improves the accuracy of frosting detection by iterative training. Thirdly, a novel defrosting control method based on YOLOv5-frost network is proposed, in which the defrosting initiation and termination points are investigated. Finally, comparative experiments are conducted between the proposed defrosting control method and traditional methods. The results indicate that the mal-defrosting phenomena are effectively avoided under the proposed method. The COP and total heating capacity are increased by 11.83 % and 7.42 % respectively, as well as the defrosting frequency and energy consumption are decreased by 75.00 % and 88.24 %, respectively. Additionally, the time consumption, memory overhead, and central processing unit overhead of the proposed method are 2.72 %, 71.58 %, and 74.07 % of those for the traditional methods, respectively. The performance of air source heat pump unit in real-time frosting detection and on-demand defrosting in complex conditions can be effectively improved with the proposed method.