Spaces:
Sleeping
Sleeping
fix bug
Browse files
model.py
CHANGED
|
@@ -51,7 +51,54 @@ class TrafficSignDetector:
|
|
| 51 |
|
| 52 |
self.thickness = config['inference']['thickness']
|
| 53 |
self.classes = config['classes']
|
|
|
|
|
|
|
|
|
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
def _ensure_square(self, image, target_size=640):
|
| 56 |
"""
|
| 57 |
Adjust image to square while maintaining aspect ratio.
|
|
|
|
| 51 |
|
| 52 |
self.thickness = config['inference']['thickness']
|
| 53 |
self.classes = config['classes']
|
| 54 |
+
|
| 55 |
+
# Print model information
|
| 56 |
+
self._print_model_info()
|
| 57 |
|
| 58 |
+
def _print_model_info(self):
|
| 59 |
+
"""
|
| 60 |
+
Print detailed information about the loaded model.
|
| 61 |
+
"""
|
| 62 |
+
print("\n" + "="*80)
|
| 63 |
+
print("MODEL INFORMATION")
|
| 64 |
+
print("="*80)
|
| 65 |
+
|
| 66 |
+
# Basic model info
|
| 67 |
+
print(f"Model type: {type(self.model)}")
|
| 68 |
+
print(f"Model device: {self.model.device}")
|
| 69 |
+
print(f"Confidence threshold: {self.conf_threshold}")
|
| 70 |
+
print(f"Number of classes: {len(self.classes)}")
|
| 71 |
+
|
| 72 |
+
# Model architecture
|
| 73 |
+
try:
|
| 74 |
+
print(f"\nModel architecture:")
|
| 75 |
+
print(f" - Task: {self.model.task if hasattr(self.model, 'task') else 'Unknown'}")
|
| 76 |
+
print(f" - Model type: {self.model.model.__class__.__name__ if hasattr(self.model, 'model') else 'Unknown'}")
|
| 77 |
+
|
| 78 |
+
# Model parameters
|
| 79 |
+
if hasattr(self.model, 'model') and hasattr(self.model.model, 'parameters'):
|
| 80 |
+
total_params = sum(p.numel() for p in self.model.model.parameters())
|
| 81 |
+
trainable_params = sum(p.numel() for p in self.model.model.parameters() if p.requires_grad)
|
| 82 |
+
print(f" - Total parameters: {total_params:,}")
|
| 83 |
+
print(f" - Trainable parameters: {trainable_params:,}")
|
| 84 |
+
except Exception as e:
|
| 85 |
+
print(f" - Could not retrieve architecture details: {e}")
|
| 86 |
+
|
| 87 |
+
# Class information
|
| 88 |
+
print(f"\nClasses ({len(self.classes)} total):")
|
| 89 |
+
for i, cls in enumerate(self.classes):
|
| 90 |
+
print(f" {i}: {cls}")
|
| 91 |
+
|
| 92 |
+
# Try to get model summary
|
| 93 |
+
try:
|
| 94 |
+
if hasattr(self.model, 'info'):
|
| 95 |
+
print(f"\nModel summary:")
|
| 96 |
+
self.model.info()
|
| 97 |
+
except Exception as e:
|
| 98 |
+
print(f"Could not get model summary: {e}")
|
| 99 |
+
|
| 100 |
+
print("="*80 + "\n")
|
| 101 |
+
|
| 102 |
def _ensure_square(self, image, target_size=640):
|
| 103 |
"""
|
| 104 |
Adjust image to square while maintaining aspect ratio.
|