Skip to content

Latest commit

 

History

History
216 lines (164 loc) · 5.46 KB

File metadata and controls

216 lines (164 loc) · 5.46 KB

✅ Model Integration Complete - Quick Reference

Your YOLOv8 Batik Detection Model

Model Specs

  • Input: float32[1, 640, 640, 3] - RGB image normalized to [0,1]
  • Output 0: float32[1, 38, 8400] - Detections (x, y, w, h + class scores)
  • Output 1: float32[1, 160, 160, 32] - Feature map (not used)
  • Classes: megamendung (0), parang (1)
  • Preprocessing: Letterbox resize to 640x640 with black background

✅ What's Been Configured

1. TFLite Service (tflite_service.dart)

  • ✅ Input size: 640x640
  • ✅ YOLOv8 output parsing
  • ✅ Letterbox preprocessing with black background
  • ✅ NMS (Non-Maximum Suppression)
  • ✅ Confidence filtering

2. Labels File (labels.txt)

megamendung
parang

3. Detection Parameters

  • Confidence threshold: 0.5 (50%)
  • NMS IoU threshold: 0.45
  • Max detections: 100
  • Predictions processed: 8400

🚀 Final Setup Steps

Step 1: Place Your Model

lib/assets/models/model.tflite    ← Put your model.tflite here

Step 2: Run the App

flutter run

Step 3: Test Detection

Point your camera at batik patterns with:

  • Megamendung motifs
  • Parang motifs

You should see:

  • ✅ Green bounding boxes
  • ✅ Label text ("megamendung" or "parang")
  • ✅ Confidence percentage

🎯 Detection Configuration

Current Settings (in tflite_service.dart)

Line 23: static const int inputSize = 640;
Line 24: static const int numResults = 100;
Line 25: static const double threshold = 0.5;
Line 26: static const int numPredictions = 8400;

YOLOv8 Output Parsing (Line 237+)

// Bounding box from indices 0-3
xCenter = output[0][0][i]
yCenter = output[0][1][i]
width = output[0][2][i]
height = output[0][3][i]

// Class scores from indices 4-5
class0 (megamendung) = output[0][4][i]
class1 (parang) = output[0][5][i]

🔧 Quick Adjustments

More/Fewer Detections

// tflite_service.dart, line 25
static const double threshold = 0.5;

// Lower = more detections (but more false positives)
static const double threshold = 0.3;

// Higher = fewer detections (but more accurate)
static const double threshold = 0.7;

Overlapping Boxes

// tflite_service.dart, line 272
List<Recognition> _applyNMS(..., {double iouThreshold = 0.45})

// Lower = fewer overlaps (might remove valid boxes)
{double iouThreshold = 0.3}

// Higher = more overlaps (might show duplicates)
{double iouThreshold = 0.6}

📊 Expected Performance

On Real Device:

  • Inference: 50-150ms per frame
  • FPS: 7-20 frames per second
  • Memory: +100-200MB

On Emulator:

  • Much slower, test on real device!

🐛 Troubleshooting

No Detections?

  1. Lower threshold to 0.3
  2. Check model file location: lib/assets/models/model.tflite
  3. Verify labels.txt has exactly 2 lines
  4. Check Flutter logs: flutter logs

Wrong Positions?

Your model outputs normalized coordinates (0-1). If boxes are in wrong places:

  • Check if your model outputs pixel coordinates instead
  • May need to divide by 640 in parsing code

App Crashes?

  1. Verify output shapes: [1, 38, 8400] and [1, 160, 160, 32]
  2. Check model is float32 format
  3. Run: flutter clean && flutter pub get

Slow Performance?

  1. Test on physical device (not emulator)
  2. Lower max results: numResults = 50
  3. Add delay between frames in lens_screen.dart

📁 File Locations

lib/assets/models/
├── model.tflite          ← Your model goes here
├── labels.txt            ← Already configured ✅
├── README.md            ← General TFLite guide
└── MODEL_CONFIG.md      ← Your model specifics

lib/features/lens/services/
└── tflite_service.dart  ← Configured for YOLOv8 ✅

🎨 UI Elements

Bounding Box Colors (bounding_box_painter.dart)

  • Box: Green, 3px stroke
  • Label: Green background, white text
  • Text: Bold, 14px

Detection Info Displayed

  • Pattern name (megamendung/parang)
  • Confidence as percentage
  • Bounding box around detected area

⚡ Quick Test Checklist

  • Model file at lib/assets/models/model.tflite
  • Labels file has exactly 2 lines (megamendung, parang)
  • Run flutter pub get (if haven't already)
  • Run flutter run
  • Point camera at batik pattern
  • See green bounding boxes appear
  • Labels show correct pattern names

🔍 Debugging Tips

Enable Debug Logs

In tflite_service.dart, line 45-47:

print('TFLite model initialized successfully');
print('Input shape: ${_interpreter!.getInputTensors()}');
print('Output shape: ${_interpreter!.getOutputTensors()}');

Check these match:

  • Input: [1, 640, 640, 3]
  • Output 0: [1, 38, 8400]
  • Output 1: [1, 160, 160, 32]

Check Detection Count

Add after line 272 in _parseYOLOv8Results():

print('Found ${recognitions.length} detections before NMS');
recognitions = _applyNMS(recognitions);
print('Found ${recognitions.length} detections after NMS');

📚 Documentation

  • General Setup: README.md in models folder
  • Your Model Details: MODEL_CONFIG.md in models folder
  • Implementation Summary: IMPLEMENTATION_SUMMARY.md in root
  • Quick Start: QUICK_START.md in root

✨ You're All Set!

Your app is configured for your specific YOLOv8 model:

  • ✅ Input: 640x640 with letterbox and black background
  • ✅ Output: [1, 38, 8400] YOLOv8 format
  • ✅ Labels: megamendung and parang
  • ✅ Detection with NMS and confidence filtering

Just add your model.tflite file and run! 🚀