Can someone help me with the custom TF Lite model and Flutter using google_mlkit_object_detection: 0.13.0
Currently, I use the code below to try getting the detected objects and assign labels to them:
Future<void> labelImage(File imageFile) async {
final modelPath = await getModelPath('assets/ml/model.tflite');
final InputImage inputImage = InputImage.fromFile(imageFile);
const mode = DetectionMode.single;
final options = LocalObjectDetectorOptions(
mode: mode,
modelPath: modelPath,
classifyObjects: true,
multipleObjects: true,
maximumLabelsPerObject: 39,
);
final objectDetector = ObjectDetector(options: options);
final List<DetectedObject> objects =
await objectDetector.processImage(inputImage);
}
- In IOS, I can only see one object with an actual label Shorts while the rest of the objects have label with “Entitiy” as the text.
- In Android, all the detected objects have the empty list of labels.
Here’s the codes I made following the Google CodeLab with Model Maker
import tensorflow as tf
assert tf.__version__.startswith('2')
from tflite_model_maker import image_classifier
from tflite_model_maker.image_classifier import DataLoader
from tflite_model_maker.config import ExportFormat
from tflite_model_maker import model_spec
data_dir="D:\images_group_selected"
BATCH_SIZE = 4
EPOCHS = 8
data = DataLoader.from_folder(data_dir)
train_data, rest_data = data.split(0.8)
validation_data, test_data = rest_data.split(0.5)
model = image_classifier.create(
train_data,
validation_data=validation_data,
epochs=EPOCHS,
train_whole_model=True,
batch_size=BATCH_SIZE,
model_spec=model_spec.get('mobilenet_v2'),
shuffle=True)
model.summary()
model.export(export_dir='.', export_format=ExportFormat.TFLITE)
model.export(export_dir='.', export_format=ExportFormat.LABEL)
model.evaluate_tflite('model.tflite', test_data)
In my data structure, each directory would contain all the data belongs to a class (a label)
class1
-- image_class1_1.jpg
-- image_class1_2.jpg
class2
-- image_class2_1.jpg
-- image_class2_2.jpg
...
I suspect that since I created an image classifier, it does not work well with the ObjectDetector in Flutter. I really appreciate any advice about this issue.