From b692fface149689298f82ab1a61286acfa695886 Mon Sep 17 00:00:00 2001 From: Sam948-byte Date: Sun, 12 Jan 2025 01:04:42 -0600 Subject: [PATCH 1/2] it'll work --- .../common/configuration/NeuralNetworkModelManager.java | 5 +++++ .../main/java/org/photonvision/server/RequestHandler.java | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/photon-core/src/main/java/org/photonvision/common/configuration/NeuralNetworkModelManager.java b/photon-core/src/main/java/org/photonvision/common/configuration/NeuralNetworkModelManager.java index 0418d5902a..e09151037b 100644 --- a/photon-core/src/main/java/org/photonvision/common/configuration/NeuralNetworkModelManager.java +++ b/photon-core/src/main/java/org/photonvision/common/configuration/NeuralNetworkModelManager.java @@ -136,6 +136,11 @@ public HashMap> getModels() { return modelMap; } + public void rescanModels(File modelsDirectory) { + models = null; + discoverModels(modelsDirectory); + } + /** * Retrieves the model with the specified name, assuming it is available under a supported * backend. diff --git a/photon-server/src/main/java/org/photonvision/server/RequestHandler.java b/photon-server/src/main/java/org/photonvision/server/RequestHandler.java index b1cc59656b..671fbb6ded 100644 --- a/photon-server/src/main/java/org/photonvision/server/RequestHandler.java +++ b/photon-server/src/main/java/org/photonvision/server/RequestHandler.java @@ -604,7 +604,7 @@ public static void onObjectDetectionModelImportRequest(Context ctx) { } NeuralNetworkModelManager.getInstance() - .discoverModels(ConfigManager.getInstance().getModelsDirectory()); + .rescanModels(ConfigManager.getInstance().getModelsDirectory()); ctx.status(200).result("Successfully uploaded object detection model"); } catch (Exception e) { From 935486401d6675eefdfc2f3c4a197fc8be4a51c2 Mon Sep 17 00:00:00 2001 From: Sam948-byte Date: Sun, 12 Jan 2025 01:04:42 -0600 Subject: [PATCH 2/2] it'll work --- .../common/configuration/NeuralNetworkModelManager.java | 8 +++++++- .../main/java/org/photonvision/server/RequestHandler.java | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/photon-core/src/main/java/org/photonvision/common/configuration/NeuralNetworkModelManager.java b/photon-core/src/main/java/org/photonvision/common/configuration/NeuralNetworkModelManager.java index 0418d5902a..c2f58c3e39 100644 --- a/photon-core/src/main/java/org/photonvision/common/configuration/NeuralNetworkModelManager.java +++ b/photon-core/src/main/java/org/photonvision/common/configuration/NeuralNetworkModelManager.java @@ -136,6 +136,11 @@ public HashMap> getModels() { return modelMap; } + public void rescanModels(File modelsDirectory) { + models = null; + discoverModels(modelsDirectory); + } + /** * Retrieves the model with the specified name, assuming it is available under a supported * backend. @@ -243,7 +248,8 @@ public void discoverModels(File modelsFolder) { logger.error("Failed to discover models at " + modelsFolder.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()))); diff --git a/photon-server/src/main/java/org/photonvision/server/RequestHandler.java b/photon-server/src/main/java/org/photonvision/server/RequestHandler.java index b1cc59656b..671fbb6ded 100644 --- a/photon-server/src/main/java/org/photonvision/server/RequestHandler.java +++ b/photon-server/src/main/java/org/photonvision/server/RequestHandler.java @@ -604,7 +604,7 @@ public static void onObjectDetectionModelImportRequest(Context ctx) { } NeuralNetworkModelManager.getInstance() - .discoverModels(ConfigManager.getInstance().getModelsDirectory()); + .rescanModels(ConfigManager.getInstance().getModelsDirectory()); ctx.status(200).result("Successfully uploaded object detection model"); } catch (Exception e) {