- 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
- ✅ Input size: 640x640
- ✅ YOLOv8 output parsing
- ✅ Letterbox preprocessing with black background
- ✅ NMS (Non-Maximum Suppression)
- ✅ Confidence filtering
megamendung
parang
- Confidence threshold: 0.5 (50%)
- NMS IoU threshold: 0.45
- Max detections: 100
- Predictions processed: 8400
lib/assets/models/model.tflite ← Put your model.tflite here
flutter runPoint your camera at batik patterns with:
- Megamendung motifs
- Parang motifs
You should see:
- ✅ Green bounding boxes
- ✅ Label text ("megamendung" or "parang")
- ✅ Confidence percentage
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;// 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]// 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;// 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}- Inference: 50-150ms per frame
- FPS: 7-20 frames per second
- Memory: +100-200MB
- Much slower, test on real device!
- Lower threshold to 0.3
- Check model file location:
lib/assets/models/model.tflite - Verify labels.txt has exactly 2 lines
- Check Flutter logs:
flutter logs
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
- Verify output shapes:
[1, 38, 8400]and[1, 160, 160, 32] - Check model is float32 format
- Run:
flutter clean && flutter pub get
- Test on physical device (not emulator)
- Lower max results:
numResults = 50 - Add delay between frames in lens_screen.dart
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 ✅
- Box: Green, 3px stroke
- Label: Green background, white text
- Text: Bold, 14px
- Pattern name (megamendung/parang)
- Confidence as percentage
- Bounding box around detected area
- 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
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]
Add after line 272 in _parseYOLOv8Results():
print('Found ${recognitions.length} detections before NMS');
recognitions = _applyNMS(recognitions);
print('Found ${recognitions.length} detections after NMS');- General Setup:
README.mdin models folder - Your Model Details:
MODEL_CONFIG.mdin models folder - Implementation Summary:
IMPLEMENTATION_SUMMARY.mdin root - Quick Start:
QUICK_START.mdin root
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! 🚀