SRUTHI123 commited on
Commit
d6c4dbe
·
verified ·
1 Parent(s): 9b883d7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -15
app.py CHANGED
@@ -19,30 +19,30 @@ def classify_action(detections):
19
  objects = [d[0] for d in detections]
20
  confidences = [d[1] for d in detections]
21
 
22
- has_person = 'person' in objects
23
- has_valuable = any(obj in objects for obj in ['backpack', 'handbag', 'laptop', 'cash', 'mobile', 'refrigerator', 'microwave'])
24
- low_conf = max(confidences) < 0.55 if confidences else True
25
- few_objects = len(set(objects)) <= 2
26
- mostly_person = objects.count('person') > len(objects) * 0.6
27
-
28
- if has_person:
29
- # Stealing logic
30
  if has_valuable:
31
  action_scores['Stealing'] += 0.7
32
  if 'handbag' in objects or 'laptop' in objects:
33
  action_scores['Stealing'] += 0.2
34
 
35
- # Sneaking logic
36
- if low_conf and not has_valuable:
37
- action_scores['Sneaking'] += 0.8
38
 
39
- # Peaking logic
40
- elif few_objects and mostly_person:
41
  action_scores['Peaking'] += 0.7
42
 
43
- # Normal behavior fallback
44
  else:
45
- action_scores['Normal'] += 0.5
46
  else:
47
  action_scores['Normal'] += 1.0
48
 
@@ -54,6 +54,7 @@ def classify_action(detections):
54
 
55
  return action_scores
56
 
 
57
  # ------------------ Detection Function ------------------
58
  def detect_action(image_path):
59
  results = model.predict(source=image_path, conf=0.4, iou=0.5, save=False, verbose=False)
 
19
  objects = [d[0] for d in detections]
20
  confidences = [d[1] for d in detections]
21
 
22
+ num_persons = objects.count('person')
23
+ total_objects = len(objects)
24
+ avg_conf = np.mean(confidences) if confidences else 0.0
25
+
26
+ has_valuable = any(obj in objects for obj in ['backpack', 'handbag', 'laptop', 'cash', 'microwave', 'refrigerator'])
27
+
28
+ if num_persons >= 1:
29
+ # Stealing
30
  if has_valuable:
31
  action_scores['Stealing'] += 0.7
32
  if 'handbag' in objects or 'laptop' in objects:
33
  action_scores['Stealing'] += 0.2
34
 
35
+ # Sneaking - enhanced logic
36
+ if (total_objects <= 2 and avg_conf < 0.5 and not has_valuable):
37
+ action_scores['Sneaking'] += 0.9
38
 
39
+ # Peaking
40
+ elif (total_objects <= 3 and num_persons == 1 and avg_conf >= 0.5):
41
  action_scores['Peaking'] += 0.7
42
 
43
+ # Normal fallback
44
  else:
45
+ action_scores['Normal'] += 0.6
46
  else:
47
  action_scores['Normal'] += 1.0
48
 
 
54
 
55
  return action_scores
56
 
57
+
58
  # ------------------ Detection Function ------------------
59
  def detect_action(image_path):
60
  results = model.predict(source=image_path, conf=0.4, iou=0.5, save=False, verbose=False)