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:
Sam Freund
2025-01-12 19:48:39 -06:00
committed by GitHub
parent 5f75619063
commit 966b9e8c61
4 changed files with 34 additions and 21 deletions

View File

@@ -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())));