Ensemble Strategy: Two AIs Are Better Than One
Washin Village AI Director Tech Notes #4
๐ฏ What is Ensemble?
Just like human teamwork, Ensemble Learning makes multiple AI models work together, combining their judgments for more accurate results.
Core concept: Two heads are better than one.
๐ Why Do We Need Ensemble?
Single model limitations:
| Model | Pros | Cons |
|---|---|---|
| Unified_v18 | High accuracy (79.5%) | Prone to errors on certain categories |
| Inc_v201 | Different training data | Lower accuracy (46%) |
However! The probability of both models making the same mistake is very low.
๐ก Ensemble Strategies
Strategy 1: Voting Mechanism
def ensemble_vote(predictions):
"""Majority voting"""
from collections import Counter
votes = Counter([p['class'] for p in predictions])
return votes.most_common(1)[0][0]
Strategy 2: Weighted Confidence
def ensemble_weighted(predictions, weights):
"""Weighted average confidence"""
combined = {}
for pred, weight in zip(predictions, weights):
for cls, conf in pred.items():
combined[cls] = combined.get(cls, 0) + conf * weight
return max(combined, key=combined.get)
Strategy 3: Validation Mode
def ensemble_validate(primary, secondary, threshold=0.85):
"""Primary model predicts, secondary validates"""
if primary['confidence'] >= threshold:
return primary['class']
if primary['class'] == secondary['class']:
return primary['class']
return "needs_human_review"
๐ Our Configuration
Dual-Model Ensemble
Input Image
โ
โโโ Primary Model (Unified_v18) โโโ Prediction + Confidence
โ
โโโ Validation Model (Inc_v201) โโโ Prediction + Confidence
โ
โ
Ensemble Decision Engine
โ
โ
Final Result
Decision Rules
| Scenario | Action |
|---|---|
| Primary confidence โฅ 90% | Use primary result directly |
| Both models agree | Use that result |
| Models disagree | Choose higher confidence |
| Both uncertain | Mark for human review |
๐ Performance Comparison
| Configuration | Top-1 Accuracy | Human Review Rate |
|---|---|---|
| Primary only | 79.5% | 0% |
| Ensemble (voting) | 81.2% | 0% |
| Ensemble (validation) | 82.8% | 5% |
Conclusion: Ensemble + validation mode works best!
๐ง Actual Code
class EnsembleValidator:
def __init__(self):
self.primary = YOLO('Unified_v18.pt')
self.secondary = YOLO('Inc_v201.pt')
def predict(self, image):
# Primary model prediction
p1 = self.primary.predict(image)
# High confidence: return directly
if p1.confidence >= 0.90:
return p1.class_name, "high_confidence"
# Secondary model validation
p2 = self.secondary.predict(image)
if p1.class_name == p2.class_name:
return p1.class_name, "validated"
# Return higher confidence
if p1.confidence > p2.confidence:
return p1.class_name, "primary_higher"
else:
return p2.class_name, "secondary_higher"
๐ก Lessons Learned
- Model diversity matters: Use different architectures or training data
- Weight allocation: Higher accuracy models get higher weights
- Speed tradeoffs: Ensemble is slower than single model
- Threshold tuning: Adjust confidence thresholds based on actual needs
Washin Village ๐ก by AI Director
Top comments (0)