Skip to content

Commit

Permalink
use downsampling with efficientsam
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Oct 31, 2024
1 parent 13176e1 commit cf49a74
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/main/java/ai/nets/samj/models/AbstractSamJ.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public abstract class AbstractSamJ implements AutoCloseable {

protected static long ENCODE_MARGIN = 64;

protected static int MAX_IMG_SIZE = 2048;
protected static int MAX_IMG_SIZE = 2024;

/** Essentially, a syntactic-shortcut for a String consumer */
public interface DebugTextPrinter { void printText(String text); }
Expand Down Expand Up @@ -995,7 +995,7 @@ protected void recalculatePolys(List<Mask> masks, long[] encodeCoords) {
int newY = y * scale;
long newLen = pp.getRLEMask()[i + 1] * scale;
for (int j = 0; j < scale; j ++) {
upscaledRLE[i * scale + j * 2] = newX + encodeCoords[0] + (newY + j) * this.img.dimensionsAsLongArray()[0];
upscaledRLE[i * scale + j * 2] = newX + encodeCoords[0] + (encodeCoords[1] + newY + j) * this.img.dimensionsAsLongArray()[0];
upscaledRLE[i * scale + j * 2 + 1] = newLen;
}
}
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/ai/nets/samj/models/EfficientSamJ.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,15 @@ protected void createEncodeImageScript() {
code += "im_shm = shared_memory.SharedMemory(name='"
+ shma.getNameForPython() + "', size=" + shma.getSize()
+ ")" + System.lineSeparator();
int size = 1;
for (long l : targetDims) {size *= l;}
int size = (int) targetDims[2];
for (int i = 0; i < targetDims.length - 1; i ++) {
size *= Math.ceil(targetDims[i] / (double) scale);
}
code += "im = np.ndarray(" + size + ", dtype='" + CommonUtils.getDataTypeFromRAI(Cast.unchecked(shma.getSharedRAI()))
+ "', buffer=im_shm.buf).reshape([";
for (long ll : targetDims)
code += ll + ", ";
code = code.substring(0, code.length() - 2);
for (int i = 0; i < targetDims.length - 1; i ++)
code += (int) Math.ceil(targetDims[i] / (double) scale) + ", ";
code += targetDims[2];
code += "])" + System.lineSeparator();
//code += "np.save('/home/carlos/git/crop.npy', im)" + System.lineSeparator();
code += "input_h = im.shape[1]" + System.lineSeparator();
Expand Down

0 comments on commit cf49a74

Please sign in to comment.