Skip to content

Commit ae4c3f2

Browse files
committed
update the logging so all models do the same
1 parent 0d2f510 commit ae4c3f2

File tree

7 files changed

+91
-98
lines changed

7 files changed

+91
-98
lines changed

src/main/java/ai/nets/samj/communication/model/EfficientSAM.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,21 @@ public <T extends RealType<T> & NativeType<T>> void setImage(final RandomAccessi
100100
Objects.requireNonNull(image, "The image cannot be null.");
101101
if (useThisLoggerForIt != null)
102102
this.log = useThisLoggerForIt;
103+
AbstractSamJ.DebugTextPrinter filteringLogger = text -> {
104+
int idx = text.indexOf("\"responseType\": \"COMPLETION\"");
105+
int idxProgress = text.indexOf(AbstractSamJ.getProgressString());
106+
if (idxProgress != -1) return;
107+
if (idx > 0) {
108+
String regex = "\"outputs\"\\s*:\\s*\\{.*?\\}(,)?";
109+
Pattern pattern = Pattern.compile(regex, Pattern.DOTALL);
110+
Matcher matcher = pattern.matcher(text);
111+
text = matcher.replaceAll("");
112+
}
113+
this.log.info( text );
114+
};
103115
if (this.samj == null)
104-
samj = EfficientSamJ.initializeSam(manager);
116+
samj = EfficientSamJ.initializeSam(manager, filteringLogger, false);
105117
try {
106-
AbstractSamJ.DebugTextPrinter filteringLogger = text -> {
107-
int idx = text.indexOf("\"responseType\": \"COMPLETION\"");
108-
int idxProgress = text.indexOf(AbstractSamJ.getProgressString());
109-
if (idxProgress != -1) return;
110-
if (idx > 0) {
111-
String regex = "\"outputs\"\\s*:\\s*\\{.*?\\}(,)?";
112-
Pattern pattern = Pattern.compile(regex, Pattern.DOTALL);
113-
Matcher matcher = pattern.matcher(text);
114-
text = matcher.replaceAll("");
115-
}
116-
this.log.info( text );
117-
};
118-
this.samj.setDebugPrinter(filteringLogger);
119118
this.samj.setImage(Cast.unchecked(image));;
120119
} catch (IOException | InterruptedException | RuntimeException e) {
121120
log.error(FULL_NAME + " experienced an error: " + e.getMessage());

src/main/java/ai/nets/samj/communication/model/EfficientViTSAML0.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,22 +105,21 @@ public <T extends RealType<T> & NativeType<T>> void setImage(final RandomAccessi
105105
Objects.requireNonNull(image, "The image cannot be null.");
106106
if (useThisLoggerForIt != null)
107107
this.log = useThisLoggerForIt;
108+
AbstractSamJ.DebugTextPrinter filteringLogger = text -> {
109+
int idx = text.indexOf("\"responseType\": \"COMPLETION\"");
110+
int idxProgress = text.indexOf(AbstractSamJ.getProgressString());
111+
if (idxProgress != -1) return;
112+
if (idx > 0) {
113+
String regex = "\"outputs\"\\s*:\\s*\\{.*?\\}(,)?";
114+
Pattern pattern = Pattern.compile(regex, Pattern.DOTALL);
115+
Matcher matcher = pattern.matcher(text);
116+
text = matcher.replaceAll("");
117+
}
118+
this.log.info( text );
119+
};
108120
if (this.samj == null)
109-
this.samj = EfficientViTSamJ.initializeSam("l0", manager);
121+
this.samj = EfficientViTSamJ.initializeSam(ID, manager, filteringLogger, false);
110122
try {
111-
AbstractSamJ.DebugTextPrinter filteringLogger = text -> {
112-
int idx = text.indexOf("\"responseType\": \"COMPLETION\"");
113-
int idxProgress = text.indexOf(AbstractSamJ.getProgressString());
114-
if (idxProgress != -1) return;
115-
if (idx > 0) {
116-
String regex = "\"outputs\"\\s*:\\s*\\{.*?\\}(,)?";
117-
Pattern pattern = Pattern.compile(regex, Pattern.DOTALL);
118-
Matcher matcher = pattern.matcher(text);
119-
text = matcher.replaceAll("");
120-
}
121-
this.log.info( text );
122-
};
123-
this.samj.setDebugPrinter(filteringLogger);
124123
this.samj.setImage(Cast.unchecked(image));;
125124
} catch (IOException | InterruptedException | RuntimeException e) {
126125
log.error(FULL_NAME + " experienced an error: " + e.getMessage());

src/main/java/ai/nets/samj/communication/model/EfficientViTSAML1.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -103,22 +103,21 @@ public <T extends RealType<T> & NativeType<T>> void setImage(final RandomAccessi
103103
Objects.requireNonNull(image, "The image cannot be null.");
104104
if (useThisLoggerForIt != null)
105105
this.log = useThisLoggerForIt;
106+
AbstractSamJ.DebugTextPrinter filteringLogger = text -> {
107+
int idx = text.indexOf("\"responseType\": \"COMPLETION\"");
108+
int idxProgress = text.indexOf(AbstractSamJ.getProgressString());
109+
if (idxProgress != -1) return;
110+
if (idx > 0) {
111+
String regex = "\"outputs\"\\s*:\\s*\\{.*?\\}(,)?";
112+
Pattern pattern = Pattern.compile(regex, Pattern.DOTALL);
113+
Matcher matcher = pattern.matcher(text);
114+
text = matcher.replaceAll("");
115+
}
116+
this.log.info( text );
117+
};
106118
if (this.samj == null)
107-
this.samj = EfficientViTSamJ.initializeSam("l1", manager);
119+
this.samj = EfficientViTSamJ.initializeSam(ID, manager, filteringLogger, false);
108120
try {
109-
AbstractSamJ.DebugTextPrinter filteringLogger = text -> {
110-
int idx = text.indexOf("\"responseType\": \"COMPLETION\"");
111-
int idxProgress = text.indexOf(AbstractSamJ.getProgressString());
112-
if (idxProgress != -1) return;
113-
if (idx > 0) {
114-
String regex = "\"outputs\"\\s*:\\s*\\{.*?\\}(,)?";
115-
Pattern pattern = Pattern.compile(regex, Pattern.DOTALL);
116-
Matcher matcher = pattern.matcher(text);
117-
text = matcher.replaceAll("");
118-
}
119-
this.log.info( text );
120-
};
121-
this.samj.setDebugPrinter(filteringLogger);
122121
this.samj.setImage(Cast.unchecked(image));;
123122
} catch (IOException | InterruptedException | RuntimeException e) {
124123
log.error(FULL_NAME + " experienced an error: " + e.getMessage());

src/main/java/ai/nets/samj/communication/model/EfficientViTSAML2.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -103,22 +103,21 @@ public <T extends RealType<T> & NativeType<T>> void setImage(final RandomAccessi
103103
Objects.requireNonNull(image, "The image cannot be null.");
104104
if (useThisLoggerForIt != null)
105105
this.log = useThisLoggerForIt;
106+
AbstractSamJ.DebugTextPrinter filteringLogger = text -> {
107+
int idx = text.indexOf("\"responseType\": \"COMPLETION\"");
108+
int idxProgress = text.indexOf(AbstractSamJ.getProgressString());
109+
if (idxProgress != -1) return;
110+
if (idx > 0) {
111+
String regex = "\"outputs\"\\s*:\\s*\\{.*?\\}(,)?";
112+
Pattern pattern = Pattern.compile(regex, Pattern.DOTALL);
113+
Matcher matcher = pattern.matcher(text);
114+
text = matcher.replaceAll("");
115+
}
116+
this.log.info( text );
117+
};
106118
if (this.samj == null)
107-
this.samj = EfficientViTSamJ.initializeSam("l2", manager);
119+
this.samj = EfficientViTSamJ.initializeSam(ID, manager, filteringLogger, false);
108120
try {
109-
AbstractSamJ.DebugTextPrinter filteringLogger = text -> {
110-
int idx = text.indexOf("\"responseType\": \"COMPLETION\"");
111-
int idxProgress = text.indexOf(AbstractSamJ.getProgressString());
112-
if (idxProgress != -1) return;
113-
if (idx > 0) {
114-
String regex = "\"outputs\"\\s*:\\s*\\{.*?\\}(,)?";
115-
Pattern pattern = Pattern.compile(regex, Pattern.DOTALL);
116-
Matcher matcher = pattern.matcher(text);
117-
text = matcher.replaceAll("");
118-
}
119-
this.log.info( text );
120-
};
121-
this.samj.setDebugPrinter(filteringLogger);
122121
this.samj.setImage(Cast.unchecked(image));;
123122
} catch (IOException | InterruptedException | RuntimeException e) {
124123
log.error(FULL_NAME + " experienced an error: " + e.getMessage());

src/main/java/ai/nets/samj/communication/model/EfficientViTSAMXL0.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,22 +102,21 @@ public <T extends RealType<T> & NativeType<T>> void setImage(final RandomAccessi
102102
Objects.requireNonNull(image, "The image cannot be null.");
103103
if (useThisLoggerForIt != null)
104104
this.log = useThisLoggerForIt;
105+
AbstractSamJ.DebugTextPrinter filteringLogger = text -> {
106+
int idx = text.indexOf("\"responseType\": \"COMPLETION\"");
107+
int idxProgress = text.indexOf(AbstractSamJ.getProgressString());
108+
if (idxProgress != -1) return;
109+
if (idx > 0) {
110+
String regex = "\"outputs\"\\s*:\\s*\\{.*?\\}(,)?";
111+
Pattern pattern = Pattern.compile(regex, Pattern.DOTALL);
112+
Matcher matcher = pattern.matcher(text);
113+
text = matcher.replaceAll("");
114+
}
115+
this.log.info( text );
116+
};
105117
if (this.samj == null)
106-
this.samj = EfficientViTSamJ.initializeSam("xl0", manager);
118+
this.samj = EfficientViTSamJ.initializeSam(ID, manager, filteringLogger, false);
107119
try {
108-
AbstractSamJ.DebugTextPrinter filteringLogger = text -> {
109-
int idx = text.indexOf("\"responseType\": \"COMPLETION\"");
110-
int idxProgress = text.indexOf(AbstractSamJ.getProgressString());
111-
if (idxProgress != -1) return;
112-
if (idx > 0) {
113-
String regex = "\"outputs\"\\s*:\\s*\\{.*?\\}(,)?";
114-
Pattern pattern = Pattern.compile(regex, Pattern.DOTALL);
115-
Matcher matcher = pattern.matcher(text);
116-
text = matcher.replaceAll("");
117-
}
118-
this.log.info( text );
119-
};
120-
this.samj.setDebugPrinter(filteringLogger);
121120
this.samj.setImage(Cast.unchecked(image));;
122121
} catch (IOException | InterruptedException | RuntimeException e) {
123122
log.error(FULL_NAME + " experienced an error: " + e.getMessage());

src/main/java/ai/nets/samj/communication/model/EfficientViTSAMXL1.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,22 +104,21 @@ public <T extends RealType<T> & NativeType<T>> void setImage(final RandomAccessi
104104
Objects.requireNonNull(image, "The image cannot be null.");
105105
if (useThisLoggerForIt != null)
106106
this.log = useThisLoggerForIt;
107+
AbstractSamJ.DebugTextPrinter filteringLogger = text -> {
108+
int idx = text.indexOf("\"responseType\": \"COMPLETION\"");
109+
int idxProgress = text.indexOf(AbstractSamJ.getProgressString());
110+
if (idxProgress != -1) return;
111+
if (idx > 0) {
112+
String regex = "\"outputs\"\\s*:\\s*\\{.*?\\}(,)?";
113+
Pattern pattern = Pattern.compile(regex, Pattern.DOTALL);
114+
Matcher matcher = pattern.matcher(text);
115+
text = matcher.replaceAll("");
116+
}
117+
this.log.info( text );
118+
};
107119
if (this.samj == null)
108-
this.samj = EfficientViTSamJ.initializeSam("xl1", manager);
120+
this.samj = EfficientViTSamJ.initializeSam(ID, manager, filteringLogger, false);
109121
try {
110-
AbstractSamJ.DebugTextPrinter filteringLogger = text -> {
111-
int idx = text.indexOf("\"responseType\": \"COMPLETION\"");
112-
int idxProgress = text.indexOf(AbstractSamJ.getProgressString());
113-
if (idxProgress != -1) return;
114-
if (idx > 0) {
115-
String regex = "\"outputs\"\\s*:\\s*\\{.*?\\}(,)?";
116-
Pattern pattern = Pattern.compile(regex, Pattern.DOTALL);
117-
Matcher matcher = pattern.matcher(text);
118-
text = matcher.replaceAll("");
119-
}
120-
this.log.info( text );
121-
};
122-
this.samj.setDebugPrinter(filteringLogger);
123122
this.samj.setImage(Cast.unchecked(image));;
124123
} catch (IOException | InterruptedException | RuntimeException e) {
125124
log.error(FULL_NAME + " experienced an error: " + e.getMessage());

src/main/java/ai/nets/samj/communication/model/SAM2Small.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,22 +105,21 @@ public <T extends RealType<T> & NativeType<T>> void setImage(final RandomAccessi
105105
Objects.requireNonNull(image, "The image cannot be null.");
106106
if (useThisLoggerForIt != null)
107107
this.log = useThisLoggerForIt;
108+
AbstractSamJ.DebugTextPrinter filteringLogger = text -> {
109+
int idx = text.indexOf("\"responseType\": \"COMPLETION\"");
110+
int idxProgress = text.indexOf(AbstractSamJ.getProgressString());
111+
if (idxProgress != -1) return;
112+
if (idx > 0) {
113+
String regex = "\"outputs\"\\s*:\\s*\\{.*?\\}(,)?";
114+
Pattern pattern = Pattern.compile(regex, Pattern.DOTALL);
115+
Matcher matcher = pattern.matcher(text);
116+
text = matcher.replaceAll("");
117+
}
118+
this.log.info( text );
119+
};
108120
if (this.samj == null)
109-
samj = Sam2.initializeSam(ID, manager);
121+
samj = Sam2.initializeSam(ID, manager, filteringLogger, false);
110122
try {
111-
AbstractSamJ.DebugTextPrinter filteringLogger = text -> {
112-
int idx = text.indexOf("\"responseType\": \"COMPLETION\"");
113-
int idxProgress = text.indexOf(AbstractSamJ.getProgressString());
114-
if (idxProgress != -1) return;
115-
if (idx > 0) {
116-
String regex = "\"outputs\"\\s*:\\s*\\{.*?\\}(,)?";
117-
Pattern pattern = Pattern.compile(regex, Pattern.DOTALL);
118-
Matcher matcher = pattern.matcher(text);
119-
text = matcher.replaceAll("");
120-
}
121-
this.log.info( text );
122-
};
123-
this.samj.setDebugPrinter(filteringLogger);
124123
this.samj.setImage(Cast.unchecked(image));;
125124
} catch (IOException | InterruptedException | RuntimeException e) {
126125
log.error(FULL_NAME + " experienced an error: " + e.getMessage());

0 commit comments

Comments
 (0)