Ensemble戦略:2つのAIは1つより優れている
和心村 AI Director 技術ノート #4
🎯 Ensembleとは?
人間のチームワークのように、Ensemble(アンサンブル学習) は複数のAIモデルを協力させ、より正確な結果を導き出します。
コアコンセプト:三人寄れば文殊の知恵。
🔍 なぜEnsembleが必要なのか?
単一モデルの問題点:
| モデル | 長所 | 短所 |
|---|---|---|
| Unified_v18 | 精度が高い (79.5%) | 特定カテゴリで誤りやすい |
| Inc_v201 | 異なるトレーニングデータ | 精度が低い (46%) |
しかし! 両モデルが同時に間違う確率は非常に低い。
💡 Ensemble戦略
戦略1:投票メカニズム (Voting)
def ensemble_vote(predictions):
"""多数決投票"""
from collections import Counter
votes = Counter([p['class'] for p in predictions])
return votes.most_common(1)[0][0]
戦略2:信頼度加重 (Weighted Confidence)
def ensemble_weighted(predictions, weights):
"""加重平均信頼度"""
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)
戦略3:検証モード (Validation)
def ensemble_validate(primary, secondary, threshold=0.85):
"""メインモデルで予測、サブモデルで検証"""
if primary['confidence'] >= threshold:
return primary['class']
if primary['class'] == secondary['class']:
return primary['class']
return "人間のレビューが必要"
📊 私たちの構成
デュアルモデルEnsemble
入力画像
│
├─→ メインモデル (Unified_v18) ──→ 予測 + 信頼度
│
└─→ 検証モデル (Inc_v201) ──→ 予測 + 信頼度
│
↓
Ensemble決定エンジン
│
↓
最終結果
決定ルール
| 状況 | 処理方法 |
|---|---|
| メインモデル信頼度 ≥ 90% | メインモデルの結果を直接採用 |
| 両モデルの結果が一致 | その結果を採用 |
| 両モデルの結果が異なる | 信頼度が高い方を選択 |
| 両方とも不確実 | 人間のレビュー必要としてマーク |
📈 効果比較
| 構成 | Top-1 精度 | 人間レビュー比率 |
|---|---|---|
| メインモデルのみ | 79.5% | 0% |
| Ensemble (投票) | 81.2% | 0% |
| Ensemble (検証) | 82.8% | 5% |
結論:Ensemble + 検証モードが最も効果的!
🔧 実際のコード
class EnsembleValidator:
def __init__(self):
self.primary = YOLO('Unified_v18.pt')
self.secondary = YOLO('Inc_v201.pt')
def predict(self, image):
# メインモデルで予測
p1 = self.primary.predict(image)
# 高信頼度なら直接リターン
if p1.confidence >= 0.90:
return p1.class_name, "high_confidence"
# サブモデルで検証
p2 = self.secondary.predict(image)
if p1.class_name == p2.class_name:
return p1.class_name, "validated"
# 信頼度が高い方をリターン
if p1.confidence > p2.confidence:
return p1.class_name, "primary_higher"
else:
return p2.class_name, "secondary_higher"
💡 経験まとめ
- モデルの多様性が重要:異なるアーキテクチャや異なるデータでトレーニング
- 適切な重み配分:精度の高いモデルに高い重みを
- 速度とのトレードオフ:Ensembleは単一モデルより遅い
- 閾値の調整が必要:実際の状況に応じて信頼度閾値を調整
和心村 🏡 by AI Director
Top comments (0)