Skip to content

Commit

Permalink
add fix on bounding boxes and both model types
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed May 29, 2024
1 parent 0798459 commit 6d01190
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/java/ai/nets/samj/models/EfficientSamJ.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ protected void processMasksWithSam(SharedMemoryArray shmArr, boolean returnAll)
+ " predicted_iou = torch.take_along_dim(predicted_iou, sorted_ids, dim=2)" + System.lineSeparator()
+ " predicted_logits = torch.take_along_dim(predicted_logits, sorted_ids[..., None, None], dim=2)" + System.lineSeparator()
+ " mask_val = torch.ge(predicted_logits[0, 0, 0, :, :], 0).cpu().detach().numpy()" + System.lineSeparator()
+ (this.isIJROIManager ? "mask_val[0, 1:, 1:] += mask_val[0, :-1, :-1]" : "") + System.lineSeparator()
+ " cont_x_val,cont_y_val = get_polygons_from_binary_mask(mask_val, only_biggest=" + (!returnAll ? "True" : "False") + ")" + System.lineSeparator()
+ " cont_x += cont_x_val" + System.lineSeparator()
+ " cont_y += cont_y_val" + System.lineSeparator()
Expand Down Expand Up @@ -315,6 +316,7 @@ protected void processPointsWithSAM(int nPoints, int nNegPoints, boolean returnA
+ "task.update('end predict')" + System.lineSeparator()
+ "task.update(str(mask.shape))" + System.lineSeparator()
//+ "np.save('/temp/aa.npy', mask)" + System.lineSeparator()
+ (this.isIJROIManager ? "mask[0, 1:, 1:] += mask[0, :-1, :-1]" : "") + System.lineSeparator()
+ "contours_x,contours_y = get_polygons_from_binary_mask(mask, only_biggest=" + (!returnAll ? "True" : "False") + ")" + System.lineSeparator()
+ "task.update('all contours traced')" + System.lineSeparator()
+ "task.outputs['contours_x'] = contours_x" + System.lineSeparator()
Expand Down Expand Up @@ -345,6 +347,7 @@ protected void processBoxWithSAM(boolean returnAll) {
+ "task.update('end predict')" + System.lineSeparator()
+ "task.update(str(mask.shape))" + System.lineSeparator()
//+ "np.save('/home/carlos/git/mask.npy', mask)" + System.lineSeparator()
+ (this.isIJROIManager ? "mask[0, 1:, 1:] += mask[0, :-1, :-1]" : "") + System.lineSeparator()
+ "contours_x,contours_y = get_polygons_from_binary_mask(mask, only_biggest=" + (!returnAll ? "True" : "False") + ")" + System.lineSeparator()
+ "task.update('all contours traced')" + System.lineSeparator()
+ "task.outputs['contours_x'] = contours_x" + System.lineSeparator()
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/ai/nets/samj/models/EfficientViTSamJ.java
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ protected void processMasksWithSam(SharedMemoryArray shmArr, boolean returnAll)
+ " multimask_output=False," + System.lineSeparator()
+ " box=None,)" + System.lineSeparator()
//+ "np.save('/temp/aa.npy', mask)" + System.lineSeparator()
+ (this.isIJROIManager ? "mask_val[0, 1:, 1:] += mask_val[0, :-1, :-1]" : "") + System.lineSeparator()
+ " contours_x_val,contours_y_val = get_polygons_from_binary_mask(mask_val[0], only_biggest=" + (!returnAll ? "True" : "False") + ")" + System.lineSeparator()
+ " contours_x += contours_x_val" + System.lineSeparator()
+ " contours_y += contours_y_val" + System.lineSeparator()
Expand Down Expand Up @@ -433,6 +434,7 @@ protected void processBoxWithSAM(boolean returnAll) {
+ "task.update('end predict')" + System.lineSeparator()
+ "task.update(str(mask.shape))" + System.lineSeparator()
//+ "np.save('/home/carlos/git/mask.npy', mask)" + System.lineSeparator()
+ (this.isIJROIManager ? "mask[0, 1:, 1:] += mask[0, :-1, :-1]" : "") + System.lineSeparator()
+ "contours_x,contours_y = get_polygons_from_binary_mask(mask[0], only_biggest=" + (!returnAll ? "True" : "False") + ")" + System.lineSeparator()
+ "task.update('all contours traced')" + System.lineSeparator()
+ "task.outputs['contours_x'] = contours_x" + System.lineSeparator()
Expand Down

0 comments on commit 6d01190

Please sign in to comment.