Spaces:
Sleeping
Sleeping
Lower confidence threshold to 0.001 and add detailed confidence analysis
Browse files- config.yaml +1 -1
- model.py +31 -11
config.yaml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
model:
|
| 2 |
path: 'VietCat/GTSRB-Model/models/GTSRB.pt' # Path to the YOLO model on Hugging Face Hub (will be downloaded automatically)
|
| 3 |
-
confidence_threshold: 0.
|
| 4 |
|
| 5 |
inference:
|
| 6 |
box_color: (128, 0, 128) # Purple color for bounding boxes (BGR format)
|
|
|
|
| 1 |
model:
|
| 2 |
path: 'VietCat/GTSRB-Model/models/GTSRB.pt' # Path to the YOLO model on Hugging Face Hub (will be downloaded automatically)
|
| 3 |
+
confidence_threshold: 0.001 # Minimum confidence for detections (very low for testing)
|
| 4 |
|
| 5 |
inference:
|
| 6 |
box_color: (128, 0, 128) # Purple color for bounding boxes (BGR format)
|
model.py
CHANGED
|
@@ -196,10 +196,16 @@ class TrafficSignDetector:
|
|
| 196 |
|
| 197 |
# Run with conf=0.0 to get raw predictions (before filtering)
|
| 198 |
results_raw = self.model(image, conf=0.0, imgsz=640, iou=0.45)
|
| 199 |
-
|
|
|
|
|
|
|
| 200 |
if results_raw and len(results_raw[0].boxes) > 0:
|
| 201 |
-
|
| 202 |
-
print(f" - Top 5 raw confidences: {[f'{c:.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
|
| 204 |
# Now run with actual threshold
|
| 205 |
results = self.model(image, conf=self.conf_threshold, imgsz=640, iou=0.45)
|
|
@@ -256,15 +262,29 @@ class TrafficSignDetector:
|
|
| 256 |
print(f"{'='*80}")
|
| 257 |
|
| 258 |
# Analysis and recommendations
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 259 |
if scale < 0.5:
|
| 260 |
-
print(f"\n
|
| 261 |
-
print(f"
|
| 262 |
-
print(f"
|
| 263 |
-
print(f"
|
| 264 |
-
print(f" b) Use multi-scale detection (detect multiple regions)")
|
| 265 |
-
print(f" c) Reduce input image size to avoid extreme scaling")
|
| 266 |
-
print(f" d) Check if model was trained with your image dimensions")
|
| 267 |
-
print(f" 3. Current: {original_image.shape} → {image.shape} (scale {scale:.2f})")
|
| 268 |
|
| 269 |
print()
|
| 270 |
return original_image, preprocessed_display
|
|
|
|
| 196 |
|
| 197 |
# Run with conf=0.0 to get raw predictions (before filtering)
|
| 198 |
results_raw = self.model(image, conf=0.0, imgsz=640, iou=0.45)
|
| 199 |
+
raw_box_count = len(results_raw[0].boxes) if results_raw else 0
|
| 200 |
+
print(f" - Raw detections (conf=0.0): {raw_box_count}")
|
| 201 |
+
|
| 202 |
if results_raw and len(results_raw[0].boxes) > 0:
|
| 203 |
+
all_raw_confs = [float(box.conf[0]) for box in results_raw[0].boxes]
|
| 204 |
+
print(f" - Top 5 raw confidences: {[f'{c:.6f}' for c in sorted(all_raw_confs, reverse=True)[:5]]}")
|
| 205 |
+
print(f" - Confidence stats: min={min(all_raw_confs):.6f}, max={max(all_raw_confs):.6f}, mean={np.mean(all_raw_confs):.6f}")
|
| 206 |
+
print(f" - Confidences > 0.01: {sum(1 for c in all_raw_confs if c > 0.01)}")
|
| 207 |
+
print(f" - Confidences > 0.001: {sum(1 for c in all_raw_confs if c > 0.001)}")
|
| 208 |
+
print(f" - Confidences > 0.0001: {sum(1 for c in all_raw_confs if c > 0.0001)}")
|
| 209 |
|
| 210 |
# Now run with actual threshold
|
| 211 |
results = self.model(image, conf=self.conf_threshold, imgsz=640, iou=0.45)
|
|
|
|
| 262 |
print(f"{'='*80}")
|
| 263 |
|
| 264 |
# Analysis and recommendations
|
| 265 |
+
print(f"\n📋 ANALYSIS & RECOMMENDATIONS:")
|
| 266 |
+
|
| 267 |
+
# Check for raw detections issue
|
| 268 |
+
if raw_box_count > 0 and max([float(box.conf[0]) for box in results_raw[0].boxes]) < 0.01:
|
| 269 |
+
print(f" ⚠️ MODEL CONFIDENCE ISSUE:")
|
| 270 |
+
print(f" - Model detects {raw_box_count} objects but all with confidence < 0.01")
|
| 271 |
+
print(f" - This indicates the model may not be well-trained for this domain")
|
| 272 |
+
print(f" - Possible causes:")
|
| 273 |
+
print(f" a) Model trained on different dataset/resolution")
|
| 274 |
+
print(f" b) Model underfitted (needs more training epochs)")
|
| 275 |
+
print(f" c) Training data does not match inference data")
|
| 276 |
+
print(f" d) Model weights not properly saved")
|
| 277 |
+
print(f" - Solutions:")
|
| 278 |
+
print(f" 1) Retrain model with proper hyperparameters (100+ epochs)")
|
| 279 |
+
print(f" 2) Use augmentation during training")
|
| 280 |
+
print(f" 3) Check training/validation accuracy was good")
|
| 281 |
+
print(f" 4) Ensure training data matches inference image types")
|
| 282 |
+
|
| 283 |
if scale < 0.5:
|
| 284 |
+
print(f"\n ⚠️ SCALING ISSUE:")
|
| 285 |
+
print(f" - Objects too small after resizing (scale={scale:.2f})")
|
| 286 |
+
print(f" - Current: {original_image.shape} → {image.shape}")
|
| 287 |
+
print(f" - Solutions: use larger imgsz (1024/1280) or smaller input images")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 288 |
|
| 289 |
print()
|
| 290 |
return original_image, preprocessed_display
|