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
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionvoid
discoverModels
(File modelsDirectory) 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.static String[]
parseRKNNName
(String modelName) Parse RKNN name and return the name, width, height, and model type.static void
verifyRKNNNames
(String modelName, String labelsName) Check naming conventions for models and labels.
-
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:
modelsDirectory
- 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
-
verifyRKNNNames
Check naming conventions for models and labels.This is static as it is not dependent on the state of the class.
- Parameters:
modelName
- the name of the modellabelsName
- the name of the labels file- Throws:
IllegalArgumentException
- if the names are invalid
-
parseRKNNName
Parse RKNN name and return the name, width, height, and model type.This is static as it is not dependent on the state of the class.
- Parameters:
modelName
- the name of the model- Returns:
- an array containing the name, width, height, and model type
- Throws:
IllegalArgumentException
- if the model name does not follow the naming convention
-