loadObjectDetectionModel static method
Loads an object detection model from the specified asset path.
Creates a ModelObjectDetection instance with the loaded PyTorch model, configured dimensions, and optional label mappings.
@param path The asset path to the PyTorch model file @param numberOfClasses The number of classes the model can detect @param imageWidth The expected width for input images @param imageHeight The expected height for input images @param labelPath Optional path to a labels file (.txt or .csv format) @return A Future that completes with a ModelObjectDetection instance
Implementation
static Future<ModelObjectDetection> loadObjectDetectionModel(
String path, int numberOfClasses, int imageWidth, int imageHeight,
{String? labelPath}) async {
String absPathModelPath = await _getAbsolutePath(path);
int index = await ModelApi()
.loadModel(absPathModelPath, numberOfClasses, imageWidth, imageHeight, 0);
List<String> labels = [];
if (labelPath != null) {
if (labelPath.endsWith(".txt")) {
labels = await _getLabelsTxt(labelPath);
} else {
labels = await _getLabelsCsv(labelPath);
}
}
return ModelObjectDetection(index, imageWidth, imageHeight, labels);
}