From f2b7ce3068d4e700f3ddcff9446e2735c90f58e8 Mon Sep 17 00:00:00 2001 From: carlosuc3m <100329787@alumnos.uc3m.es> Date: Tue, 1 Oct 2024 18:19:00 +0200 Subject: [PATCH] improve javadoc --- .../pytorch/javacpp/JavaWorker.java | 6 ++ .../javacpp/tensor/ImgLib2Builder.java | 73 ++----------------- .../javacpp/tensor/JavaCPPTensorBuilder.java | 32 -------- 3 files changed, 11 insertions(+), 100 deletions(-) diff --git a/src/main/java/io/bioimage/modelrunner/pytorch/javacpp/JavaWorker.java b/src/main/java/io/bioimage/modelrunner/pytorch/javacpp/JavaWorker.java index da7b605..adb98cc 100644 --- a/src/main/java/io/bioimage/modelrunner/pytorch/javacpp/JavaWorker.java +++ b/src/main/java/io/bioimage/modelrunner/pytorch/javacpp/JavaWorker.java @@ -22,6 +22,12 @@ public class JavaWorker { private boolean cancelRequested = false; + /** + * Method in the child process that is in charge of keeping the process open and calling the model load, + * model inference and model closing + * @param args + * args of the parent process + */ public static void main(String[] args) { try(Scanner scanner = new Scanner(System.in)){ diff --git a/src/main/java/io/bioimage/modelrunner/pytorch/javacpp/tensor/ImgLib2Builder.java b/src/main/java/io/bioimage/modelrunner/pytorch/javacpp/tensor/ImgLib2Builder.java index 76236a6..f1c2786 100644 --- a/src/main/java/io/bioimage/modelrunner/pytorch/javacpp/tensor/ImgLib2Builder.java +++ b/src/main/java/io/bioimage/modelrunner/pytorch/javacpp/tensor/ImgLib2Builder.java @@ -25,17 +25,12 @@ import io.bioimage.modelrunner.tensor.Utils; import io.bioimage.modelrunner.utils.CommonUtils; -import io.bioimage.modelrunner.utils.IndexingUtils; -import net.imglib2.Cursor; import net.imglib2.RandomAccessibleInterval; -import net.imglib2.img.Img; -import net.imglib2.img.array.ArrayImgFactory; import net.imglib2.img.array.ArrayImgs; import net.imglib2.type.Type; import net.imglib2.type.numeric.integer.ByteType; import net.imglib2.type.numeric.integer.IntType; import net.imglib2.type.numeric.integer.LongType; -import net.imglib2.type.numeric.integer.UnsignedByteType; import net.imglib2.type.numeric.real.DoubleType; import net.imglib2.type.numeric.real.FloatType; @@ -78,37 +73,7 @@ public static > RandomAccessibleInterval build(org.bytedeco } } - /** - * Builds a {@link RandomAccessibleInterval} from a unsigned byte-typed {@link org.bytedeco.pytorch.Tensor}. - * - * @param tensor - * The {@link org.bytedeco.pytorch.Tensor} data is read from. - * @return The {@link RandomAccessibleInterval} built from the tensor of type {@link UnsignedByteType}. - */ - public static RandomAccessibleInterval buildFromTensorUByte(org.bytedeco.pytorch.Tensor tensor) { - long[] arrayShape = tensor.shape(); - if (CommonUtils.int32Overflows(arrayShape, 1)) - throw new IllegalArgumentException("Model output tensor with shape " + Arrays.toString(arrayShape) - + " is too big. Max number of elements per ubyte output tensor supported: " + Integer.MAX_VALUE / 1); - long[] tensorShape = new long[arrayShape.length]; - for (int i = 0; i < arrayShape.length; i ++) tensorShape[i] = arrayShape[arrayShape.length - 1 - i]; - long flatSize = 1; - for (long l : tensorShape) {flatSize *= l;} - byte[] flatArr = new byte[(int) flatSize]; - tensor.data_ptr_byte().get(flatArr); - RandomAccessibleInterval rai = ArrayImgs.unsignedBytes(flatArr, tensorShape); - return Utils.transpose(rai); - } - - - /** - * Builds a {@link RandomAccessibleInterval} from a signed byte-typed {@link org.bytedeco.pytorch.Tensor}. - * - * @param tensor - * The {@link org.bytedeco.pytorch.Tensor} data is read from. - * @return The {@link RandomAccessibleInterval} built from the tensor of type {@link ByteType}. - */ - public static RandomAccessibleInterval buildFromTensorByte(org.bytedeco.pytorch.Tensor tensor) + private static RandomAccessibleInterval buildFromTensorByte(org.bytedeco.pytorch.Tensor tensor) { long[] arrayShape = tensor.shape(); if (CommonUtils.int32Overflows(arrayShape, 1)) @@ -124,14 +89,7 @@ public static RandomAccessibleInterval buildFromTensorByte(org.bytedec return Utils.transpose(rai); } - /** - * Builds a {@link RandomAccessibleInterval} from a signed integer-typed {@link org.bytedeco.pytorch.Tensor}. - * - * @param tensor - * The {@link org.bytedeco.pytorch.Tensor} data is read from. - * @return The {@link RandomAccessibleInterval} built from the tensor of type {@link IntType}. - */ - public static RandomAccessibleInterval buildFromTensorInt(org.bytedeco.pytorch.Tensor tensor) + private static RandomAccessibleInterval buildFromTensorInt(org.bytedeco.pytorch.Tensor tensor) { long[] arrayShape = tensor.shape(); if (CommonUtils.int32Overflows(arrayShape, 4)) @@ -147,14 +105,7 @@ public static RandomAccessibleInterval buildFromTensorInt(org.bytedeco. return Utils.transpose(rai); } - /** - * Builds a {@link RandomAccessibleInterval} from a signed float-typed {@link org.bytedeco.pytorch.Tensor}. - * - * @param tensor - * The {@link org.bytedeco.pytorch.Tensor} data is read from. - * @return The {@link RandomAccessibleInterval} built from the tensor of type {@link FloatType}. - */ - public static RandomAccessibleInterval buildFromTensorFloat(org.bytedeco.pytorch.Tensor tensor) + private static RandomAccessibleInterval buildFromTensorFloat(org.bytedeco.pytorch.Tensor tensor) { long[] arrayShape = tensor.shape(); if (CommonUtils.int32Overflows(arrayShape, 4)) @@ -170,14 +121,7 @@ public static RandomAccessibleInterval buildFromTensorFloat(org.byted return Utils.transpose(rai); } - /** - * Builds a {@link RandomAccessibleInterval} from a signed double-typed {@link org.bytedeco.pytorch.Tensor}. - * - * @param tensor - * The {@link org.bytedeco.pytorch.Tensor} data is read from. - * @return The {@link RandomAccessibleInterval} built from the tensor of type {@link DoubleType}. - */ - public static RandomAccessibleInterval buildFromTensorDouble(org.bytedeco.pytorch.Tensor tensor) + private static RandomAccessibleInterval buildFromTensorDouble(org.bytedeco.pytorch.Tensor tensor) { long[] arrayShape = tensor.shape(); if (CommonUtils.int32Overflows(arrayShape, 8)) @@ -193,14 +137,7 @@ public static RandomAccessibleInterval buildFromTensorDouble(org.byt return Utils.transpose(rai); } - /** - * Builds a {@link RandomAccessibleInterval} from a signed long-typed {@link org.bytedeco.pytorch.Tensor}. - * - * @param tensor - * The {@link org.bytedeco.pytorch.Tensor} data is read from. - * @return The {@link RandomAccessibleInterval} built from the tensor of type {@link LongType}. - */ - public static RandomAccessibleInterval buildFromTensorLong(org.bytedeco.pytorch.Tensor tensor) + private static RandomAccessibleInterval buildFromTensorLong(org.bytedeco.pytorch.Tensor tensor) { long[] arrayShape = tensor.shape(); if (CommonUtils.int32Overflows(arrayShape, 8)) diff --git a/src/main/java/io/bioimage/modelrunner/pytorch/javacpp/tensor/JavaCPPTensorBuilder.java b/src/main/java/io/bioimage/modelrunner/pytorch/javacpp/tensor/JavaCPPTensorBuilder.java index a623eb4..970f15d 100644 --- a/src/main/java/io/bioimage/modelrunner/pytorch/javacpp/tensor/JavaCPPTensorBuilder.java +++ b/src/main/java/io/bioimage/modelrunner/pytorch/javacpp/tensor/JavaCPPTensorBuilder.java @@ -88,14 +88,6 @@ public static < T extends RealType< T > & NativeType< T > > org.bytedeco.pytorch } } - /** - * Builds a {@link org.bytedeco.pytorch.Tensor} from a signed byte-typed - * {@link RandomAccessibleInterval}. - * - * @param tensor - * the {@link RandomAccessibleInterval} that will be copied into an {@link org.bytedeco.pytorch.Tensor} - * @return The {@link org.bytedeco.pytorch.Tensor} built from the tensor of type {@link ByteType}. - */ private static org.bytedeco.pytorch.Tensor buildFromTensorByte(RandomAccessibleInterval tensor) { long[] ogShape = tensor.dimensionsAsLongArray(); @@ -121,14 +113,6 @@ private static org.bytedeco.pytorch.Tensor buildFromTensorByte(RandomAccessibleI return ndarray; } - /** - * Builds a {@link org.bytedeco.pytorch.Tensor} from a signed integer-typed - * {@link RandomAccessibleInterval}. - * - * @param tensor - * the {@link RandomAccessibleInterval} that will be copied into an {@link org.bytedeco.pytorch.Tensor} - * @return The {@link org.bytedeco.pytorch.Tensor} built from the tensor of type {@link IntType}. - */ private static org.bytedeco.pytorch.Tensor buildFromTensorInt(RandomAccessibleInterval tensor) { long[] ogShape = tensor.dimensionsAsLongArray(); @@ -154,14 +138,6 @@ private static org.bytedeco.pytorch.Tensor buildFromTensorInt(RandomAccessibleIn return ndarray; } - /** - * Builds a {@link org.bytedeco.pytorch.Tensor} from a signed float-typed - * {@link RandomAccessibleInterval}. - * - * @param tensor - * the {@link RandomAccessibleInterval} that will be copied into an {@link org.bytedeco.pytorch.Tensor} - * @return The {@link org.bytedeco.pytorch.Tensor} built from the tensor of type {@link FloatType}. - */ private static org.bytedeco.pytorch.Tensor buildFromTensorFloat(RandomAccessibleInterval tensor) { long[] ogShape = tensor.dimensionsAsLongArray(); @@ -187,14 +163,6 @@ private static org.bytedeco.pytorch.Tensor buildFromTensorFloat(RandomAccessible return ndarray; } - /** - * Builds a {@link org.bytedeco.pytorch.Tensor} from a signed double-typed - * {@link RandomAccessibleInterval}. - * - * @param tensor - * the {@link RandomAccessibleInterval} that will be copied into an {@link NDArray} - * @return The {@link org.bytedeco.pytorch.Tensor} built from the tensor of type {@link DoubleType}. - */ private static org.bytedeco.pytorch.Tensor buildFromTensorDouble(RandomAccessibleInterval tensor) { long[] ogShape = tensor.dimensionsAsLongArray();