loadObjectDetectionModel static method

Future<ModelObjectDetection> loadObjectDetectionModel(
  1. String path,
  2. int numberOfClasses,
  3. int imageWidth,
  4. int imageHeight, {
  5. String? labelPath,
  6. ObjectDetectionModelType objectDetectionModelType = ObjectDetectionModelType.yolov5,
  7. ModelLocation modelLocation = ModelLocation.asset,
})

Sets pytorch object detection model (path and lables) and returns Model

Implementation

static Future<ModelObjectDetection> loadObjectDetectionModel(
    String path, int numberOfClasses, int imageWidth, int imageHeight,
    {String? labelPath,
    ObjectDetectionModelType objectDetectionModelType =
        ObjectDetectionModelType.yolov5,
    ModelLocation modelLocation = ModelLocation.asset}) async {
  if (modelLocation == ModelLocation.asset) {
    path = await _getAbsolutePath(path);
  }

  int index = await ModelApi().loadModel(path, numberOfClasses, imageWidth,
      imageHeight, objectDetectionModelType.index);
  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,
      modelType: objectDetectionModelType);
}