From f0b1d321ffa61f785e9a4148a0693cff1dffaa81 Mon Sep 17 00:00:00 2001 From: carlosuc3m <100329787@alumnos.uc3m.es> Date: Mon, 9 Dec 2024 19:55:31 +0100 Subject: [PATCH] correct one bug for macos --- src/main/java/ai/nets/samj/models/EfficientSamJ.java | 9 +++++++-- src/main/java/ai/nets/samj/models/EfficientViTSamJ.java | 9 +++++++-- src/main/java/ai/nets/samj/models/Sam2.java | 9 +++++++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/main/java/ai/nets/samj/models/EfficientSamJ.java b/src/main/java/ai/nets/samj/models/EfficientSamJ.java index d2688d3..dbd672f 100644 --- a/src/main/java/ai/nets/samj/models/EfficientSamJ.java +++ b/src/main/java/ai/nets/samj/models/EfficientSamJ.java @@ -410,9 +410,14 @@ protected void processPromptsBatchWithSAM(SharedMemoryArray shmArr, if (shmArr != null) { code += "" + "shm_mask = shared_memory.SharedMemory(name='" + shmArr.getNameForPython() + "')" + System.lineSeparator() - + "mask_batch = np.frombuffer(buffer=shm_mask.buf, dtype='" + shmArr.getOriginalDataType() + "').reshape(["; - for (long l : shmArr.getOriginalShape()) + + "mask_batch = np.ndarray(%s, buffer=shm_mask.buf, dtype='" + + shmArr.getOriginalDataType() + "').reshape(["; + long size = 1; + for (long l : shmArr.getOriginalShape()) { code += l + ","; + size *= l; + } + code = String.format(code, size); code += "])" + System.lineSeparator(); code += "labeled_array, num_features = label(mask_batch)" + System.lineSeparator(); code += "num_features -= 1" + System.lineSeparator(); diff --git a/src/main/java/ai/nets/samj/models/EfficientViTSamJ.java b/src/main/java/ai/nets/samj/models/EfficientViTSamJ.java index 919c497..881e4bd 100644 --- a/src/main/java/ai/nets/samj/models/EfficientViTSamJ.java +++ b/src/main/java/ai/nets/samj/models/EfficientViTSamJ.java @@ -491,9 +491,14 @@ protected void processPromptsBatchWithSAM(SharedMemoryArray shmArr, if (shmArr != null) { code += "" + "shm_mask = shared_memory.SharedMemory(name='" + shmArr.getNameForPython() + "')" + System.lineSeparator() - + "mask_batch = np.frombuffer(buffer=shm_mask.buf, dtype='" + shmArr.getOriginalDataType() + "').reshape(["; - for (long l : shmArr.getOriginalShape()) + + "mask_batch = np.ndarray(%s, buffer=shm_mask.buf, dtype='" + + shmArr.getOriginalDataType() + "').reshape(["; + long size = 1; + for (long l : shmArr.getOriginalShape()) { code += l + ","; + size *= l; + } + code = String.format(code, size); code += "])" + System.lineSeparator(); code += "labeled_array, num_features = label(mask_batch)" + System.lineSeparator(); code += "num_features -= 1" + System.lineSeparator(); diff --git a/src/main/java/ai/nets/samj/models/Sam2.java b/src/main/java/ai/nets/samj/models/Sam2.java index f934074..520241f 100644 --- a/src/main/java/ai/nets/samj/models/Sam2.java +++ b/src/main/java/ai/nets/samj/models/Sam2.java @@ -465,9 +465,14 @@ protected void processPromptsBatchWithSAM(SharedMemoryArray shmArr, boolean retu if (shmArr != null) { code += "" + "shm_mask = shared_memory.SharedMemory(name='" + shmArr.getNameForPython() + "')" + System.lineSeparator() - + "mask_batch = np.frombuffer(buffer=shm_mask.buf, dtype='" + shmArr.getOriginalDataType() + "').reshape(["; - for (long l : shmArr.getOriginalShape()) + + "mask_batch = np.ndarray(%s, buffer=shm_mask.buf, dtype='" + + shmArr.getOriginalDataType() + "').reshape(["; + long size = 1; + for (long l : shmArr.getOriginalShape()) { code += l + ","; + size *= l; + } + code = String.format(code, size); code += "])" + System.lineSeparator(); code += "labeled_array, num_features = label(mask_batch)" + System.lineSeparator(); code += "num_features -= 1" + System.lineSeparator();