Accurate detection of flames is an important prerequisite for the implementation of many security measures. To address the problems of low detection accuracy and difficulty in detecting small target flame in the current mainstream flame detection algorithms, we propose a small target flame detection algorithm incorporating an attention mechanism. First, we optimize the self-acquired dataset with data enhancement and structural similarity algorithms to improve the quality of the dataset and enhance the training efficiency of the model; then, a coordinate attention mechanism is introduced in the feature extraction stage of the original you-only-look-once (YOLOv7) network to improve the ability of the model to extract useful feature information and help the model to more accurately; and then, a small target flame detection layer is introduced at the output of the YOLOv7 network to improve the model's ability to detect small flames. Finally, the parameters of each layer of the improved model are initialized through model pre-training and migration learning to reduce the risk of model overfitting and accelerate the convergence speed of model training. The experimental results show that the average detection accuracy of the flame detection algorithm designed in this paper reaches up to 89.5%, which is 8.7% better than the detection accuracy of the original YOLOv7 algorithm and is innovative and practical. [ABSTRACT FROM AUTHOR]