From 704447f194de506e996844a446f2241618ba32b7 Mon Sep 17 00:00:00 2001 From: carlosuc3m <100329787@alumnos.uc3m.es> Date: Fri, 20 Dec 2024 13:06:12 +0100 Subject: [PATCH] remove prints --- .../javacpp/PytorchJavaCPPInterface.java | 47 ++----------------- .../pytorch/javacpp/shm/TensorBuilder.java | 9 ---- 2 files changed, 5 insertions(+), 51 deletions(-) diff --git a/src/main/java/io/bioimage/modelrunner/pytorch/javacpp/PytorchJavaCPPInterface.java b/src/main/java/io/bioimage/modelrunner/pytorch/javacpp/PytorchJavaCPPInterface.java index c8d156a..4cd6a11 100644 --- a/src/main/java/io/bioimage/modelrunner/pytorch/javacpp/PytorchJavaCPPInterface.java +++ b/src/main/java/io/bioimage/modelrunner/pytorch/javacpp/PytorchJavaCPPInterface.java @@ -29,7 +29,6 @@ import java.nio.charset.StandardCharsets; import java.security.ProtectionDomain; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.LinkedList; @@ -58,13 +57,11 @@ import io.bioimage.modelrunner.tensor.Tensor; import io.bioimage.modelrunner.tensor.shm.SharedMemoryArray; import io.bioimage.modelrunner.utils.CommonUtils; -import net.imglib2.Cursor; import net.imglib2.RandomAccessibleInterval; import net.imglib2.type.NativeType; import net.imglib2.type.numeric.RealType; import net.imglib2.util.Cast; import net.imglib2.util.Util; -import net.imglib2.view.Views; /** * This class implements an interface that allows the main plugin to interact in @@ -190,11 +187,11 @@ private void launchModelLoadOnProcess() throws IOException, InterruptedException if (task.status == TaskStatus.CANCELED) throw new RuntimeException(); else if (task.status == TaskStatus.FAILED) - throw new RuntimeException(); + throw new RuntimeException(task.error); else if (task.status == TaskStatus.CRASHED) { this.runner.close(); runner = null; - throw new RuntimeException(); + throw new RuntimeException(task.error); } } @@ -245,7 +242,6 @@ protected void runFromShmas(List inputs, List outputs) throws IO IValueVector inputsVector = new IValueVector(); for (String ee : inputs) { Map decoded = Types.decode(ee); - System.out.println("MM: -> " + ee); SharedMemoryArray shma = SharedMemoryArray.read((String) decoded.get(MEM_NAME_KEY)); org.bytedeco.pytorch.Tensor inT = TensorBuilder.build(shma); inputsVector.put(new IValue(inT)); @@ -310,7 +306,7 @@ else if (task.status == TaskStatus.FAILED) else if (task.status == TaskStatus.CRASHED) { this.runner.close(); runner = null; - throw new RuntimeException(); + throw new RuntimeException(task.error); } for (int i = 0; i < outputTensors.size(); i ++) { String name = (String) Types.decode(encOuts.get(i)).get(MEM_NAME_KEY); @@ -321,30 +317,7 @@ else if (task.status == TaskStatus.CRASHED) { shmaOutputList.add(shm); } RandomAccessibleInterval rai = shm.getSharedRAI(); - System.out.println("Output size: " + Arrays.toString(rai.dimensionsAsLongArray())); - // TODO remove - double max0 = 0; - Cursor iter0 = Views.iterable(rai).cursor(); - while (iter0.hasNext()) { - iter0.next(); - double doub = iter0.get().getRealDouble(); - if (doub > max0) - max0 = doub; - } - System.out.println("Output SHM " + i + " max value: " + max0); - // TODO remove outputTensors.get(i).setData(Tensor.createCopyOfRaiInWantedDataType(Cast.unchecked(rai), Util.getTypeFromInterval(Cast.unchecked(rai)))); - // TODO remove - double max = 0; - Cursor iter = Views.iterable(outputTensors.get(i).getData()).cursor(); - while (iter.hasNext()) { - iter.next(); - double doub = iter.get().getRealDouble(); - if (doub > max) - max = doub; - } - System.out.println("Copied ouput " + i + " max value: " + max); - // TODO remove } } catch (Exception e) { closeShmas(); @@ -385,11 +358,11 @@ public void closeModel() { if (task.status == TaskStatus.CANCELED) throw new RuntimeException(); else if (task.status == TaskStatus.FAILED) - throw new RuntimeException(); + throw new RuntimeException(task.error); else if (task.status == TaskStatus.CRASHED) { this.runner.close(); runner = null; - throw new RuntimeException(); + throw new RuntimeException(task.error); } this.runner.close(); this.runner = null; @@ -432,16 +405,6 @@ private & NativeType> List encodeInputs(List encodedInputTensors = new ArrayList(); Gson gson = new Gson(); for (Tensor tt : inputTensors) { - System.out.println("Input size: " + Arrays.toString(tt.getData().dimensionsAsLongArray())); - double max0 = 0; - Cursor iter0 = Views.iterable(tt.getData()).cursor(); - while (iter0.hasNext()) { - iter0.next(); - double doub = iter0.get().getRealDouble(); - if (doub > max0) - max0 = doub; - } - System.out.println("Input max: " + max0); SharedMemoryArray shma = SharedMemoryArray.createSHMAFromRAI(tt.getData(), false, true); shmaInputList.add(shma); HashMap map = new HashMap(); diff --git a/src/main/java/io/bioimage/modelrunner/pytorch/javacpp/shm/TensorBuilder.java b/src/main/java/io/bioimage/modelrunner/pytorch/javacpp/shm/TensorBuilder.java index eef30bd..ff3d3f3 100644 --- a/src/main/java/io/bioimage/modelrunner/pytorch/javacpp/shm/TensorBuilder.java +++ b/src/main/java/io/bioimage/modelrunner/pytorch/javacpp/shm/TensorBuilder.java @@ -139,15 +139,6 @@ private static org.bytedeco.pytorch.Tensor buildFloat(SharedMemoryArray shmArray float[] flat = new float[buff.capacity() / 4]; buff.asFloatBuffer().get(flat); Tensor ndarray = Tensor.create(flat, ogShape); - - // TODO remove - double max0 = 0; - for (float ff : flat) { - if (ff > max0) - max0 = ff; - } - System.out.println("Input max: " + max0); - // TODO remove return ndarray; }