Home >Technology peripherals >AI >Train YOLOv7 model and develop AI fire detection
The data set uses open source images, a total of 6k fire images, marked with thick smoke
and Fire
Two categories.
火
YOLOTraining, I have converted the data into
YOLOformat, and separated the training set and validation set, see the
datasetdirectory.
fire_detector = torch.hub.load('./yolov7', 'custom', './weights/fire.pt', source='local')There is a fire video fire_video.mp4 in the source code, which can be read with opencv to test the detection effect.
ret, frame = cap.read() results = self.fire_detector(img_cvt) pd = results.pandas().xyxy[0] # 绘制检测框 for obj in pd.to_numpy(): box_l, box_t = int(obj[0]), int(obj[1]) box_r, box_b = int(obj[2]), int(obj[3]) obj_name = obj[6] if obj_name == 'smoke': box_color = (0, 0, 255) box_txt = '检测到浓烟' else: box_color = (0, 255, 0) box_txt = '检测到大火' frame = cv2.rectangle(frame, (box_l, box_t), (box_r, box_b), box_color, 2) frame = cv2_add_chinese_text(frame, box_txt, (box_l, box_t-40), box_color, 25)After running successfully, the effect will be the same as the video at the beginning of the article. You can deploy the project to an embedded GPU, such as jetson nano, for real-time detection. Develop a cloud communication service to call the police in the event of a fire. At the same time, an APP can also be developed to transmit the live video stream back to the server. The APP can see the monitoring effect in real time and help make decisions. 4. DifficultiesIn fact, there are still some difficulties in using target detection for fire detection. For example, there are many interfering samples, which can easily lead to false detections. For another example, inconsistent labeling prevents efficient calculation of mAP. So, it is best if we can customize the loss function and the calculation method of the accuracy. Taking recall as an example, if we can detect a fire in the picture, it will be considered successful, but it does not necessarily have to detect how many flames and how many smokes. Of course, this type of task does not necessarily have to be done through target detection. A friend suggested to me the use of classification tasks and segmentation tasks, and I think I can try both.
The above is the detailed content of Train YOLOv7 model and develop AI fire detection. For more information, please follow other related articles on the PHP Chinese website!