Anshu13 commited on
Commit
7bde47e
·
verified ·
1 Parent(s): b780e91

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -9
app.py CHANGED
@@ -7,7 +7,7 @@ import cv2
7
  from PIL import Image
8
  from model import create_model
9
  model,transform=create_model(num_of_classes=3)
10
- model.load_state_dict(torch.load("fire_smoke_weight.pth", map_location=torch.device("cpu")))
11
  model.eval()
12
  def classify_video(video):
13
  cap = cv2.VideoCapture(video)
@@ -27,7 +27,7 @@ def classify_video(video):
27
  pred = output.argmax().item()
28
  predictions.append(pred)
29
  cap.release()
30
- class_names=['DEFAULT', 'FIRE', 'SMOKE']
31
  for i in predictions:
32
  if i == 1:
33
  Fire.append(i)
@@ -35,14 +35,10 @@ def classify_video(video):
35
  Smoke.append(i)
36
  else:
37
  Default.append(i)
38
- if len(Fire)>10 and len(Smoke)>8:
39
- return f"Spotted {class_names[1]} and {class_names[2]}"
40
- elif len(Fire)>10:
41
- return f"Spotted {class_names[1]}"
42
- elif len(Smoke)>8:
43
- return f"Spotted {class_names[2]}"
44
  else:
45
- return f"Spotted {class_names[0]}"
46
  Description="An MobileNET model trained to classify Fire and Smoke through Videos"
47
  Article="Created at jupyter NoteBook with GPU NVIDIA_GeForce_MX350"
48
  gr.Interface(
 
7
  from PIL import Image
8
  from model import create_model
9
  model,transform=create_model(num_of_classes=3)
10
+ model.load_state_dict(torch.load("fire_smoke_weights.pth", map_location=torch.device("cpu")))
11
  model.eval()
12
  def classify_video(video):
13
  cap = cv2.VideoCapture(video)
 
27
  pred = output.argmax().item()
28
  predictions.append(pred)
29
  cap.release()
30
+ class_names=['DEFAULT', 'FIRE Spotted', 'SMOKE Spotted']
31
  for i in predictions:
32
  if i == 1:
33
  Fire.append(i)
 
35
  Smoke.append(i)
36
  else:
37
  Default.append(i)
38
+ if len(Fire)>5 and len(Smoke)>5:
39
+ return f"Fire and Smoke"
 
 
 
 
40
  else:
41
+ return f"Spotted {class_names[max(predictions)]}"
42
  Description="An MobileNET model trained to classify Fire and Smoke through Videos"
43
  Article="Created at jupyter NoteBook with GPU NVIDIA_GeForce_MX350"
44
  gr.Interface(