Spaces:
Sleeping
Sleeping
fix bug
Browse files- check_model.py +59 -0
- config.yaml +1 -1
check_model.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Script to verify if the model has been trained with actual weights.
|
| 4 |
+
"""
|
| 5 |
+
import torch
|
| 6 |
+
from ultralytics import YOLO
|
| 7 |
+
from huggingface_hub import hf_hub_download
|
| 8 |
+
|
| 9 |
+
# Download model
|
| 10 |
+
repo_id = 'VietCat/GTSRB-Model'
|
| 11 |
+
file_path = 'models/GTSRB.pt'
|
| 12 |
+
local_model_path = hf_hub_download(repo_id=repo_id, filename=file_path)
|
| 13 |
+
|
| 14 |
+
print(f"Model path: {local_model_path}\n")
|
| 15 |
+
|
| 16 |
+
# Load model
|
| 17 |
+
model = YOLO(local_model_path)
|
| 18 |
+
|
| 19 |
+
print("="*80)
|
| 20 |
+
print("MODEL WEIGHTS ANALYSIS")
|
| 21 |
+
print("="*80)
|
| 22 |
+
|
| 23 |
+
# Check model layers and weights
|
| 24 |
+
print("\nChecking model weights...")
|
| 25 |
+
total_params = 0
|
| 26 |
+
zero_params = 0
|
| 27 |
+
trained_params = 0
|
| 28 |
+
|
| 29 |
+
for name, param in model.model.named_parameters():
|
| 30 |
+
param_count = param.numel()
|
| 31 |
+
total_params += param_count
|
| 32 |
+
|
| 33 |
+
# Check if weights are mostly zeros or random initialization
|
| 34 |
+
if torch.allclose(param, torch.zeros_like(param), atol=1e-6):
|
| 35 |
+
zero_params += param_count
|
| 36 |
+
status = "ZERO"
|
| 37 |
+
elif param.mean().item() != 0:
|
| 38 |
+
trained_params += param_count
|
| 39 |
+
status = "TRAINED"
|
| 40 |
+
else:
|
| 41 |
+
status = "RANDOM"
|
| 42 |
+
|
| 43 |
+
if param_count > 1000: # Only print large layers
|
| 44 |
+
print(f"{name:50s} | {param_count:10,} params | {status:10s} | mean: {param.mean().item():.6f}, std: {param.std().item():.6f}")
|
| 45 |
+
|
| 46 |
+
print(f"\n{'='*80}")
|
| 47 |
+
print(f"Total parameters: {total_params:,}")
|
| 48 |
+
print(f"Zero parameters: {zero_params:,} ({100*zero_params/total_params:.1f}%)")
|
| 49 |
+
print(f"Trained parameters: {trained_params:,} ({100*trained_params/total_params:.1f}%)")
|
| 50 |
+
|
| 51 |
+
# Check if this looks like trained weights
|
| 52 |
+
if zero_params / total_params > 0.5:
|
| 53 |
+
print("\n⚠️ WARNING: Model has >50% zero parameters - may not be properly trained!")
|
| 54 |
+
elif trained_params / total_params > 0.7:
|
| 55 |
+
print("\n✅ Model appears to be properly trained")
|
| 56 |
+
else:
|
| 57 |
+
print("\n❓ Uncertain - model may need verification")
|
| 58 |
+
|
| 59 |
+
print("="*80)
|
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.1 # Minimum confidence for detections
|
| 4 |
|
| 5 |
inference:
|
| 6 |
box_color: (128, 0, 128) # Purple color for bounding boxes (BGR format)
|