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 0e92635..714faaa 100644 --- a/src/main/java/io/bioimage/modelrunner/pytorch/javacpp/PytorchJavaCPPInterface.java +++ b/src/main/java/io/bioimage/modelrunner/pytorch/javacpp/PytorchJavaCPPInterface.java @@ -57,11 +57,14 @@ 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.loops.LoopBuilder; 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 @@ -316,8 +319,30 @@ else if (task.status == TaskStatus.CRASHED) { shm = SharedMemoryArray.read(name); shmaOutputList.add(shm); } - RandomAccessibleInterval rai = shm.getSharedRAI(); + RandomAccessibleInterval rai = shm.getSharedRAI(); + // 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(); 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 7067f36..cd4a0dc 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 @@ -23,7 +23,9 @@ import io.bioimage.modelrunner.tensor.shm.SharedMemoryArray; import io.bioimage.modelrunner.utils.CommonUtils; +import net.imglib2.Cursor; import net.imglib2.util.Cast; +import net.imglib2.view.Views; import java.nio.ByteBuffer; import java.util.Arrays; @@ -139,6 +141,15 @@ 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; }