SamiKhokhar commited on
Commit
fd21413
·
verified ·
1 Parent(s): cdef2a7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -17,7 +17,10 @@ for root, dirs, files in os.walk(base_path):
17
  if best_path is None:
18
  print("Trained weights (best.pt) not found.")
19
  print("Using pre-trained YOLOv5 weights (yolov5s.pt) instead.")
20
- model = torch.hub.load('ultralytics/yolov5', 'yolov5s') # Load pre-trained weights
 
 
 
21
  else:
22
  try:
23
  print(f"Model weights found at: {best_path}")
@@ -37,8 +40,8 @@ def detect_weapons(image):
37
  except Exception as e:
38
  return f"Error during detection: {e}", None
39
 
40
- # Print available model class names to check for class mismatches
41
- model_classes = results.names # This should give the list of class labels used by the model
42
  print("Model class names:", model_classes)
43
 
44
  # Filter detections by confidence threshold (0.5 or higher)
@@ -47,8 +50,6 @@ def detect_weapons(image):
47
 
48
  # Get the detected classes with high confidence
49
  detected_classes = filtered_results['name'].unique()
50
-
51
- # Print detected classes for debugging
52
  print("Detected classes:", detected_classes)
53
 
54
  # Check if any of the detected objects are weapons
 
17
  if best_path is None:
18
  print("Trained weights (best.pt) not found.")
19
  print("Using pre-trained YOLOv5 weights (yolov5s.pt) instead.")
20
+ try:
21
+ model = torch.hub.load('ultralytics/yolov5', 'yolov5s') # Load pre-trained weights
22
+ except Exception as e:
23
+ print(f"Error loading pre-trained YOLOv5 model: {e}")
24
  else:
25
  try:
26
  print(f"Model weights found at: {best_path}")
 
40
  except Exception as e:
41
  return f"Error during detection: {e}", None
42
 
43
+ # Check available model class names
44
+ model_classes = results.names
45
  print("Model class names:", model_classes)
46
 
47
  # Filter detections by confidence threshold (0.5 or higher)
 
50
 
51
  # Get the detected classes with high confidence
52
  detected_classes = filtered_results['name'].unique()
 
 
53
  print("Detected classes:", detected_classes)
54
 
55
  # Check if any of the detected objects are weapons