2525
2626import io .bioimage .modelrunner .tensor .Utils ;
2727import io .bioimage .modelrunner .utils .CommonUtils ;
28- import io .bioimage .modelrunner .utils .IndexingUtils ;
29- import net .imglib2 .Cursor ;
3028import net .imglib2 .RandomAccessibleInterval ;
31- import net .imglib2 .img .Img ;
32- import net .imglib2 .img .array .ArrayImgFactory ;
3329import net .imglib2 .img .array .ArrayImgs ;
3430import net .imglib2 .type .Type ;
3531import net .imglib2 .type .numeric .integer .ByteType ;
3632import net .imglib2 .type .numeric .integer .IntType ;
3733import net .imglib2 .type .numeric .integer .LongType ;
38- import net .imglib2 .type .numeric .integer .UnsignedByteType ;
3934import net .imglib2 .type .numeric .real .DoubleType ;
4035import net .imglib2 .type .numeric .real .FloatType ;
4136
@@ -78,37 +73,7 @@ public static <T extends Type<T>> RandomAccessibleInterval<T> build(org.bytedeco
7873 }
7974 }
8075
81- /**
82- * Builds a {@link RandomAccessibleInterval} from a unsigned byte-typed {@link org.bytedeco.pytorch.Tensor}.
83- *
84- * @param tensor
85- * The {@link org.bytedeco.pytorch.Tensor} data is read from.
86- * @return The {@link RandomAccessibleInterval} built from the tensor of type {@link UnsignedByteType}.
87- */
88- public static RandomAccessibleInterval <UnsignedByteType > buildFromTensorUByte (org .bytedeco .pytorch .Tensor tensor ) {
89- long [] arrayShape = tensor .shape ();
90- if (CommonUtils .int32Overflows (arrayShape , 1 ))
91- throw new IllegalArgumentException ("Model output tensor with shape " + Arrays .toString (arrayShape )
92- + " is too big. Max number of elements per ubyte output tensor supported: " + Integer .MAX_VALUE / 1 );
93- long [] tensorShape = new long [arrayShape .length ];
94- for (int i = 0 ; i < arrayShape .length ; i ++) tensorShape [i ] = arrayShape [arrayShape .length - 1 - i ];
95- long flatSize = 1 ;
96- for (long l : tensorShape ) {flatSize *= l ;}
97- byte [] flatArr = new byte [(int ) flatSize ];
98- tensor .data_ptr_byte ().get (flatArr );
99- RandomAccessibleInterval <UnsignedByteType > rai = ArrayImgs .unsignedBytes (flatArr , tensorShape );
100- return Utils .transpose (rai );
101- }
102-
103-
104- /**
105- * Builds a {@link RandomAccessibleInterval} from a signed byte-typed {@link org.bytedeco.pytorch.Tensor}.
106- *
107- * @param tensor
108- * The {@link org.bytedeco.pytorch.Tensor} data is read from.
109- * @return The {@link RandomAccessibleInterval} built from the tensor of type {@link ByteType}.
110- */
111- public static RandomAccessibleInterval <ByteType > buildFromTensorByte (org .bytedeco .pytorch .Tensor tensor )
76+ private static RandomAccessibleInterval <ByteType > buildFromTensorByte (org .bytedeco .pytorch .Tensor tensor )
11277 {
11378 long [] arrayShape = tensor .shape ();
11479 if (CommonUtils .int32Overflows (arrayShape , 1 ))
@@ -124,14 +89,7 @@ public static RandomAccessibleInterval<ByteType> buildFromTensorByte(org.bytedec
12489 return Utils .transpose (rai );
12590 }
12691
127- /**
128- * Builds a {@link RandomAccessibleInterval} from a signed integer-typed {@link org.bytedeco.pytorch.Tensor}.
129- *
130- * @param tensor
131- * The {@link org.bytedeco.pytorch.Tensor} data is read from.
132- * @return The {@link RandomAccessibleInterval} built from the tensor of type {@link IntType}.
133- */
134- public static RandomAccessibleInterval <IntType > buildFromTensorInt (org .bytedeco .pytorch .Tensor tensor )
92+ private static RandomAccessibleInterval <IntType > buildFromTensorInt (org .bytedeco .pytorch .Tensor tensor )
13593 {
13694 long [] arrayShape = tensor .shape ();
13795 if (CommonUtils .int32Overflows (arrayShape , 4 ))
@@ -147,14 +105,7 @@ public static RandomAccessibleInterval<IntType> buildFromTensorInt(org.bytedeco.
147105 return Utils .transpose (rai );
148106 }
149107
150- /**
151- * Builds a {@link RandomAccessibleInterval} from a signed float-typed {@link org.bytedeco.pytorch.Tensor}.
152- *
153- * @param tensor
154- * The {@link org.bytedeco.pytorch.Tensor} data is read from.
155- * @return The {@link RandomAccessibleInterval} built from the tensor of type {@link FloatType}.
156- */
157- public static RandomAccessibleInterval <FloatType > buildFromTensorFloat (org .bytedeco .pytorch .Tensor tensor )
108+ private static RandomAccessibleInterval <FloatType > buildFromTensorFloat (org .bytedeco .pytorch .Tensor tensor )
158109 {
159110 long [] arrayShape = tensor .shape ();
160111 if (CommonUtils .int32Overflows (arrayShape , 4 ))
@@ -170,14 +121,7 @@ public static RandomAccessibleInterval<FloatType> buildFromTensorFloat(org.byted
170121 return Utils .transpose (rai );
171122 }
172123
173- /**
174- * Builds a {@link RandomAccessibleInterval} from a signed double-typed {@link org.bytedeco.pytorch.Tensor}.
175- *
176- * @param tensor
177- * The {@link org.bytedeco.pytorch.Tensor} data is read from.
178- * @return The {@link RandomAccessibleInterval} built from the tensor of type {@link DoubleType}.
179- */
180- public static RandomAccessibleInterval <DoubleType > buildFromTensorDouble (org .bytedeco .pytorch .Tensor tensor )
124+ private static RandomAccessibleInterval <DoubleType > buildFromTensorDouble (org .bytedeco .pytorch .Tensor tensor )
181125 {
182126 long [] arrayShape = tensor .shape ();
183127 if (CommonUtils .int32Overflows (arrayShape , 8 ))
@@ -193,14 +137,7 @@ public static RandomAccessibleInterval<DoubleType> buildFromTensorDouble(org.byt
193137 return Utils .transpose (rai );
194138 }
195139
196- /**
197- * Builds a {@link RandomAccessibleInterval} from a signed long-typed {@link org.bytedeco.pytorch.Tensor}.
198- *
199- * @param tensor
200- * The {@link org.bytedeco.pytorch.Tensor} data is read from.
201- * @return The {@link RandomAccessibleInterval} built from the tensor of type {@link LongType}.
202- */
203- public static RandomAccessibleInterval <LongType > buildFromTensorLong (org .bytedeco .pytorch .Tensor tensor )
140+ private static RandomAccessibleInterval <LongType > buildFromTensorLong (org .bytedeco .pytorch .Tensor tensor )
204141 {
205142 long [] arrayShape = tensor .shape ();
206143 if (CommonUtils .int32Overflows (arrayShape , 8 ))
0 commit comments