Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -50,18 +50,18 @@ CONFIG = {
|
|
| 50 |
"domain": "login"
|
| 51 |
},
|
| 52 |
"PUBLIC_URL_BASE": "https://huggingface.co/spaces/PrashanthB461/AI_Safety_Demo2/resolve/main/static/output/",
|
| 53 |
-
"FRAME_SKIP":
|
| 54 |
"CONFIDENCE_THRESHOLDS": {
|
| 55 |
-
"no_helmet": 0.
|
| 56 |
"no_harness": 0.15,
|
| 57 |
"unsafe_posture": 0.15,
|
| 58 |
"unsafe_zone": 0.15,
|
| 59 |
"improper_tool_use": 0.15
|
| 60 |
},
|
| 61 |
"IOU_THRESHOLD": 0.4,
|
| 62 |
-
"MIN_VIOLATION_FRAMES":2,
|
| 63 |
-
"HELMET_CONFIDENCE_THRESHOLD": 0.
|
| 64 |
-
"MAX_PROCESSING_TIME":
|
| 65 |
}
|
| 66 |
|
| 67 |
# Setup logging
|
|
@@ -379,7 +379,9 @@ def process_video(video_data):
|
|
| 379 |
helmet_compliance[worker_id]["no_helmet_frames"] += 1
|
| 380 |
if detection["confidence"] < CONFIG["HELMET_CONFIDENCE_THRESHOLD"]:
|
| 381 |
helmet_compliance[worker_id]["compliant"] = True
|
| 382 |
-
logger.debug(f"Worker {worker_id} marked as helmet compliant due to low no_helmet confidence")
|
|
|
|
|
|
|
| 383 |
if helmet_compliance[worker_id]["compliant"]:
|
| 384 |
logger.debug(f"Worker {worker_id} has helmet, skipping no_helmet violation")
|
| 385 |
continue
|
|
@@ -439,9 +441,8 @@ def process_video(video_data):
|
|
| 439 |
if worker_id in helmet_compliance and helmet_compliance[worker_id]["compliant"]:
|
| 440 |
logger.debug(f"Skipping no_helmet for worker {worker_id} due to helmet compliance")
|
| 441 |
continue
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
continue
|
| 445 |
|
| 446 |
best_detection = max(worker_dets, key=lambda x: x["confidence"])
|
| 447 |
violations.append(best_detection)
|
|
|
|
| 50 |
"domain": "login"
|
| 51 |
},
|
| 52 |
"PUBLIC_URL_BASE": "https://huggingface.co/spaces/PrashanthB461/AI_Safety_Demo2/resolve/main/static/output/",
|
| 53 |
+
"FRAME_SKIP": 5,
|
| 54 |
"CONFIDENCE_THRESHOLDS": {
|
| 55 |
+
"no_helmet": 0.6, # Increased to reduce false positives
|
| 56 |
"no_harness": 0.15,
|
| 57 |
"unsafe_posture": 0.15,
|
| 58 |
"unsafe_zone": 0.15,
|
| 59 |
"improper_tool_use": 0.15
|
| 60 |
},
|
| 61 |
"IOU_THRESHOLD": 0.4,
|
| 62 |
+
"MIN_VIOLATION_FRAMES": 2,
|
| 63 |
+
"HELMET_CONFIDENCE_THRESHOLD": 0.65, # Lowered to mark more workers as compliant
|
| 64 |
+
"MAX_PROCESSING_TIME": 30
|
| 65 |
}
|
| 66 |
|
| 67 |
# Setup logging
|
|
|
|
| 379 |
helmet_compliance[worker_id]["no_helmet_frames"] += 1
|
| 380 |
if detection["confidence"] < CONFIG["HELMET_CONFIDENCE_THRESHOLD"]:
|
| 381 |
helmet_compliance[worker_id]["compliant"] = True
|
| 382 |
+
logger.debug(f"Worker {worker_id} marked as helmet compliant due to low no_helmet confidence: {detection['confidence']}")
|
| 383 |
+
else:
|
| 384 |
+
logger.debug(f"Worker {worker_id} potential no_helmet violation with confidence: {detection['confidence']}")
|
| 385 |
if helmet_compliance[worker_id]["compliant"]:
|
| 386 |
logger.debug(f"Worker {worker_id} has helmet, skipping no_helmet violation")
|
| 387 |
continue
|
|
|
|
| 441 |
if worker_id in helmet_compliance and helmet_compliance[worker_id]["compliant"]:
|
| 442 |
logger.debug(f"Skipping no_helmet for worker {worker_id} due to helmet compliance")
|
| 443 |
continue
|
| 444 |
+
# Removed the stricter persistence check for no_helmet
|
| 445 |
+
logger.info(f"Confirmed no_helmet for worker {worker_id} with {len(worker_dets)} detections")
|
|
|
|
| 446 |
|
| 447 |
best_detection = max(worker_dets, key=lambda x: x["confidence"])
|
| 448 |
violations.append(best_detection)
|