From 8868c3b295b3f8edb6fc8f3cac4d684b50fe9c3b Mon Sep 17 00:00:00 2001 From: Alextopher Date: Thu, 19 Sep 2024 02:53:21 -0400 Subject: [PATCH] improve od pipeline error handling --- .../pipeline/ObjectDetectionPipeline.java | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/photon-core/src/main/java/org/photonvision/vision/pipeline/ObjectDetectionPipeline.java b/photon-core/src/main/java/org/photonvision/vision/pipeline/ObjectDetectionPipeline.java index 7d260b8b48..cac5b04827 100644 --- a/photon-core/src/main/java/org/photonvision/vision/pipeline/ObjectDetectionPipeline.java +++ b/photon-core/src/main/java/org/photonvision/vision/pipeline/ObjectDetectionPipeline.java @@ -56,19 +56,24 @@ public ObjectDetectionPipeline(ObjectDetectionPipelineSettings settings) { @Override protected void setPipeParamsImpl() { - // this needs to be based off of the current backend selected!! var params = new ObjectDetectionPipeParams(); params.confidence = settings.confidence; params.nms = settings.nms; - Optional model = NeuralNetworkModelManager.getInstance().getModel(settings.model); - model.ifPresentOrElse( - m -> params.model = m, - () -> { - params.model = - NeuralNetworkModelManager.getInstance() - .getDefaultModel() - .orElse(NullModel.getInstance()); - }); + Optional selectedModel = NeuralNetworkModelManager.getInstance().getModel(settings.model); + + // If the desired model couldn't be found, log an error and try to use the default model + if (selectedModel.isEmpty()) { + // logger.error("Model not found: " + settings.model + ". Trying to use default model."); + selectedModel = NeuralNetworkModelManager.getInstance().getDefaultModel(); + } + + // If the model remains empty, use the NullModel + if (selectedModel.isEmpty()) { + // logger.error("Default Model not found. Using empty NullModel."); + selectedModel = Optional.of(NullModel.getInstance()); + } + + params.model = selectedModel.get(); objectDetectorPipe.setParams(params);