mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-19 00:41:41 +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:
@@ -42,7 +42,9 @@ import org.photonvision.common.configuration.NeuralNetworkModelManager;
|
||||
import org.photonvision.common.dataflow.DataChangeDestination;
|
||||
import org.photonvision.common.dataflow.DataChangeService;
|
||||
import org.photonvision.common.dataflow.events.IncomingWebSocketEvent;
|
||||
import org.photonvision.common.dataflow.events.OutgoingUIEvent;
|
||||
import org.photonvision.common.dataflow.networktables.NetworkTablesManager;
|
||||
import org.photonvision.common.dataflow.websocket.UIPhotonConfiguration;
|
||||
import org.photonvision.common.hardware.HardwareManager;
|
||||
import org.photonvision.common.hardware.Platform;
|
||||
import org.photonvision.common.logging.LogGroup;
|
||||
@@ -546,7 +548,7 @@ public class RequestHandler {
|
||||
restartProgram();
|
||||
}
|
||||
|
||||
public static void onObjectDetectionModelImportRequest(Context ctx) {
|
||||
public static void onImportObjectDetectionModelRequest(Context ctx) {
|
||||
try {
|
||||
// Retrieve the uploaded files
|
||||
var modelFile = ctx.uploadedFile("rknn");
|
||||
@@ -579,7 +581,11 @@ public class RequestHandler {
|
||||
Pattern.compile("^[a-zA-Z0-9]+-\\d+-\\d+-yolov[58][a-z]*-labels\\.txt$");
|
||||
|
||||
if (!modelPattern.matcher(modelFile.filename()).matches()
|
||||
|| !labelsPattern.matcher(labelsFile.filename()).matches()) {
|
||||
|| !labelsPattern.matcher(labelsFile.filename()).matches()
|
||||
|| !(modelFile
|
||||
.filename()
|
||||
.substring(0, modelFile.filename().indexOf("-"))
|
||||
.equals(labelsFile.filename().substring(0, labelsFile.filename().indexOf("-"))))) {
|
||||
ctx.status(400);
|
||||
ctx.result("The uploaded files were not named correctly.");
|
||||
logger.error("The uploaded object detection model files were not named correctly.");
|
||||
@@ -610,6 +616,12 @@ public class RequestHandler {
|
||||
} catch (Exception e) {
|
||||
ctx.status(500).result("Error processing files: " + e.getMessage());
|
||||
}
|
||||
|
||||
DataChangeService.getInstance()
|
||||
.publishEvent(
|
||||
new OutgoingUIEvent<>(
|
||||
"fullsettings",
|
||||
UIPhotonConfiguration.programStateToUi(ConfigManager.getInstance().getConfig())));
|
||||
}
|
||||
|
||||
public static void onDeviceRestartRequest(Context ctx) {
|
||||
|
||||
Reference in New Issue
Block a user