Skip to content

Commit

Permalink
start adding SAM everything method
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Jun 3, 2024
1 parent 1be34cc commit c6a8a91
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/main/java/ai/nets/samj/models/AbstractSamJ.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ public interface DebugTextPrinter { void printText(String text); }
*/
protected boolean imageSmall = true;

protected abstract void samEverything(List<int[]> grid, boolean returnAll);

protected abstract void processPointsWithSAM(int nPoints, int nNegPoints, boolean returnAll);

protected abstract void processBoxWithSAM(boolean returnAll);
Expand Down Expand Up @@ -365,6 +367,29 @@ else if (task.outputs.get("contours_y") == null)
return polys;
}

public List<Polygon> everything(int objectSize, boolean returnAll)
throws IOException, RuntimeException, InterruptedException {
int encodingSize = OPTIMAL_BBOX_IM_RATIO * objectSize;
long imWidth = this.img.dimensionsAsLongArray()[0];
long imHeight = this.img.dimensionsAsLongArray()[1];
double pointPromptsX = Math.ceil(imWidth / (double) objectSize);
double pointPromptsY = Math.ceil(imHeight / (double) objectSize);
List<int[]> grid = new ArrayList<int[]>();

for (int i = 0; i < pointPromptsX; i ++) {
for (int j = 0; j < pointPromptsX; j ++) {
grid.add(null);
}
}
this.script = "";
samEverything(grid, returnAll);
printScript(script, "SAM-EVERYHING");
List<Polygon> polys = processAndRetrieveContours(null);
recalculatePolys(polys, encodeCoords);
debugPrinter.printText("processBox() obtained " + polys.size() + " polygons");
return polys;
}

/**
* Method used that runs EfficientSAM using a list of points as the prompt. This method runs
* the prompt encoder and the EfficientSAM decoder only, the image encoder was run when the model
Expand Down

0 comments on commit c6a8a91

Please sign in to comment.