Skip to content

Commit

Permalink
improve javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Oct 1, 2024
1 parent 4dfa7d3 commit f2b7ce3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -78,37 +73,7 @@ public static <T extends Type<T>> RandomAccessibleInterval<T> 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<UnsignedByteType> 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<UnsignedByteType> 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<ByteType> buildFromTensorByte(org.bytedeco.pytorch.Tensor tensor)
private static RandomAccessibleInterval<ByteType> buildFromTensorByte(org.bytedeco.pytorch.Tensor tensor)
{
long[] arrayShape = tensor.shape();
if (CommonUtils.int32Overflows(arrayShape, 1))
Expand All @@ -124,14 +89,7 @@ public static RandomAccessibleInterval<ByteType> 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<IntType> buildFromTensorInt(org.bytedeco.pytorch.Tensor tensor)
private static RandomAccessibleInterval<IntType> buildFromTensorInt(org.bytedeco.pytorch.Tensor tensor)
{
long[] arrayShape = tensor.shape();
if (CommonUtils.int32Overflows(arrayShape, 4))
Expand All @@ -147,14 +105,7 @@ public static RandomAccessibleInterval<IntType> 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<FloatType> buildFromTensorFloat(org.bytedeco.pytorch.Tensor tensor)
private static RandomAccessibleInterval<FloatType> buildFromTensorFloat(org.bytedeco.pytorch.Tensor tensor)
{
long[] arrayShape = tensor.shape();
if (CommonUtils.int32Overflows(arrayShape, 4))
Expand All @@ -170,14 +121,7 @@ public static RandomAccessibleInterval<FloatType> 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<DoubleType> buildFromTensorDouble(org.bytedeco.pytorch.Tensor tensor)
private static RandomAccessibleInterval<DoubleType> buildFromTensorDouble(org.bytedeco.pytorch.Tensor tensor)
{
long[] arrayShape = tensor.shape();
if (CommonUtils.int32Overflows(arrayShape, 8))
Expand All @@ -193,14 +137,7 @@ public static RandomAccessibleInterval<DoubleType> 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<LongType> buildFromTensorLong(org.bytedeco.pytorch.Tensor tensor)
private static RandomAccessibleInterval<LongType> buildFromTensorLong(org.bytedeco.pytorch.Tensor tensor)
{
long[] arrayShape = tensor.shape();
if (CommonUtils.int32Overflows(arrayShape, 8))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ByteType> tensor)
{
long[] ogShape = tensor.dimensionsAsLongArray();
Expand All @@ -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<IntType> tensor)
{
long[] ogShape = tensor.dimensionsAsLongArray();
Expand All @@ -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<FloatType> tensor)
{
long[] ogShape = tensor.dimensionsAsLongArray();
Expand All @@ -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<DoubleType> tensor)
{
long[] ogShape = tensor.dimensionsAsLongArray();
Expand Down

0 comments on commit f2b7ce3

Please sign in to comment.