Skip to content

Commit

Permalink
Merge branch 'yolo-duplication-fix' of github.com:Sam948-byte/photonv…
Browse files Browse the repository at this point in the history
…ision into yolo-duplication-fix
  • Loading branch information
Sam948-byte committed Jan 12, 2025
2 parents 96381e7 + 3870263 commit 8cd1a2a
Showing 2 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -137,6 +137,11 @@ public HashMap<String, ArrayList<String>> 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.
Original file line number Diff line number Diff line change
@@ -585,15 +585,27 @@ public static void onImportObjectDetectionModelRequest(Context ctx) {
logger.error("The uploaded object detection model files were not named correctly.");
return;
}
File tmpModel = Files.createTempFile(modelFile.filename(), null).toFile();
File tmpLabels = Files.createTempFile(labelsFile.filename(), null).toFile();

if (!NeuralNetworkModelManager.getInstance()
.addNewModel(tmpModel, tmpLabels, ConfigManager.getInstance().getModelsDirectory())) {
ctx.status(500).result("Error processing files: Check logs for more information");
return;
// TODO move into neural network manager

var modelPath =
Paths.get(
ConfigManager.getInstance().getModelsDirectory().toString(), modelFile.filename());
var labelsPath =
Paths.get(
ConfigManager.getInstance().getModelsDirectory().toString(), labelsFile.filename());

try (FileOutputStream out = new FileOutputStream(modelPath.toFile())) {
modelFile.content().transferTo(out);
}

try (FileOutputStream out = new FileOutputStream(labelsPath.toFile())) {
labelsFile.content().transferTo(out);
}

NeuralNetworkModelManager.getInstance()
.rescanModels(ConfigManager.getInstance().getModelsDirectory());

ctx.status(200).result("Successfully uploaded object detection model");
} catch (Exception e) {
ctx.status(500).result("Error processing files: " + e.getMessage());

0 comments on commit 8cd1a2a

Please sign in to comment.