paranox commited on
Commit
fd12b0a
Β·
verified Β·
1 Parent(s): 4580660

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +178 -224
app.py CHANGED
@@ -291,8 +291,7 @@ def advanced_inference(
291
 
292
  # Strategy 2: Multi-scale inference (ensemble mode)
293
  if use_ensemble:
294
- scales = [img_size - 64, img_size +
295
- 64] if img_size >= 704 else [img_size]
296
  for scale in scales:
297
  results_scaled = model.predict(
298
  img,
@@ -422,8 +421,7 @@ def draw_boxes(image, boxes, show_conf=True, box_thickness=3):
422
  label_pos = "bottom"
423
 
424
  # Background rectangle with rounded appearance
425
- bg_coords = [x1, label_y, x1 + text_w +
426
- padding * 2, label_y + text_h + padding * 2]
427
  d.rectangle(bg_coords, fill=color + (240,))
428
 
429
  # Add subtle border to label
@@ -657,7 +655,7 @@ def predict_batch(files, conf, iou, use_tta, img_size, use_ensemble, enhance_img
657
 
658
 
659
  # ==========================================================
660
- # GRADIO UI (PREMIUM DESIGN)
661
  # ==========================================================
662
  css = """
663
  .gradio-container {
@@ -666,7 +664,7 @@ css = """
666
  margin: auto;
667
  }
668
  .primary-btn {
669
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
670
  border: none !important;
671
  color: white !important;
672
  font-weight: 600 !important;
@@ -675,7 +673,7 @@ css = """
675
  }
676
  .primary-btn:hover {
677
  transform: translateY(-2px) !important;
678
- box-shadow: 0 12px 24px rgba(102, 126, 234, 0.4) !important;
679
  }
680
  .stats-box {
681
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
@@ -694,24 +692,59 @@ css = """
694
  font-size: 14px;
695
  box-shadow: 0 2px 4px rgba(16, 185, 129, 0.3);
696
  }
 
 
 
 
 
 
 
 
 
 
 
697
  .header-gradient {
698
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
699
  -webkit-background-clip: text;
700
  -webkit-text-fill-color: transparent;
701
  background-clip: text;
702
  }
703
- </css>
704
-
705
- with gr.Blocks(theme=gr.themes.Soft(), css=css, title="Duality AI - Safety Detector") as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
706
 
707
  gr.Markdown("""
708
- <div style = "text-align: center; padding: 30px 20px; background: linear-gradient(135deg, #667eea15 0%, #764ba215 100%); border-radius: 15px; margin-bottom: 20px;" >
709
- <h1 style = "font-size: 2.5em; margin-bottom: 10px;" > πŸš€ Duality AI – Safety Object Detector < /h1 >
710
- <p style = "font-size: 1.2em; color: #555; margin: 10px 0;" >
711
- <span class = "accuracy-badge" > MAXIMUM ACCURACY MODE < /span > <br >
712
- <span style = "margin-top: 10px; display: inline-block;" > Advanced YOLOv8 with Enhanced NMS & False Positive Suppression < /span >
713
- </p >
714
- </div >
715
  """)
716
 
717
  with gr.Row():
@@ -740,8 +773,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css, title="Duality AI - Safety Detec
740
  )
741
 
742
  with gr.Accordion("πŸ”¬ Advanced Accuracy Boosters", open=True):
743
- gr.Markdown(
744
- "**Performance Enhancers** - Enable for maximum accuracy")
745
  with gr.Row():
746
  use_tta = gr.Checkbox(
747
  value=True,
@@ -795,8 +827,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css, title="Duality AI - Safety Detec
795
  file_types=["image"],
796
  height=120
797
  )
798
- gr.Markdown(
799
- "*πŸ’‘ Tip: Upload multiple images to process them all at once and download as ZIP*")
800
 
801
  # ===== RIGHT PANEL: RESULTS & OUTPUT =====
802
  with gr.Column(scale=3):
@@ -816,8 +847,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css, title="Duality AI - Safety Detec
816
 
817
  with gr.Accordion("πŸ“Š Detailed Detection Table", open=True):
818
  out_table = gr.Dataframe(
819
- headers=["Class", "Confidence",
820
- "Top-Left (x,y)", "Bottom-Right (x,y)", "Area (pxΒ²)"],
821
  label="All Detections Sorted by Confidence",
822
  row_count=10,
823
  wrap=True
@@ -836,164 +866,141 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css, title="Duality AI - Safety Detec
836
  # ===== TIPS & CONFIGURATION GUIDE =====
837
  with gr.Accordion("πŸ’‘ Configuration Guide - Get Best Results", open=False):
838
  gr.Markdown("""
839
- # 🎯 Recommended Settings by Use Case
840
 
841
- # πŸ† MAXIMUM ACCURACY (Best for Critical Applications)
842
  Perfect for: Safety inspections, compliance checks, detailed analysis
843
 
844
  | Parameter | Value | Why? |
845
- |----------- | ------- | ------|
846
  | Confidence | `0.35-0.45` | Filters out most false positives while keeping real objects |
847
  | IoU | `0.45-0.55` | Good balance for overlapping objects |
848
- | TTA | βœ… ** Enabled ** | +3-7 % accuracy through augmentation |
849
- | Ensemble | βœ… ** Enabled ** | +2-5 % accuracy through multi-scale detection |
850
- | Enhancement | βœ… ** Enabled ** | Improves detection on low-quality images |
851
  | Image Size | `800-1024px` | Better for small and distant objects |
852
 
853
- **Expected Performance: ** Best accuracy, ~5-10 seconds per image
854
 
855
  ---
856
 
857
- # ⚑ BALANCED MODE (Speed + Accuracy)
858
  Perfect for: General use, moderate batch processing
859
 
860
  | Parameter | Value | Why? |
861
- |----------- | ------- | ------|
862
  | Confidence | `0.30-0.40` | Good detection rate with acceptable false positives |
863
  | IoU | `0.45-0.50` | Standard NMS threshold |
864
- | TTA | βœ… ** Enabled ** | Worth the small speed cost |
865
- | Ensemble | ❌ ** Disabled ** | Too slow for marginal gains |
866
- | Enhancement | βœ… ** Enabled ** | Fast and helpful |
867
  | Image Size | `640px` | Fast and sufficient for most cases |
868
 
869
- **Expected Performance: ** Good accuracy, ~2-3 seconds per image
870
 
871
  ---
872
 
873
- # πŸš€ SPEED MODE (Real-time/Batch)
874
  Perfect for: Large batches, real-time monitoring, quick scans
875
 
876
  | Parameter | Value | Why? |
877
- |----------- | ------- | ------|
878
  | Confidence | `0.40-0.55` | Higher threshold = fewer detections but faster |
879
  | IoU | `0.50-0.60` | Standard NMS, less computation |
880
- | TTA | ❌ ** Disabled ** | Too slow for speed mode |
881
- | Ensemble | ❌ ** Disabled ** | Significantly slower |
882
- | Enhancement | ❌ ** Disabled ** | Save preprocessing time |
883
  | Image Size | `640px` | Fastest inference size |
884
 
885
- **Expected Performance: ** Fast, ~0.5-1 second per image
886
 
887
  ---
888
 
889
- # πŸ” Understanding Each Parameter
890
-
891
- # Confidence Threshold (0.05 - 0.95)
892
- - **What it does: ** Minimum probability score for a detection to be kept
893
- - **Lower(0.15-0.25): ** More detections, more false positives
894
- - **Higher(0.40-0.60): ** Fewer detections, fewer false positives
895
- - **Sweet spot: ** 0.30-0.40 for most use cases
896
-
897
- # IoU Threshold (0.10 - 0.95)
898
- - **What it does: ** Controls how much boxes can overlap before one is removed(Non-Maximum Suppression)
899
- - **Lower(0.30-0.40): ** More aggressive overlap removal, fewer boxes kept
900
- - **Higher(0.50-0.70): ** Keeps more overlapping boxes(good for crowded scenes)
901
- - **Sweet spot: ** 0.45-0.55 for most use cases
902
-
903
- # Test-Time Augmentation (TTA)
904
- - **What it does: ** Runs detection on multiple augmented versions of the image(flips, scales) and averages results
905
- - **Pros: ** +3-7 % mAP improvement, more robust to image variations
906
- - **Cons: ** 2-3x slower inference
907
- - **Use when: ** Accuracy is critical, small/hard-to-detect objects
908
-
909
- # Multi-Scale Ensemble
910
- - **What it does: ** Runs detection at multiple image sizes and merges predictions
911
- - **Pros: ** +2-5 % mAP, better for objects of varying sizes
912
- - **Cons: ** 2-4x slower inference
913
- - **Use when: ** Scene has both large and small objects, maximum accuracy needed
914
-
915
- # Image Enhancement
916
- - **What it does: ** Applies contrast, sharpness, and brightness adjustments before detection
917
- - **Pros: ** Improves detection on low-quality/dark images, minimal speed cost
918
- - **Cons: ** May hurt performance on already high-quality images
919
- - **Use when: ** Images are low-quality, poorly lit, or low contrast
920
-
921
- # Image Size
922
- - **What it does: ** Resizes input image before detection
923
- - **640px: ** Fast, good for large objects
924
- - **800px: ** Balanced, handles medium-small objects well
925
- - **1024px: ** Slower, best for small/distant objects
926
- - **1280px: ** Slowest, maximum detail preservation
927
 
928
- ---
 
 
 
 
929
 
930
- # πŸŽ“ Pro Tips for Best Results
931
-
932
- # 1. **Start Conservative, Then Adjust**
933
- Begin with confidence = 0.40, IoU = 0.50, then lower confidence if missing objects
934
-
935
- # 2. **Watch the Quality Indicators**
936
- - βœ… High Quality ( > 70 % avg confidence): Results are trustworthy
937
- - ⚠️ Medium Quality (50-70 %): Review results carefully
938
- - ❌ Low Quality (< 50%): Likely many false positives, adjust settings
939
-
940
- # 3. **False Positive Troubleshooting**
941
- If you see wrong detections:
942
- - βœ… Increase confidence threshold by 0.10-0.15
943
- - βœ… Increase IoU threshold to 0.55-0.60
944
- - βœ… Disable ensemble mode(can introduce noise)
945
- - βœ… Use higher image size for clearer features
946
-
947
- # 4. **Missing Object Troubleshooting**
948
- If objects aren't detected:
949
- - βœ… Lower confidence threshold to 0.20-0.25
950
- - βœ… Enable TTA and Ensemble
951
- - βœ… Enable image enhancement
952
- - βœ… Increase image size to 800-1024px
953
- - βœ… Check if object is in trained classes
954
-
955
- ### 5. **Image Quality Matters**
956
- - βœ… Good lighting and contrast dramatically improve detection
957
- - βœ… Avoid heavy JPEG compression, motion blur, and low resolution
958
- - βœ… Center important objects when possible
959
- - βœ… For small objects, use original high-resolution images
960
-
961
- ### 6. **Batch Processing Best Practices**
962
- - Use balanced/speed mode for large batches (50+ images)
963
- - Enable TTA only if accuracy is critical
964
- - Disable ensemble for batches over 100 images
965
- - Use 640px image size unless detecting small objects
966
-
967
- ---
968
-
969
- ## ⚠️ Common Issues & Solutions
970
-
971
- | Problem | Solution |
972
- |---------|----------|
973
- | Too many overlapping boxes on same object | Increase IoU threshold to 0.55-0.65 |
974
- | Multiple wrong classes detected | Increase confidence to 0.40+, disable ensemble |
975
- | Missing small objects | Use 1024px image size, enable TTA, lower confidence |
976
- | Slow inference | Disable TTA & ensemble, use 640px, increase confidence |
977
- | Low confidence warnings | Increase confidence threshold by 0.10-0.20 |
978
- | Objects at image edges not detected | Use lower confidence (0.20-0.30), enable TTA |
979
-
980
- ---
981
-
982
- ## πŸ“Š Expected Performance Metrics
983
-
984
- ### Processing Speed (approximate, on GPU)
985
- - **640px, no TTA/ensemble:** ~0.5-1 sec/image
986
- - **640px, TTA enabled:** ~1.5-2 sec/image
987
- - **800px, TTA + ensemble:** ~5-8 sec/image
988
- - **1024px, all enabled:** ~10-15 sec/image
989
-
990
- ### Accuracy Improvements
991
- - **Baseline (default settings):** 100% (reference)
992
- - **+ TTA:** +3-7% mAP
993
- - **+ Ensemble:** +2-5% mAP
994
- - **+ Image Enhancement:** +1-3% mAP (on low-quality images)
995
- - **+ All combined:** +8-15% mAP
996
-
 
 
 
 
 
 
 
 
 
 
997
  """)
998
 
999
  # ===== MODEL INFORMATION =====
@@ -1041,79 +1048,6 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css, title="Duality AI - Safety Detec
1041
  - Containment-based filtering (boxes inside other boxes)
1042
  - High-overlap cross-class suppression
1043
  - Confidence-based quality assessment
1044
-
1045
- βœ… **Enhanced Visualization**
1046
- - Adaptive box thickness based on confidence
1047
- - Corner markers for better visibility
1048
- - Color-coded class labels with shadows
1049
- - Confidence quality indicators
1050
-
1051
- ## πŸ“ˆ Performance Characteristics
1052
-
1053
- | Metric | Value |
1054
- |--------|-------|
1055
- | Base Inference Speed (640px) | ~30-50 FPS (GPU) / ~5-10 FPS (CPU) |
1056
- | With TTA | ~10-15 FPS (GPU) / ~2-3 FPS (CPU) |
1057
- | With TTA + Ensemble | ~3-5 FPS (GPU) / ~0.5-1 FPS (CPU) |
1058
- | Maximum Image Size | 1280px |
1059
- | Maximum Detections | 150 per image |
1060
- | Supported Formats | JPG, PNG, BMP, TIFF |
1061
-
1062
- ## πŸ”§ Technical Implementation
1063
-
1064
- **Framework:** Ultralytics YOLOv8 + PyTorch {torch.__version__}
1065
- **UI Framework:** Gradio {gr.__version__}
1066
- **Inference Optimizations:**
1067
- - Half-precision (FP16) on CUDA
1068
- - Agnostic NMS enabled
1069
- - Batch processing with ZIP compression
1070
- - Optimized image I/O with PIL
1071
-
1072
- """)
1073
-
1074
- # ===== ABOUT & CREDITS =====
1075
- with gr.Accordion("ℹ️ About & Credits", open=False):
1076
- gr.Markdown("""
1077
- ## πŸš€ Duality AI - Safety Object Detector
1078
-
1079
- **Version:** 2.0 (Enhanced)
1080
- **Last Updated:** November 2025
1081
-
1082
- ### 🎯 Purpose
1083
- This application provides state-of-the-art object detection for safety equipment identification.
1084
- It combines multiple advanced techniques to maximize detection accuracy while minimizing false positives.
1085
-
1086
- ### πŸ—οΈ Built With
1087
- - **YOLOv8** - Ultralytics' state-of-the-art object detection
1088
- - **PyTorch** - Deep learning framework
1089
- - **Gradio** - Interactive ML web interface
1090
- - **PIL/Pillow** - Image processing
1091
- - **NumPy** - Numerical computations
1092
-
1093
- ### πŸ“ Citation
1094
- If you use this tool in your research or work, please cite:
1095
- ```
1096
- @software{duality_ai_detector_2025,
1097
- title={Duality AI Safety Object Detector},
1098
- author={Duality AI Team},
1099
- year={2025},
1100
- version={2.0}
1101
- }
1102
- ```
1103
-
1104
- ### 🀝 Contributing
1105
- We welcome contributions! This is an open system designed to be improved by the community.
1106
-
1107
- ### πŸ“„ License
1108
- This software is provided as-is for safety and security applications.
1109
-
1110
- ### ⚠️ Disclaimer
1111
- This is an AI-powered tool and may not be 100% accurate. Always verify critical detections manually.
1112
- Not intended to replace professional safety inspections.
1113
-
1114
- ---
1115
-
1116
- **Made with ❀️ for safety and security**
1117
  """)
1118
 
1119
  # ===== EVENT BINDINGS =====
@@ -1156,7 +1090,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css, title="Duality AI - Safety Detec
1156
  gr.Markdown("""
1157
  **Try these configurations for common scenarios:**
1158
 
1159
- 1. **Single clear object (like your fire extinguisher):**
1160
  - Confidence: 0.40, IoU: 0.50, TTA: βœ…, Ensemble: ❌, Size: 640px
1161
 
1162
  2. **Multiple small objects:**
@@ -1169,13 +1103,33 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css, title="Duality AI - Safety Detec
1169
  - Confidence: 0.30, IoU: 0.50, TTA: βœ…, Enhancement: βœ…, Size: 800px
1170
  """)
1171
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1172
 
1173
  # ==========================================================
1174
  # LAUNCH APPLICATION
1175
  # ==========================================================
1176
  if __name__ == "__main__":
1177
  print("\n" + "="*60)
1178
- print("πŸš€ Starting Duality AI Safety Object Detector")
 
1179
  print("="*60)
1180
  print(f"πŸ“¦ Model: {MODEL_PATH}")
1181
  print(f"🏷️ Classes: {len(CLASS_NAMES)}")
 
291
 
292
  # Strategy 2: Multi-scale inference (ensemble mode)
293
  if use_ensemble:
294
+ scales = [img_size - 64, img_size + 64] if img_size >= 704 else [img_size]
 
295
  for scale in scales:
296
  results_scaled = model.predict(
297
  img,
 
421
  label_pos = "bottom"
422
 
423
  # Background rectangle with rounded appearance
424
+ bg_coords = [x1, label_y, x1 + text_w + padding * 2, label_y + text_h + padding * 2]
 
425
  d.rectangle(bg_coords, fill=color + (240,))
426
 
427
  # Add subtle border to label
 
655
 
656
 
657
  # ==========================================================
658
+ # GRADIO UI (PREMIUM DESIGN WITH TECHXNINJAS BRANDING)
659
  # ==========================================================
660
  css = """
661
  .gradio-container {
 
664
  margin: auto;
665
  }
666
  .primary-btn {
667
+ background: linear-gradient(135deg, #ff6b6b 0%, #ee5a6f 100%) !important;
668
  border: none !important;
669
  color: white !important;
670
  font-weight: 600 !important;
 
673
  }
674
  .primary-btn:hover {
675
  transform: translateY(-2px) !important;
676
+ box-shadow: 0 12px 24px rgba(255, 107, 107, 0.4) !important;
677
  }
678
  .stats-box {
679
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
 
692
  font-size: 14px;
693
  box-shadow: 0 2px 4px rgba(16, 185, 129, 0.3);
694
  }
695
+ .hackathon-badge {
696
+ display: inline-block;
697
+ background: linear-gradient(135deg, #ff6b6b 0%, #ee5a6f 100%);
698
+ color: white;
699
+ padding: 8px 20px;
700
+ border-radius: 25px;
701
+ font-weight: bold;
702
+ font-size: 16px;
703
+ margin: 10px 5px;
704
+ box-shadow: 0 4px 8px rgba(255, 107, 107, 0.3);
705
+ }
706
  .header-gradient {
707
+ background: linear-gradient(135deg, #ff6b6b 0%, #ee5a6f 100%);
708
  -webkit-background-clip: text;
709
  -webkit-text-fill-color: transparent;
710
  background-clip: text;
711
  }
712
+ .paranox-banner {
713
+ background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
714
+ color: white;
715
+ padding: 25px;
716
+ border-radius: 15px;
717
+ text-align: center;
718
+ margin-bottom: 20px;
719
+ box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
720
+ }
721
+ """
722
+
723
+ with gr.Blocks(theme=gr.themes.Soft(), css=css, title="TechXNinjas | PARANOX 2.0 - Safety Detector") as demo:
724
+
725
+ gr.HTML("""
726
+ <div class="paranox-banner">
727
+ <h1 style="font-size: 3em; margin: 0; font-weight: bold;">⚑ TechXNinjas</h1>
728
+ <div style="margin: 15px 0;">
729
+ <span class="hackathon-badge">PARANOX 2.0</span>
730
+ </div>
731
+ <p style="font-size: 1.3em; margin: 10px 0; opacity: 0.9;">
732
+ 24-Hour National Innovation Hackathon | 3-Month Journey: Build β†’ Pitch β†’ Prototype
733
+ </p>
734
+ <p style="font-size: 1em; margin: 5px 0; opacity: 0.7;">
735
+ πŸš€ Where Students Transform Ideas Into Reality
736
+ </p>
737
+ </div>
738
+ """)
739
 
740
  gr.Markdown("""
741
+ <div style="text-align: center; padding: 30px 20px; background: linear-gradient(135deg, #ff6b6b15 0%, #ee5a6f15 100%); border-radius: 15px; margin-bottom: 20px;">
742
+ <h1 style="font-size: 2.5em; margin-bottom: 10px;">πŸ›‘οΈ AI Safety Object Detector</h1>
743
+ <p style="font-size: 1.2em; color: #555; margin: 10px 0;">
744
+ <span class="accuracy-badge">MAXIMUM ACCURACY MODE</span><br>
745
+ <span style="margin-top: 10px; display: inline-block;">Advanced YOLOv8 with Enhanced NMS & False Positive Suppression</span>
746
+ </p>
747
+ </div>
748
  """)
749
 
750
  with gr.Row():
 
773
  )
774
 
775
  with gr.Accordion("πŸ”¬ Advanced Accuracy Boosters", open=True):
776
+ gr.Markdown("**Performance Enhancers** - Enable for maximum accuracy")
 
777
  with gr.Row():
778
  use_tta = gr.Checkbox(
779
  value=True,
 
827
  file_types=["image"],
828
  height=120
829
  )
830
+ gr.Markdown("*πŸ’‘ Tip: Upload multiple images to process them all at once and download as ZIP*")
 
831
 
832
  # ===== RIGHT PANEL: RESULTS & OUTPUT =====
833
  with gr.Column(scale=3):
 
847
 
848
  with gr.Accordion("πŸ“Š Detailed Detection Table", open=True):
849
  out_table = gr.Dataframe(
850
+ headers=["Class", "Confidence", "Top-Left (x,y)", "Bottom-Right (x,y)", "Area (pxΒ²)"],
 
851
  label="All Detections Sorted by Confidence",
852
  row_count=10,
853
  wrap=True
 
866
  # ===== TIPS & CONFIGURATION GUIDE =====
867
  with gr.Accordion("πŸ’‘ Configuration Guide - Get Best Results", open=False):
868
  gr.Markdown("""
869
+ ## 🎯 Recommended Settings by Use Case
870
 
871
+ ### πŸ† MAXIMUM ACCURACY (Best for Critical Applications)
872
  Perfect for: Safety inspections, compliance checks, detailed analysis
873
 
874
  | Parameter | Value | Why? |
875
+ |-----------|-------|------|
876
  | Confidence | `0.35-0.45` | Filters out most false positives while keeping real objects |
877
  | IoU | `0.45-0.55` | Good balance for overlapping objects |
878
+ | TTA | βœ… **Enabled** | +3-7% accuracy through augmentation |
879
+ | Ensemble | βœ… **Enabled** | +2-5% accuracy through multi-scale detection |
880
+ | Enhancement | βœ… **Enabled** | Improves detection on low-quality images |
881
  | Image Size | `800-1024px` | Better for small and distant objects |
882
 
883
+ **Expected Performance:** Best accuracy, ~5-10 seconds per image
884
 
885
  ---
886
 
887
+ ### ⚑ BALANCED MODE (Speed + Accuracy)
888
  Perfect for: General use, moderate batch processing
889
 
890
  | Parameter | Value | Why? |
891
+ |-----------|-------|------|
892
  | Confidence | `0.30-0.40` | Good detection rate with acceptable false positives |
893
  | IoU | `0.45-0.50` | Standard NMS threshold |
894
+ | TTA | βœ… **Enabled** | Worth the small speed cost |
895
+ | Ensemble | ❌ **Disabled** | Too slow for marginal gains |
896
+ | Enhancement | βœ… **Enabled** | Fast and helpful |
897
  | Image Size | `640px` | Fast and sufficient for most cases |
898
 
899
+ **Expected Performance:** Good accuracy, ~2-3 seconds per image
900
 
901
  ---
902
 
903
+ ### πŸš€ SPEED MODE (Real-time/Batch)
904
  Perfect for: Large batches, real-time monitoring, quick scans
905
 
906
  | Parameter | Value | Why? |
907
+ |-----------|-------|------|
908
  | Confidence | `0.40-0.55` | Higher threshold = fewer detections but faster |
909
  | IoU | `0.50-0.60` | Standard NMS, less computation |
910
+ | TTA | ❌ **Disabled** | Too slow for speed mode |
911
+ | Ensemble | ❌ **Disabled** | Significantly slower |
912
+ | Enhancement | ❌ **Disabled** | Save preprocessing time |
913
  | Image Size | `640px` | Fastest inference size |
914
 
915
+ **Expected Performance:** Fast, ~0.5-1 second per image
916
 
917
  ---
918
 
919
+ ## πŸ” Understanding Each Parameter
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
920
 
921
+ ### Confidence Threshold (0.05-0.95)
922
+ - **What it does:** Minimum probability score for a detection to be kept
923
+ - **Lower (0.15-0.25):** More detections, more false positives
924
+ - **Higher (0.40-0.60):** Fewer detections, fewer false positives
925
+ - **Sweet spot:** 0.30-0.40 for most use cases
926
 
927
+ ### IoU Threshold (0.10-0.95)
928
+ - **What it does:** Controls how much boxes can overlap before one is removed (Non-Maximum Suppression)
929
+ - **Lower (0.30-0.40):** More aggressive overlap removal, fewer boxes kept
930
+ - **Higher (0.50-0.70):** Keeps more overlapping boxes (good for crowded scenes)
931
+ - **Sweet spot:** 0.45-0.55 for most use cases
932
+ """)
933
+
934
+ # ===== HACKATHON INFO =====
935
+ with gr.Accordion("πŸ† About PARANOX 2.0 - TechXNinjas", open=True):
936
+ gr.HTML("""
937
+ <div style="padding: 20px; background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%); border-radius: 15px; color: white;">
938
+ <h2 style="color: #ff6b6b; margin-top: 0;">⚑ PARANOX 2.0 - National Innovation Hackathon</h2>
939
+
940
+ <div style="margin: 20px 0;">
941
+ <h3 style="color: #ffd93d;">🎯 What is PARANOX 2.0?</h3>
942
+ <p style="font-size: 1.1em; line-height: 1.6;">
943
+ A <strong>24-hour national-level innovation hackathon</strong> where students transform their ideas into
944
+ working prototypes. This isn't just a competitionβ€”it's a <strong>3-month journey</strong> of building,
945
+ learning, and growing alongside India's brightest minds.
946
+ </p>
947
+ </div>
948
+
949
+ <div style="margin: 20px 0;">
950
+ <h3 style="color: #ffd93d;">πŸš€ The Journey</h3>
951
+ <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 15px; margin-top: 15px;">
952
+ <div style="background: rgba(255, 107, 107, 0.2); padding: 15px; border-radius: 10px; border-left: 4px solid #ff6b6b;">
953
+ <h4 style="margin: 0 0 10px 0; color: #ff6b6b;">πŸ“ Month 1: Build</h4>
954
+ <p style="margin: 0;">Ideate, design, and develop your innovative solution with mentor guidance</p>
955
+ </div>
956
+ <div style="background: rgba(255, 211, 61, 0.2); padding: 15px; border-radius: 10px; border-left: 4px solid #ffd93d;">
957
+ <h4 style="margin: 0 0 10px 0; color: #ffd93d;">🎀 Month 2: Pitch</h4>
958
+ <p style="margin: 0;">Present your prototype to industry experts and refine based on feedback</p>
959
+ </div>
960
+ <div style="background: rgba(16, 185, 129, 0.2); padding: 15px; border-radius: 10px; border-left: 4px solid #10b981;">
961
+ <h4 style="margin: 0 0 10px 0; color: #10b981;">πŸ—οΈ Month 3: Prototype</h4>
962
+ <p style="margin: 0;">Polish your working prototype and compete in the 24-hour grand finale</p>
963
+ </div>
964
+ </div>
965
+ </div>
966
+
967
+ <div style="margin: 20px 0;">
968
+ <h3 style="color: #ffd93d;">✨ Why PARANOX 2.0?</h3>
969
+ <ul style="font-size: 1.05em; line-height: 1.8;">
970
+ <li>πŸŽ“ <strong>Learn by Doing:</strong> Real-world problem solving with cutting-edge technologies</li>
971
+ <li>🀝 <strong>Network:</strong> Connect with 100+ students, mentors, and industry professionals</li>
972
+ <li>πŸ† <strong>Compete:</strong> Showcase your skills at a national level</li>
973
+ <li>πŸ’‘ <strong>Innovate:</strong> Turn your ideas into tangible products</li>
974
+ <li>🎁 <strong>Win:</strong> Exciting prizes, internships, and recognition</li>
975
+ <li>πŸ“ˆ <strong>Grow:</strong> 3 months of continuous learning and improvement</li>
976
+ </ul>
977
+ </div>
978
+
979
+ <div style="margin: 20px 0;">
980
+ <h3 style="color: #ffd93d;">🎯 This Project</h3>
981
+ <p style="font-size: 1.1em; line-height: 1.6;">
982
+ This <strong>AI Safety Object Detector</strong> was built as part of PARANOX 2.0, demonstrating
983
+ how AI can solve real-world safety challenges. Using advanced YOLOv8 detection with enhanced
984
+ accuracy techniques, it identifies safety equipment in images with industry-grade precision.
985
+ </p>
986
+ </div>
987
+
988
+ <div style="text-align: center; margin-top: 30px; padding-top: 20px; border-top: 2px solid rgba(255, 255, 255, 0.2);">
989
+ <h3 style="color: #ff6b6b; font-size: 1.8em; margin-bottom: 10px;">⚑ TechXNinjas</h3>
990
+ <p style="font-size: 1.2em; opacity: 0.9;">Empowering Student Innovation | Building Tomorrow's Solutions Today</p>
991
+ <div style="margin-top: 15px;">
992
+ <span style="background: #ff6b6b; padding: 10px 25px; border-radius: 25px; margin: 0 10px; display: inline-block;">
993
+ #PARANOX2024
994
+ </span>
995
+ <span style="background: #ffd93d; color: #1a1a2e; padding: 10px 25px; border-radius: 25px; margin: 0 10px; display: inline-block;">
996
+ #TechXNinjas
997
+ </span>
998
+ <span style="background: #10b981; padding: 10px 25px; border-radius: 25px; margin: 0 10px; display: inline-block;">
999
+ #InnovateToElevate
1000
+ </span>
1001
+ </div>
1002
+ </div>
1003
+ </div>
1004
  """)
1005
 
1006
  # ===== MODEL INFORMATION =====
 
1048
  - Containment-based filtering (boxes inside other boxes)
1049
  - High-overlap cross-class suppression
1050
  - Confidence-based quality assessment
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1051
  """)
1052
 
1053
  # ===== EVENT BINDINGS =====
 
1090
  gr.Markdown("""
1091
  **Try these configurations for common scenarios:**
1092
 
1093
+ 1. **Single clear object (like fire extinguisher):**
1094
  - Confidence: 0.40, IoU: 0.50, TTA: βœ…, Ensemble: ❌, Size: 640px
1095
 
1096
  2. **Multiple small objects:**
 
1103
  - Confidence: 0.30, IoU: 0.50, TTA: βœ…, Enhancement: βœ…, Size: 800px
1104
  """)
1105
 
1106
+ # ===== FOOTER =====
1107
+ gr.HTML("""
1108
+ <div style="text-align: center; padding: 30px 20px; margin-top: 40px; background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%); border-radius: 15px; color: white;">
1109
+ <h3 style="color: #ff6b6b; margin-bottom: 15px;">πŸš€ Built with Innovation & Passion</h3>
1110
+ <p style="font-size: 1.1em; margin: 10px 0;">
1111
+ Powered by <strong>TechXNinjas</strong> | PARANOX 2.0 Hackathon Project
1112
+ </p>
1113
+ <p style="opacity: 0.8; margin: 10px 0;">
1114
+ 24-Hour National Hackathon β€’ 3-Month Innovation Journey β€’ Student-Led Excellence
1115
+ </p>
1116
+ <div style="margin-top: 20px; padding-top: 20px; border-top: 1px solid rgba(255,255,255,0.2);">
1117
+ <p style="opacity: 0.7; font-size: 0.9em;">
1118
+ ⚠️ AI-Powered Tool β€’ Always verify critical detections manually<br>
1119
+ Made with ❀️ for safety and security applications
1120
+ </p>
1121
+ </div>
1122
+ </div>
1123
+ """)
1124
+
1125
 
1126
  # ==========================================================
1127
  # LAUNCH APPLICATION
1128
  # ==========================================================
1129
  if __name__ == "__main__":
1130
  print("\n" + "="*60)
1131
+ print("⚑ TechXNinjas - PARANOX 2.0")
1132
+ print("πŸš€ Starting AI Safety Object Detector")
1133
  print("="*60)
1134
  print(f"πŸ“¦ Model: {MODEL_PATH}")
1135
  print(f"🏷️ Classes: {len(CLASS_NAMES)}")