Skip to content

Commit

Permalink
update the logging so all models do the same
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Dec 17, 2024
1 parent 0d2f510 commit ae4c3f2
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 98 deletions.
27 changes: 13 additions & 14 deletions src/main/java/ai/nets/samj/communication/model/EfficientSAM.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,21 @@ public <T extends RealType<T> & NativeType<T>> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,22 +105,21 @@ public <T extends RealType<T> & NativeType<T>> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,21 @@ public <T extends RealType<T> & NativeType<T>> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,21 @@ public <T extends RealType<T> & NativeType<T>> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,21 @@ public <T extends RealType<T> & NativeType<T>> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,21 @@ public <T extends RealType<T> & NativeType<T>> 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());
Expand Down
27 changes: 13 additions & 14 deletions src/main/java/ai/nets/samj/communication/model/SAM2Small.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,22 +105,21 @@ public <T extends RealType<T> & NativeType<T>> 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());
Expand Down

0 comments on commit ae4c3f2

Please sign in to comment.