mirror of
https://github.com/PhotonVision/photonvision
synced 2026-07-02 02:51:40 +00:00
Yolo duplication fix (#1713)
Somebody wanted a description, so here I am. This PR fixes an error which caused the discoverModels function to be rerun after each upload of a new model, but without clearing the list of available models. This causes any models that were on the list prior to the import to be duplicated. This PR also makes it so that uploading a model automatically updates the list of available models. --------- Co-authored-by: Matt Morley <matthew.morley.ca@gmail.com> Co-authored-by: Chris Gerth <gerth2@users.noreply.github.com>
This commit is contained in:
@@ -221,29 +221,28 @@ public class NeuralNetworkModelManager {
|
||||
/**
|
||||
* Discovers DNN models from the specified folder.
|
||||
*
|
||||
* @param modelsFolder The folder where the models are stored
|
||||
* @param modelsDirectory The folder where the models are stored
|
||||
*/
|
||||
public void discoverModels(File modelsFolder) {
|
||||
public void discoverModels(File modelsDirectory) {
|
||||
logger.info("Supported backends: " + supportedBackends);
|
||||
|
||||
if (!modelsFolder.exists()) {
|
||||
logger.error("Models folder " + modelsFolder.getAbsolutePath() + " does not exist.");
|
||||
if (!modelsDirectory.exists()) {
|
||||
logger.error("Models folder " + modelsDirectory.getAbsolutePath() + " does not exist.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (models == null) {
|
||||
models = new HashMap<>();
|
||||
}
|
||||
models = new HashMap<>();
|
||||
|
||||
try {
|
||||
Files.walk(modelsFolder.toPath())
|
||||
Files.walk(modelsDirectory.toPath())
|
||||
.filter(Files::isRegularFile)
|
||||
.forEach(path -> loadModel(path.toFile()));
|
||||
} catch (IOException e) {
|
||||
logger.error("Failed to discover models at " + modelsFolder.getAbsolutePath(), e);
|
||||
logger.error("Failed to discover models at " + modelsDirectory.getAbsolutePath(), e);
|
||||
}
|
||||
|
||||
// After loading all of the models, sort them by name to ensure a consistent ordering
|
||||
// After loading all of the models, sort them by name to ensure a consistent
|
||||
// ordering
|
||||
models.forEach(
|
||||
(backend, backendModels) ->
|
||||
backendModels.sort((a, b) -> a.getName().compareTo(b.getName())));
|
||||
|
||||
Reference in New Issue
Block a user