PrashanthB461 commited on
Commit
e20916a
·
verified ·
1 Parent(s): 763d258

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -9
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": 50, # Increased to process fewer frames (1 frame every 5 frames)
54
  "CONFIDENCE_THRESHOLDS": {
55
- "no_helmet": 0.5,
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, # Reduced to ensure violations are detected with fewer frames
63
- "HELMET_CONFIDENCE_THRESHOLD": 0.7,
64
- "MAX_PROCESSING_TIME": 120 # Enforce 30-second processing limit
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
- if helmet_compliance[worker_id]["no_helmet_frames"] < CONFIG["MIN_VIOLATION_FRAMES"] * 2:
443
- logger.debug(f"Skipping no_helmet for worker {worker_id}, not enough persistent detections")
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)