Harsh72AI commited on
Commit
8be6929
·
verified ·
1 Parent(s): 159ce32

Project Files committed

Browse files
Fire_Smoke_Detection_YOLONas.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
Project_README.md ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ # Fire Detection using YOLO Nas
2
+
3
+ A streamlit app that uses a YOLO Nas fine-tuned model go predict given a image having a fire, where the fire is coming from. This could be very helpful in places were Fires are really not welcomed!
4
+
5
+ - Dataset Used: https://universe.roboflow.com/-jwzpw/continuous_fire/
6
+ - App link: https://huggingface.co/spaces/Harsh72AI/Fire-Detection
7
+
8
+
9
+ Our Fire-detection model has acheived a mAP:0.50 value of 0.82
Roboflow dataset.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:72ceed891dd60e5df8e25028a73c0ad422dd59a53012400e5753d4610955e641
3
+ size 15759390
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from pipeline import predictPipeline
3
+
4
+
5
+ st.title('Fire and Smoke detection')
6
+ st.write('Detects Fire or/and Smoke in a Photo \nPowered by YOLO-Nas medium model')
7
+
8
+ st.write('')
9
+
10
+ detect_pipeline = predictPipeline()
11
+
12
+ st.info('Fire and Smoke Detection model loaded successfully!')
13
+
14
+
15
+ uploaded_file = st.file_uploader("Upload an image", type=["jpg", "png", "jpeg"])
16
+
17
+ if uploaded_file is not None:
18
+
19
+ with st.container():
20
+ col1, col2 = st.columns([3, 3])
21
+ col1.header('Input Image')
22
+ col1.image(uploaded_file, caption='Uploaded Image', use_column_width=True)
23
+
24
+ col1.text('')
25
+ col1.text('')
26
+
27
+ if st.button('Detect'):
28
+ detections = detect_pipeline.detect(img_path=uploaded_file)
29
+ detections_img = detect_pipeline.drawDetections2Image(img_path=uploaded_file, detections=detections)
30
+
31
+ col2.header('Detections')
32
+ col2.image(detections_img, caption='Predictions by model', use_column_width=True)
33
+
pipeline.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from super_gradients.training import models
2
+ import cv2 as cv
3
+ import numpy as np
4
+ from PIL import Image
5
+ import matplotlib.pyplot as pl
6
+
7
+
8
+ class predictPipeline():
9
+ def __init__(self) -> None:
10
+
11
+ # Load model
12
+ self.model = models.get('yolo_nas_m',
13
+ num_classes=1,
14
+ checkpoint_path='yolo_nas_m_model.pth')
15
+
16
+ def detect(self, img_path):
17
+ image = Image.open(img_path).convert('RGB')
18
+ img_array = np.array(image)
19
+
20
+ preds = self.model.predict(img_array, conf=0.5)[0].prediction
21
+ bboxes_coordinates = []
22
+ for idx, bbox in enumerate(preds.bboxes_xyxy):
23
+ bboxes_coordinates.append([int(num) for num in bbox] + [round(preds.confidence[idx]*100, 2)])
24
+ return bboxes_coordinates
25
+
26
+
27
+ def drawDetections2Image(self, img_path, detections):
28
+ img = Image.open(img_path).convert('RGB')
29
+ img = np.array(img)
30
+ for bbox in detections:
31
+ x1, y1, x2, y2, score = bbox
32
+ cv.rectangle(img, pt1=(x1, y1), pt2=(x2, y2), color=(0, 255, 0), thickness=2)
33
+ cv.putText(img, text=f'{score}%', org=(x1, y1-2), fontFace=cv.FONT_HERSHEY_SIMPLEX, fontScale=0.5, color=(0, 0, 255), lineType=cv.LINE_AA)
34
+ img_detections = np.array(img)
35
+ return img_detections
36
+
37
+
38
+
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ super-gradients
2
+ torch
3
+ numpy
4
+ streamlit
yolo_nas_m_model.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ce5c48348ef8e1f7e17b3aa0ff97d81b06b9811699103f8ab723cb6455abd0b8
3
+ size 681045674