Update app.py
Browse files
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 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
if
|
| 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 logic
|
| 36 |
-
if
|
| 37 |
-
action_scores['Sneaking'] += 0.
|
| 38 |
|
| 39 |
-
# Peaking
|
| 40 |
-
elif
|
| 41 |
action_scores['Peaking'] += 0.7
|
| 42 |
|
| 43 |
-
# Normal
|
| 44 |
else:
|
| 45 |
-
action_scores['Normal'] += 0.
|
| 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)
|