From 669035ab41f4113f5d45b364d254160063a020fd Mon Sep 17 00:00:00 2001 From: carlosuc3m <100329787@alumnos.uc3m.es> Date: Mon, 22 Apr 2024 19:06:20 +0200 Subject: [PATCH] keep converging --- src/main/java/ai/nets/samj/EfficientSamJ.java | 9 +++++---- src/main/java/ai/nets/samj/EfficientViTSamJ.java | 11 +++++++---- src/main/java/ai/nets/samj/SamEnvManager.java | 10 +++++++++- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/main/java/ai/nets/samj/EfficientSamJ.java b/src/main/java/ai/nets/samj/EfficientSamJ.java index 52707fb..7d23c5b 100644 --- a/src/main/java/ai/nets/samj/EfficientSamJ.java +++ b/src/main/java/ai/nets/samj/EfficientSamJ.java @@ -235,6 +235,7 @@ else if (task.status == TaskStatus.CRASHED) EfficientSamJ sam = null; try{ sam = new EfficientSamJ(manager); + sam.encodeCoords = new long[] {0, 0}; sam.addImage(image); sam.img = image; } catch (IOException | RuntimeException | InterruptedException ex) { @@ -533,10 +534,10 @@ public List processPoints(List pointsList) public List processPoints(List pointsList, boolean returnAll) throws IOException, RuntimeException, InterruptedException{ Rectangle rect = new Rectangle(); - rect.x = (int) this.encodeCoords[0]; - rect.y = (int) this.encodeCoords[1]; - rect.height = (int) this.targetDims[0]; - rect.width = (int) this.targetDims[1]; + rect.x = -1; + rect.y = -1; + rect.height = -1; + rect.width = -1; return processPoints(pointsList, rect, returnAll); } diff --git a/src/main/java/ai/nets/samj/EfficientViTSamJ.java b/src/main/java/ai/nets/samj/EfficientViTSamJ.java index 7743c1d..0b04d88 100644 --- a/src/main/java/ai/nets/samj/EfficientViTSamJ.java +++ b/src/main/java/ai/nets/samj/EfficientViTSamJ.java @@ -245,6 +245,7 @@ else if (task.status == TaskStatus.CRASHED) EfficientViTSamJ sam = null; try{ sam = new EfficientViTSamJ(manager, modelType, debugPrinter, printPythonCode); + sam.encodeCoords = new long[] {0, 0}; sam.addImage(image); } catch (IOException | RuntimeException | InterruptedException ex) { if (sam != null) sam.close(); @@ -277,6 +278,7 @@ else if (task.status == TaskStatus.CRASHED) EfficientViTSamJ sam = null; try{ sam = new EfficientViTSamJ(manager, modelType); + sam.encodeCoords = new long[] {0, 0}; sam.addImage(image); } catch (IOException | RuntimeException | InterruptedException ex) { if (sam != null) sam.close(); @@ -608,10 +610,10 @@ public List processPoints(List pointsList, List pointsNeg public List processPoints(List pointsList, List pointsNegList, boolean returnAll) throws IOException, RuntimeException, InterruptedException { Rectangle rect = new Rectangle(); - rect.x = (int) this.encodeCoords[0]; - rect.y = (int) this.encodeCoords[1]; - rect.height = (int) this.targetDims[0]; - rect.width = (int) this.targetDims[1]; + rect.x = -1; + rect.y = -1; + rect.height = -1; + rect.width = -1; return processPoints(pointsList, pointsNegList, rect, returnAll); } @@ -1127,6 +1129,7 @@ void adaptImageToModel(final RandomAccessibleInterval ogImg, RandomAccessible throw new IllegalArgumentException("Currently SAMJ only supports 1-channel (grayscale) or 3-channel (RGB, BGR, ...) 2D images." + "The image dimensions order should be 'yxc', first dimension height, second width and third channels."); } + this.img = targetImg; this.targetDims = targetImg.dimensionsAsLongArray(); } diff --git a/src/main/java/ai/nets/samj/SamEnvManager.java b/src/main/java/ai/nets/samj/SamEnvManager.java index da7247e..10090c3 100644 --- a/src/main/java/ai/nets/samj/SamEnvManager.java +++ b/src/main/java/ai/nets/samj/SamEnvManager.java @@ -24,6 +24,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.io.FileOutputStream; +import java.net.HttpURLConnection; import java.net.URISyntaxException; import java.net.URL; import java.nio.channels.Channels; @@ -43,6 +44,7 @@ import io.bioimage.modelrunner.bioimageio.download.DownloadModel; import io.bioimage.modelrunner.engine.installation.FileDownloader; import io.bioimage.modelrunner.system.PlatformDetection; +import io.bioimage.modelrunner.utils.CommonUtils; import org.apache.commons.compress.archivers.ArchiveException; import io.bioimage.modelrunner.apposed.appose.Mamba; @@ -518,6 +520,8 @@ public void downloadEfficientViTSAMWeights(String modelType, boolean force) thro if (progress < 0 || progress > 100) passToConsumer(LocalDateTime.now().format(DATE_FORMAT).toString() + " -- EFFICIENTVITSAM WEIGHTS DOWNLOAD: UNKNOWN%"); else passToConsumer(LocalDateTime.now().format(DATE_FORMAT).toString() + " -- EFFICIENTVITSAM WEIGHTS DOWNLOAD: " + progress + "%"); } + if (size != file.length()) + throw new IOException("Model EfficientViTSAM-" + modelType + " was not correctly downloaded"); } catch (IOException ex) { thread.interrupt(); passToConsumer(LocalDateTime.now().format(DATE_FORMAT).toString() + " -- FAILED EFFICIENTVITSAM WEIGHTS INSTALLATION"); @@ -1159,7 +1163,11 @@ public void downloadFile(String downloadURL, File targetFile, Thread parentThrea ReadableByteChannel rbc = null; try { URL website = new URL(downloadURL); - rbc = Channels.newChannel(website.openStream()); + HttpURLConnection conn = (HttpURLConnection) website.openConnection(); + conn.setRequestMethod("GET"); + conn.setRequestProperty("User-Agent", CommonUtils.getJDLLUserAgent());//"jdll/0.5.6 (Linux; Java 1.8.0_292)"); + rbc = Channels.newChannel(conn.getInputStream()); + // TODO rbc = Channels.newChannel(website.openStream()); // Create the new model file as a zip fos = new FileOutputStream(targetFile); // Send the correct parameters to the progress screen