Class NeuralNetworkModelManager

java.lang.Object
org.photonvision.common.configuration.NeuralNetworkModelManager

public class NeuralNetworkModelManager extends Object
Manages the loading of neural network models.

Models are loaded from the filesystem at the modelsFolder location. PhotonVision also supports shipping pre-trained models as resources in the JAR. If the model has already been extracted to the filesystem, it will not be extracted again.

Each model must have a corresponding labels file. The labels file format is simply a list of string names per label, one label per line. The labels file must have the same name as the model file, but with the suffix -labels.txt instead of .rknn .

  • Method Details

    • getInstance

      public static NeuralNetworkModelManager getInstance()
      Returns the singleton instance of the NeuralNetworkModelManager
      Returns:
      The singleton instance
    • getSupportedBackends

      public List<String> getSupportedBackends()
      Retrieves the list of supported backends.
      Returns:
      the list
    • getModels

      public HashMap<String,ArrayList<String>> getModels()
      Retrieves the deep neural network models available, in a format that can be used by the frontend.
      Returns:
      A map containing the available models, where the key is the backend and the value is a list of model names.
    • getModel

      public Optional<Model> getModel(String modelName)
      Retrieves the model with the specified name, assuming it is available under a supported backend.

      If this method returns `Optional.of(..)` then the model should be safe to load.

      Parameters:
      modelName - the name of the model to retrieve
      Returns:
      an Optional containing the model if found, or an empty Optional if not found
    • getDefaultModel

      public Optional<Model> getDefaultModel()
      The default model when no model is specified.
    • discoverModels

      public void discoverModels(File modelsFolder)
      Discovers DNN models from the specified folder.
      Parameters:
      modelsFolder - The folder where the models are stored
    • extractModels

      public void extractModels(File modelsDirectory)
      Extracts models from the JAR and copies them to disk.
      Parameters:
      modelsDirectory - the directory on disk to save models