Class NeuralNetworkModelManager
java.lang.Object
org.photonvision.common.configuration.NeuralNetworkModelManager
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
.
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
discoverModels
(File modelsFolder) Discovers DNN models from the specified folder.void
extractModels
(File modelsDirectory) Extracts models from the JAR and copies them to disk.The default model when no model is specified.static NeuralNetworkModelManager
Returns the singleton instance of the NeuralNetworkModelManagerRetrieves the model with the specified name, assuming it is available under a supported backend.Retrieves the deep neural network models available, in a format that can be used by the frontend.Retrieves the list of supported backends.
-
Method Details
-
getInstance
Returns the singleton instance of the NeuralNetworkModelManager- Returns:
- The singleton instance
-
getSupportedBackends
Retrieves the list of supported backends.- Returns:
- the list
-
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
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
The default model when no model is specified. -
discoverModels
Discovers DNN models from the specified folder.- Parameters:
modelsFolder
- The folder where the models are stored
-
extractModels
Extracts models from the JAR and copies them to disk.- Parameters:
modelsDirectory
- the directory on disk to save models
-