loadObjectDetectionModel static method

Future<ModelObjectDetection> loadObjectDetectionModel(
  1. String path,
  2. int numberOfClasses,
  3. int imageWidth,
  4. int imageHeight, {
  5. String? labelPath,
})

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);
}