From ae4c3f28aa4bc5aaced75a85322d21b722d0a2ab Mon Sep 17 00:00:00 2001 From: carlosuc3m <100329787@alumnos.uc3m.es> Date: Tue, 17 Dec 2024 14:58:55 +0100 Subject: [PATCH] update the logging so all models do the same --- .../communication/model/EfficientSAM.java | 27 +++++++++---------- .../model/EfficientViTSAML0.java | 27 +++++++++---------- .../model/EfficientViTSAML1.java | 27 +++++++++---------- .../model/EfficientViTSAML2.java | 27 +++++++++---------- .../model/EfficientViTSAMXL0.java | 27 +++++++++---------- .../model/EfficientViTSAMXL1.java | 27 +++++++++---------- .../samj/communication/model/SAM2Small.java | 27 +++++++++---------- 7 files changed, 91 insertions(+), 98 deletions(-) diff --git a/src/main/java/ai/nets/samj/communication/model/EfficientSAM.java b/src/main/java/ai/nets/samj/communication/model/EfficientSAM.java index 0e99eb7..3c20281 100644 --- a/src/main/java/ai/nets/samj/communication/model/EfficientSAM.java +++ b/src/main/java/ai/nets/samj/communication/model/EfficientSAM.java @@ -100,22 +100,21 @@ public & NativeType> void setImage(final RandomAccessi Objects.requireNonNull(image, "The image cannot be null."); if (useThisLoggerForIt != null) this.log = useThisLoggerForIt; + AbstractSamJ.DebugTextPrinter filteringLogger = text -> { + int idx = text.indexOf("\"responseType\": \"COMPLETION\""); + int idxProgress = text.indexOf(AbstractSamJ.getProgressString()); + if (idxProgress != -1) return; + if (idx > 0) { + String regex = "\"outputs\"\\s*:\\s*\\{.*?\\}(,)?"; + Pattern pattern = Pattern.compile(regex, Pattern.DOTALL); + Matcher matcher = pattern.matcher(text); + text = matcher.replaceAll(""); + } + this.log.info( text ); + }; if (this.samj == null) - samj = EfficientSamJ.initializeSam(manager); + samj = EfficientSamJ.initializeSam(manager, filteringLogger, false); try { - AbstractSamJ.DebugTextPrinter filteringLogger = text -> { - int idx = text.indexOf("\"responseType\": \"COMPLETION\""); - int idxProgress = text.indexOf(AbstractSamJ.getProgressString()); - if (idxProgress != -1) return; - if (idx > 0) { - String regex = "\"outputs\"\\s*:\\s*\\{.*?\\}(,)?"; - Pattern pattern = Pattern.compile(regex, Pattern.DOTALL); - Matcher matcher = pattern.matcher(text); - text = matcher.replaceAll(""); - } - this.log.info( text ); - }; - this.samj.setDebugPrinter(filteringLogger); this.samj.setImage(Cast.unchecked(image));; } catch (IOException | InterruptedException | RuntimeException e) { log.error(FULL_NAME + " experienced an error: " + e.getMessage()); diff --git a/src/main/java/ai/nets/samj/communication/model/EfficientViTSAML0.java b/src/main/java/ai/nets/samj/communication/model/EfficientViTSAML0.java index 48ed752..df1f963 100644 --- a/src/main/java/ai/nets/samj/communication/model/EfficientViTSAML0.java +++ b/src/main/java/ai/nets/samj/communication/model/EfficientViTSAML0.java @@ -105,22 +105,21 @@ public & NativeType> void setImage(final RandomAccessi Objects.requireNonNull(image, "The image cannot be null."); if (useThisLoggerForIt != null) this.log = useThisLoggerForIt; + AbstractSamJ.DebugTextPrinter filteringLogger = text -> { + int idx = text.indexOf("\"responseType\": \"COMPLETION\""); + int idxProgress = text.indexOf(AbstractSamJ.getProgressString()); + if (idxProgress != -1) return; + if (idx > 0) { + String regex = "\"outputs\"\\s*:\\s*\\{.*?\\}(,)?"; + Pattern pattern = Pattern.compile(regex, Pattern.DOTALL); + Matcher matcher = pattern.matcher(text); + text = matcher.replaceAll(""); + } + this.log.info( text ); + }; if (this.samj == null) - this.samj = EfficientViTSamJ.initializeSam("l0", manager); + this.samj = EfficientViTSamJ.initializeSam(ID, manager, filteringLogger, false); try { - AbstractSamJ.DebugTextPrinter filteringLogger = text -> { - int idx = text.indexOf("\"responseType\": \"COMPLETION\""); - int idxProgress = text.indexOf(AbstractSamJ.getProgressString()); - if (idxProgress != -1) return; - if (idx > 0) { - String regex = "\"outputs\"\\s*:\\s*\\{.*?\\}(,)?"; - Pattern pattern = Pattern.compile(regex, Pattern.DOTALL); - Matcher matcher = pattern.matcher(text); - text = matcher.replaceAll(""); - } - this.log.info( text ); - }; - this.samj.setDebugPrinter(filteringLogger); this.samj.setImage(Cast.unchecked(image));; } catch (IOException | InterruptedException | RuntimeException e) { log.error(FULL_NAME + " experienced an error: " + e.getMessage()); diff --git a/src/main/java/ai/nets/samj/communication/model/EfficientViTSAML1.java b/src/main/java/ai/nets/samj/communication/model/EfficientViTSAML1.java index c7b0354..0f1db25 100644 --- a/src/main/java/ai/nets/samj/communication/model/EfficientViTSAML1.java +++ b/src/main/java/ai/nets/samj/communication/model/EfficientViTSAML1.java @@ -103,22 +103,21 @@ public & NativeType> void setImage(final RandomAccessi Objects.requireNonNull(image, "The image cannot be null."); if (useThisLoggerForIt != null) this.log = useThisLoggerForIt; + AbstractSamJ.DebugTextPrinter filteringLogger = text -> { + int idx = text.indexOf("\"responseType\": \"COMPLETION\""); + int idxProgress = text.indexOf(AbstractSamJ.getProgressString()); + if (idxProgress != -1) return; + if (idx > 0) { + String regex = "\"outputs\"\\s*:\\s*\\{.*?\\}(,)?"; + Pattern pattern = Pattern.compile(regex, Pattern.DOTALL); + Matcher matcher = pattern.matcher(text); + text = matcher.replaceAll(""); + } + this.log.info( text ); + }; if (this.samj == null) - this.samj = EfficientViTSamJ.initializeSam("l1", manager); + this.samj = EfficientViTSamJ.initializeSam(ID, manager, filteringLogger, false); try { - AbstractSamJ.DebugTextPrinter filteringLogger = text -> { - int idx = text.indexOf("\"responseType\": \"COMPLETION\""); - int idxProgress = text.indexOf(AbstractSamJ.getProgressString()); - if (idxProgress != -1) return; - if (idx > 0) { - String regex = "\"outputs\"\\s*:\\s*\\{.*?\\}(,)?"; - Pattern pattern = Pattern.compile(regex, Pattern.DOTALL); - Matcher matcher = pattern.matcher(text); - text = matcher.replaceAll(""); - } - this.log.info( text ); - }; - this.samj.setDebugPrinter(filteringLogger); this.samj.setImage(Cast.unchecked(image));; } catch (IOException | InterruptedException | RuntimeException e) { log.error(FULL_NAME + " experienced an error: " + e.getMessage()); diff --git a/src/main/java/ai/nets/samj/communication/model/EfficientViTSAML2.java b/src/main/java/ai/nets/samj/communication/model/EfficientViTSAML2.java index e9d41a3..59c44d0 100644 --- a/src/main/java/ai/nets/samj/communication/model/EfficientViTSAML2.java +++ b/src/main/java/ai/nets/samj/communication/model/EfficientViTSAML2.java @@ -103,22 +103,21 @@ public & NativeType> void setImage(final RandomAccessi Objects.requireNonNull(image, "The image cannot be null."); if (useThisLoggerForIt != null) this.log = useThisLoggerForIt; + AbstractSamJ.DebugTextPrinter filteringLogger = text -> { + int idx = text.indexOf("\"responseType\": \"COMPLETION\""); + int idxProgress = text.indexOf(AbstractSamJ.getProgressString()); + if (idxProgress != -1) return; + if (idx > 0) { + String regex = "\"outputs\"\\s*:\\s*\\{.*?\\}(,)?"; + Pattern pattern = Pattern.compile(regex, Pattern.DOTALL); + Matcher matcher = pattern.matcher(text); + text = matcher.replaceAll(""); + } + this.log.info( text ); + }; if (this.samj == null) - this.samj = EfficientViTSamJ.initializeSam("l2", manager); + this.samj = EfficientViTSamJ.initializeSam(ID, manager, filteringLogger, false); try { - AbstractSamJ.DebugTextPrinter filteringLogger = text -> { - int idx = text.indexOf("\"responseType\": \"COMPLETION\""); - int idxProgress = text.indexOf(AbstractSamJ.getProgressString()); - if (idxProgress != -1) return; - if (idx > 0) { - String regex = "\"outputs\"\\s*:\\s*\\{.*?\\}(,)?"; - Pattern pattern = Pattern.compile(regex, Pattern.DOTALL); - Matcher matcher = pattern.matcher(text); - text = matcher.replaceAll(""); - } - this.log.info( text ); - }; - this.samj.setDebugPrinter(filteringLogger); this.samj.setImage(Cast.unchecked(image));; } catch (IOException | InterruptedException | RuntimeException e) { log.error(FULL_NAME + " experienced an error: " + e.getMessage()); diff --git a/src/main/java/ai/nets/samj/communication/model/EfficientViTSAMXL0.java b/src/main/java/ai/nets/samj/communication/model/EfficientViTSAMXL0.java index 848d8fb..7862e49 100644 --- a/src/main/java/ai/nets/samj/communication/model/EfficientViTSAMXL0.java +++ b/src/main/java/ai/nets/samj/communication/model/EfficientViTSAMXL0.java @@ -102,22 +102,21 @@ public & NativeType> void setImage(final RandomAccessi Objects.requireNonNull(image, "The image cannot be null."); if (useThisLoggerForIt != null) this.log = useThisLoggerForIt; + AbstractSamJ.DebugTextPrinter filteringLogger = text -> { + int idx = text.indexOf("\"responseType\": \"COMPLETION\""); + int idxProgress = text.indexOf(AbstractSamJ.getProgressString()); + if (idxProgress != -1) return; + if (idx > 0) { + String regex = "\"outputs\"\\s*:\\s*\\{.*?\\}(,)?"; + Pattern pattern = Pattern.compile(regex, Pattern.DOTALL); + Matcher matcher = pattern.matcher(text); + text = matcher.replaceAll(""); + } + this.log.info( text ); + }; if (this.samj == null) - this.samj = EfficientViTSamJ.initializeSam("xl0", manager); + this.samj = EfficientViTSamJ.initializeSam(ID, manager, filteringLogger, false); try { - AbstractSamJ.DebugTextPrinter filteringLogger = text -> { - int idx = text.indexOf("\"responseType\": \"COMPLETION\""); - int idxProgress = text.indexOf(AbstractSamJ.getProgressString()); - if (idxProgress != -1) return; - if (idx > 0) { - String regex = "\"outputs\"\\s*:\\s*\\{.*?\\}(,)?"; - Pattern pattern = Pattern.compile(regex, Pattern.DOTALL); - Matcher matcher = pattern.matcher(text); - text = matcher.replaceAll(""); - } - this.log.info( text ); - }; - this.samj.setDebugPrinter(filteringLogger); this.samj.setImage(Cast.unchecked(image));; } catch (IOException | InterruptedException | RuntimeException e) { log.error(FULL_NAME + " experienced an error: " + e.getMessage()); diff --git a/src/main/java/ai/nets/samj/communication/model/EfficientViTSAMXL1.java b/src/main/java/ai/nets/samj/communication/model/EfficientViTSAMXL1.java index ed43209..fcd2862 100644 --- a/src/main/java/ai/nets/samj/communication/model/EfficientViTSAMXL1.java +++ b/src/main/java/ai/nets/samj/communication/model/EfficientViTSAMXL1.java @@ -104,22 +104,21 @@ public & NativeType> void setImage(final RandomAccessi Objects.requireNonNull(image, "The image cannot be null."); if (useThisLoggerForIt != null) this.log = useThisLoggerForIt; + AbstractSamJ.DebugTextPrinter filteringLogger = text -> { + int idx = text.indexOf("\"responseType\": \"COMPLETION\""); + int idxProgress = text.indexOf(AbstractSamJ.getProgressString()); + if (idxProgress != -1) return; + if (idx > 0) { + String regex = "\"outputs\"\\s*:\\s*\\{.*?\\}(,)?"; + Pattern pattern = Pattern.compile(regex, Pattern.DOTALL); + Matcher matcher = pattern.matcher(text); + text = matcher.replaceAll(""); + } + this.log.info( text ); + }; if (this.samj == null) - this.samj = EfficientViTSamJ.initializeSam("xl1", manager); + this.samj = EfficientViTSamJ.initializeSam(ID, manager, filteringLogger, false); try { - AbstractSamJ.DebugTextPrinter filteringLogger = text -> { - int idx = text.indexOf("\"responseType\": \"COMPLETION\""); - int idxProgress = text.indexOf(AbstractSamJ.getProgressString()); - if (idxProgress != -1) return; - if (idx > 0) { - String regex = "\"outputs\"\\s*:\\s*\\{.*?\\}(,)?"; - Pattern pattern = Pattern.compile(regex, Pattern.DOTALL); - Matcher matcher = pattern.matcher(text); - text = matcher.replaceAll(""); - } - this.log.info( text ); - }; - this.samj.setDebugPrinter(filteringLogger); this.samj.setImage(Cast.unchecked(image));; } catch (IOException | InterruptedException | RuntimeException e) { log.error(FULL_NAME + " experienced an error: " + e.getMessage()); diff --git a/src/main/java/ai/nets/samj/communication/model/SAM2Small.java b/src/main/java/ai/nets/samj/communication/model/SAM2Small.java index 587effb..e029209 100644 --- a/src/main/java/ai/nets/samj/communication/model/SAM2Small.java +++ b/src/main/java/ai/nets/samj/communication/model/SAM2Small.java @@ -105,22 +105,21 @@ public & NativeType> void setImage(final RandomAccessi Objects.requireNonNull(image, "The image cannot be null."); if (useThisLoggerForIt != null) this.log = useThisLoggerForIt; + AbstractSamJ.DebugTextPrinter filteringLogger = text -> { + int idx = text.indexOf("\"responseType\": \"COMPLETION\""); + int idxProgress = text.indexOf(AbstractSamJ.getProgressString()); + if (idxProgress != -1) return; + if (idx > 0) { + String regex = "\"outputs\"\\s*:\\s*\\{.*?\\}(,)?"; + Pattern pattern = Pattern.compile(regex, Pattern.DOTALL); + Matcher matcher = pattern.matcher(text); + text = matcher.replaceAll(""); + } + this.log.info( text ); + }; if (this.samj == null) - samj = Sam2.initializeSam(ID, manager); + samj = Sam2.initializeSam(ID, manager, filteringLogger, false); try { - AbstractSamJ.DebugTextPrinter filteringLogger = text -> { - int idx = text.indexOf("\"responseType\": \"COMPLETION\""); - int idxProgress = text.indexOf(AbstractSamJ.getProgressString()); - if (idxProgress != -1) return; - if (idx > 0) { - String regex = "\"outputs\"\\s*:\\s*\\{.*?\\}(,)?"; - Pattern pattern = Pattern.compile(regex, Pattern.DOTALL); - Matcher matcher = pattern.matcher(text); - text = matcher.replaceAll(""); - } - this.log.info( text ); - }; - this.samj.setDebugPrinter(filteringLogger); this.samj.setImage(Cast.unchecked(image));; } catch (IOException | InterruptedException | RuntimeException e) { log.error(FULL_NAME + " experienced an error: " + e.getMessage());