From e62fe2ddd9a1c0e6b73cf4d605f0a0632dce75b3 Mon Sep 17 00:00:00 2001 From: carlosuc3m <100329787@alumnos.uc3m.es> Date: Tue, 3 Dec 2024 01:44:35 +0100 Subject: [PATCH] correct a couple of details about the logic --- src/main/java/ai/nets/samj/gui/MainGUI.java | 2 ++ src/main/java/ai/nets/samj/models/Sam2.java | 7 ------- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/main/java/ai/nets/samj/gui/MainGUI.java b/src/main/java/ai/nets/samj/gui/MainGUI.java index b4a5948..4043f24 100644 --- a/src/main/java/ai/nets/samj/gui/MainGUI.java +++ b/src/main/java/ai/nets/samj/gui/MainGUI.java @@ -199,6 +199,7 @@ private void loadModel() { consumer.setFocusedImage(cmbImages.getSelectedObject()); consumer.setModel(cmbModels.getSelectedModel()); setInstantPromptsEnabled(this.chkInstant.isSelected()); + cmbModels.getSelectedModel().setReturnOnlyBiggest(retunLargest.isSelected()); setTwoThirdsEnabled(true); } catch (IOException | RuntimeException | InterruptedException ex) { ex.printStackTrace(); @@ -392,6 +393,7 @@ private JPanel createSecondComponent() { CardLayout cl = (CardLayout) (cardPanel.getLayout()); cl.show(cardPanel, PRESET_STR); this.chkInstant.setSelected(false); + setInstantPromptsEnabled(false); }); GridBagConstraints gbc = new GridBagConstraints(); diff --git a/src/main/java/ai/nets/samj/models/Sam2.java b/src/main/java/ai/nets/samj/models/Sam2.java index 58b351b..6330c74 100644 --- a/src/main/java/ai/nets/samj/models/Sam2.java +++ b/src/main/java/ai/nets/samj/models/Sam2.java @@ -80,11 +80,9 @@ public class Sam2 extends AbstractSamJ { + "import sys" + System.lineSeparator() + "import os" + System.lineSeparator() + "from multiprocessing import shared_memory" + System.lineSeparator() - + "task.update('import sam')" + System.lineSeparator() + "from sam2.build_sam import build_sam2" + System.lineSeparator() + "from sam2.sam2_image_predictor import SAM2ImagePredictor" + System.lineSeparator() + "from sam2.utils.misc import variant_to_config_mapping" + System.lineSeparator() - + "task.update('imported')" + System.lineSeparator() + "model = build_sam2(variant_to_config_mapping['%s'],r'%s')" + System.lineSeparator() + "predictor = SAM2ImagePredictor(model)" + System.lineSeparator() + "task.update('created predictor')" + System.lineSeparator() @@ -303,7 +301,6 @@ protected void createEncodeImageScript() { script += "im_shm.unlink()" + System.lineSeparator(); //code += "box_shm.close()" + System.lineSeparator(); script += "" - + "task.update(str(im.shape))" + System.lineSeparator() + "predictor.set_image(im)"; } @@ -336,8 +333,6 @@ protected void processPointsWithSAM(int nPoints, int nNegPoints, boolean returnA + " point_labels=input_label," + System.lineSeparator() + " multimask_output=False," + System.lineSeparator() + " box=None,)" + System.lineSeparator() - + "task.update('end predict')" + System.lineSeparator() - + "task.update(str(mask.shape))" + System.lineSeparator() + (this.isIJROIManager ? "mask[0, 1:, 1:] += mask[0, :-1, :-1]" : "") + System.lineSeparator() + "contours_x, contours_y, rle_masks = get_polygons_from_binary_mask(mask[0], only_biggest=" + (!returnAll ? "True" : "False") + ")" + System.lineSeparator() + "task.update('all contours traced')" + System.lineSeparator() @@ -357,8 +352,6 @@ protected void processBoxWithSAM(boolean returnAll) { + " point_labels=None," + System.lineSeparator() + " multimask_output=False," + System.lineSeparator() + " box=input_box,)" + System.lineSeparator() - + "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, rle_masks = get_polygons_from_binary_mask(mask[0], only_biggest=" + (!returnAll ? "True" : "False") + ")" + System.lineSeparator()