Skip to content

Commit fc3fc86

Browse files
committed
correct javadoc
1 parent 3ca0f15 commit fc3fc86

File tree

5 files changed

+40
-218
lines changed

5 files changed

+40
-218
lines changed

src/main/java/io/bioimage/modelrunner/tensorflow/v2/api050/JavaWorker.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ public class JavaWorker {
2121
private final Tensorflow2Interface ti;
2222

2323
private boolean cancelRequested = false;
24-
24+
25+
/**
26+
* Method in the child process that is in charge of keeping the process open and calling the model load,
27+
* model inference and model closing
28+
* @param args
29+
* args of the parent process
30+
*/
2531
public static void main(String[] args) {
2632

2733
try(Scanner scanner = new Scanner(System.in)){

src/main/java/io/bioimage/modelrunner/tensorflow/v2/api050/shm/ShmBuilder.java

+12-55
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,10 @@
4343
import net.imglib2.type.numeric.real.FloatType;
4444

4545
/**
46-
* A {@link RandomAccessibleInterval} builder for TensorFlow {@link Tensor} objects.
47-
* Build ImgLib2 objects (backend of {@link io.bioimage.modelrunner.tensor.Tensor})
48-
* from Tensorflow 2 {@link Tensor}
46+
* A utility class that converts {@link TType} tensors into {@link SharedMemoryArray}s for
47+
* interprocessing communication
4948
*
50-
* @author Carlos Garcia Lopez de Haro and Daniel Felipe Gonzalez Obando
49+
* @author Carlos Garcia Lopez de Haro
5150
*/
5251
public final class ShmBuilder
5352
{
@@ -58,17 +57,15 @@ private ShmBuilder()
5857
{
5958
}
6059

61-
/**
62-
* Creates a {@link RandomAccessibleInterval} from a given {@link TType} tensor
63-
*
64-
* @param <T>
65-
* the possible ImgLib2 datatypes of the image
66-
* @param tensor
67-
* The {@link TType} tensor data is read from.
68-
* @return The {@link RandomAccessibleInterval} built from the {@link TType} tensor.
69-
* @throws IllegalArgumentException If the {@link TType} tensor type is not supported.
70-
* @throws IOException
71-
*/
60+
/**
61+
* Create a {@link SharedMemoryArray} from a {@link TType} tensor
62+
* @param tensor
63+
* the tensor to be passed into the other process through the shared memory
64+
* @param memoryName
65+
* the name of the memory region where the tensor is going to be copied
66+
* @throws IllegalArgumentException if the data type of the tensor is not supported
67+
* @throws IOException if there is any error creating the shared memory array
68+
*/
7269
public static void build(TType tensor, String memoryName) throws IllegalArgumentException, IOException
7370
{
7471
if (tensor instanceof TUint8)
@@ -97,14 +94,6 @@ else if (tensor instanceof TInt64)
9794
}
9895
}
9996

100-
/**
101-
* Builds a {@link RandomAccessibleInterval} from a unsigned byte-typed {@link TUint8} tensor.
102-
*
103-
* @param tensor
104-
* The {@link TUint8} tensor data is read from.
105-
* @return The {@link RandomAccessibleInterval} built from the tensor, of type {@link UnsignedByteType}.
106-
* @throws IOException
107-
*/
10897
private static void buildFromTensorUByte(TUint8 tensor, String memoryName) throws IOException
10998
{
11099
long[] arrayShape = tensor.shape().asArray();
@@ -122,14 +111,6 @@ private static void buildFromTensorUByte(TUint8 tensor, String memoryName) throw
122111
if (PlatformDetection.isWindows()) shma.close();
123112
}
124113

125-
/**
126-
* Builds a {@link RandomAccessibleInterval} from a unsigned int32-typed {@link TInt32} tensor.
127-
*
128-
* @param tensor
129-
* The {@link TInt32} tensor data is read from.
130-
* @return The {@link RandomAccessibleInterval} built from the tensor, of type {@link IntType}.
131-
* @throws IOException
132-
*/
133114
private static void buildFromTensorInt(TInt32 tensor, String memoryName) throws IOException
134115
{
135116
long[] arrayShape = tensor.shape().asArray();
@@ -148,14 +129,6 @@ private static void buildFromTensorInt(TInt32 tensor, String memoryName) throws
148129
if (PlatformDetection.isWindows()) shma.close();
149130
}
150131

151-
/**
152-
* Builds a {@link RandomAccessibleInterval} from a unsigned float32-typed {@link TFloat32} tensor.
153-
*
154-
* @param tensor
155-
* The {@link TFloat32} tensor data is read from.
156-
* @return The {@link RandomAccessibleInterval} built from the tensor, of type {@link FloatType}.
157-
* @throws IOException
158-
*/
159132
private static void buildFromTensorFloat(TFloat32 tensor, String memoryName) throws IOException
160133
{
161134
long[] arrayShape = tensor.shape().asArray();
@@ -174,14 +147,6 @@ private static void buildFromTensorFloat(TFloat32 tensor, String memoryName) thr
174147
if (PlatformDetection.isWindows()) shma.close();
175148
}
176149

177-
/**
178-
* Builds a {@link RandomAccessibleInterval} from a unsigned float64-typed {@link TFloat64} tensor.
179-
*
180-
* @param tensor
181-
* The {@link TFloat64} tensor data is read from.
182-
* @return The {@link RandomAccessibleInterval} built from the tensor, of type {@link DoubleType}.
183-
* @throws IOException
184-
*/
185150
private static void buildFromTensorDouble(TFloat64 tensor, String memoryName) throws IOException
186151
{
187152
long[] arrayShape = tensor.shape().asArray();
@@ -200,14 +165,6 @@ private static void buildFromTensorDouble(TFloat64 tensor, String memoryName) th
200165
if (PlatformDetection.isWindows()) shma.close();
201166
}
202167

203-
/**
204-
* Builds a {@link RandomAccessibleInterval} from a unsigned int64-typed {@link TInt64} tensor.
205-
*
206-
* @param tensor
207-
* The {@link TInt64} tensor data is read from.
208-
* @return The {@link RandomAccessibleInterval} built from the tensor, of type {@link LongType}.
209-
* @throws IOException
210-
*/
211168
private static void buildFromTensorLong(TInt64 tensor, String memoryName) throws IOException
212169
{
213170
long[] arrayShape = tensor.shape().asArray();

src/main/java/io/bioimage/modelrunner/tensorflow/v2/api050/shm/TensorBuilder.java

+9-70
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,6 @@
2323

2424
import io.bioimage.modelrunner.tensor.shm.SharedMemoryArray;
2525
import io.bioimage.modelrunner.utils.CommonUtils;
26-
import net.imglib2.RandomAccessibleInterval;
27-
import net.imglib2.img.Img;
28-
import net.imglib2.type.numeric.integer.IntType;
29-
import net.imglib2.type.numeric.integer.LongType;
30-
import net.imglib2.type.numeric.integer.UnsignedByteType;
31-
import net.imglib2.type.numeric.real.DoubleType;
32-
import net.imglib2.type.numeric.real.FloatType;
3326
import net.imglib2.util.Cast;
3427

3528
import java.nio.ByteBuffer;
@@ -55,10 +48,9 @@
5548
import org.tensorflow.types.family.TType;
5649

5750
/**
58-
* A TensorFlow 2 {@link Tensor} builder from {@link Img} and
59-
* {@link io.bioimage.modelrunner.tensor.Tensor} objects.
51+
* Utility class to build Tensorflow tensors from shm segments using {@link SharedMemoryArray}
6052
*
61-
* @author Carlos Garcia Lopez de Haro and Daniel Felipe Gonzalez Obando
53+
* @author Carlos Garcia Lopez de Haro
6254
*/
6355
public final class TensorBuilder {
6456

@@ -68,16 +60,13 @@ public final class TensorBuilder {
6860
private TensorBuilder() {}
6961

7062
/**
71-
* Creates {@link TType} instance with the same size and information as the
72-
* given {@link RandomAccessibleInterval}.
63+
* Creates {@link TType} instance from a {@link SharedMemoryArray}
7364
*
74-
* @param <T>
75-
* the ImgLib2 data types the {@link RandomAccessibleInterval} can be
7665
* @param array
77-
* the {@link RandomAccessibleInterval} that is going to be converted into
66+
* the {@link SharedMemoryArray} that is going to be converted into
7867
* a {@link TType} tensor
79-
* @return a {@link TType} tensor
80-
* @throws IllegalArgumentException if the type of the {@link RandomAccessibleInterval}
68+
* @return the Tensorflow {@link TType} as the one stored in the shared memory segment
69+
* @throws IllegalArgumentException if the type of the {@link SharedMemoryArray}
8170
* is not supported
8271
*/
8372
public static TType build(SharedMemoryArray array) throws IllegalArgumentException
@@ -103,17 +92,7 @@ else if (array.getOriginalDataType().equals("int64")) {
10392
}
10493
}
10594

106-
/**
107-
* Creates a {@link TType} tensor of type {@link TUint8} from an
108-
* {@link RandomAccessibleInterval} of type {@link UnsignedByteType}
109-
*
110-
* @param tensor
111-
* The {@link RandomAccessibleInterval} to fill the tensor with.
112-
* @return The {@link TType} tensor filled with the {@link RandomAccessibleInterval} data.
113-
* @throws IllegalArgumentException if the input {@link RandomAccessibleInterval} type is
114-
* not compatible
115-
*/
116-
public static TUint8 buildUByte(SharedMemoryArray tensor)
95+
private static TUint8 buildUByte(SharedMemoryArray tensor)
11796
throws IllegalArgumentException
11897
{
11998
long[] ogShape = tensor.getOriginalShape();
@@ -128,17 +107,7 @@ public static TUint8 buildUByte(SharedMemoryArray tensor)
128107
return ndarray;
129108
}
130109

131-
/**
132-
* Creates a {@link TInt32} tensor of type {@link TInt32} from an
133-
* {@link RandomAccessibleInterval} of type {@link IntType}
134-
*
135-
* @param tensor
136-
* The {@link RandomAccessibleInterval} to fill the tensor with.
137-
* @return The {@link TInt32} tensor filled with the {@link RandomAccessibleInterval} data.
138-
* @throws IllegalArgumentException if the input {@link RandomAccessibleInterval} type is
139-
* not compatible
140-
*/
141-
public static TInt32 buildInt(SharedMemoryArray tensor)
110+
private static TInt32 buildInt(SharedMemoryArray tensor)
142111
throws IllegalArgumentException
143112
{
144113
long[] ogShape = tensor.getOriginalShape();
@@ -157,16 +126,6 @@ public static TInt32 buildInt(SharedMemoryArray tensor)
157126
return ndarray;
158127
}
159128

160-
/**
161-
* Creates a {@link TInt64} tensor of type {@link TInt64} from an
162-
* {@link RandomAccessibleInterval} of type {@link LongType}
163-
*
164-
* @param tensor
165-
* The {@link RandomAccessibleInterval} to fill the tensor with.
166-
* @return The {@link TInt64} tensor filled with the {@link RandomAccessibleInterval} data.
167-
* @throws IllegalArgumentException if the input {@link RandomAccessibleInterval} type is
168-
* not compatible
169-
*/
170129
private static TInt64 buildLong(SharedMemoryArray tensor)
171130
throws IllegalArgumentException
172131
{
@@ -186,17 +145,7 @@ private static TInt64 buildLong(SharedMemoryArray tensor)
186145
return ndarray;
187146
}
188147

189-
/**
190-
* Creates a {@link TFloat32} tensor of type {@link TFloat32} from an
191-
* {@link RandomAccessibleInterval} of type {@link FloatType}
192-
*
193-
* @param tensor
194-
* The {@link RandomAccessibleInterval} to fill the tensor with.
195-
* @return The {@link TFloat32} tensor filled with the {@link RandomAccessibleInterval} data.
196-
* @throws IllegalArgumentException if the input {@link RandomAccessibleInterval} type is
197-
* not compatible
198-
*/
199-
public static TFloat32 buildFloat(SharedMemoryArray tensor)
148+
private static TFloat32 buildFloat(SharedMemoryArray tensor)
200149
throws IllegalArgumentException
201150
{
202151
long[] ogShape = tensor.getOriginalShape();
@@ -214,16 +163,6 @@ public static TFloat32 buildFloat(SharedMemoryArray tensor)
214163
return ndarray;
215164
}
216165

217-
/**
218-
* Creates a {@link TFloat64} tensor of type {@link TFloat64} from an
219-
* {@link RandomAccessibleInterval} of type {@link DoubleType}
220-
*
221-
* @param tensor
222-
* The {@link RandomAccessibleInterval} to fill the tensor with.
223-
* @return The {@link TFloat64} tensor filled with the {@link RandomAccessibleInterval} data.
224-
* @throws IllegalArgumentException if the input {@link RandomAccessibleInterval} type is
225-
* not compatible
226-
*/
227166
private static TFloat64 buildDouble(SharedMemoryArray tensor)
228167
throws IllegalArgumentException
229168
{

src/main/java/io/bioimage/modelrunner/tensorflow/v2/api050/tensor/ImgLib2Builder.java

+2-36
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ private ImgLib2Builder()
6767
* @return The {@link RandomAccessibleInterval} built from the {@link TType} tensor.
6868
* @throws IllegalArgumentException If the {@link TType} tensor type is not supported.
6969
*/
70-
public static <T extends Type<T>> RandomAccessibleInterval<T> build(TType tensor) throws IllegalArgumentException
70+
@SuppressWarnings("unchecked")
71+
public static <T extends Type<T>> RandomAccessibleInterval<T> build(TType tensor) throws IllegalArgumentException
7172
{
7273
if (tensor instanceof TUint8)
7374
{
@@ -95,13 +96,6 @@ else if (tensor instanceof TInt64)
9596
}
9697
}
9798

98-
/**
99-
* Builds a {@link RandomAccessibleInterval} from a unsigned byte-typed {@link TUint8} tensor.
100-
*
101-
* @param tensor
102-
* The {@link TUint8} tensor data is read from.
103-
* @return The {@link RandomAccessibleInterval} built from the tensor, of type {@link UnsignedByteType}.
104-
*/
10599
private static RandomAccessibleInterval<UnsignedByteType> buildFromTensorUByte(TUint8 tensor)
106100
{
107101
long[] arrayShape = tensor.shape().asArray();
@@ -118,13 +112,6 @@ private static RandomAccessibleInterval<UnsignedByteType> buildFromTensorUByte(T
118112
return Utils.transpose(rai);
119113
}
120114

121-
/**
122-
* Builds a {@link RandomAccessibleInterval} from a unsigned int32-typed {@link TInt32} tensor.
123-
*
124-
* @param tensor
125-
* The {@link TInt32} tensor data is read from.
126-
* @return The {@link RandomAccessibleInterval} built from the tensor, of type {@link IntType}.
127-
*/
128115
private static RandomAccessibleInterval<IntType> buildFromTensorInt(TInt32 tensor)
129116
{
130117
long[] arrayShape = tensor.shape().asArray();
@@ -141,13 +128,6 @@ private static RandomAccessibleInterval<IntType> buildFromTensorInt(TInt32 tenso
141128
return Utils.transpose(rai);
142129
}
143130

144-
/**
145-
* Builds a {@link RandomAccessibleInterval} from a unsigned float32-typed {@link TFloat32} tensor.
146-
*
147-
* @param tensor
148-
* The {@link TFloat32} tensor data is read from.
149-
* @return The {@link RandomAccessibleInterval} built from the tensor, of type {@link FloatType}.
150-
*/
151131
private static RandomAccessibleInterval<FloatType> buildFromTensorFloat(TFloat32 tensor)
152132
{
153133
long[] arrayShape = tensor.shape().asArray();
@@ -164,13 +144,6 @@ private static RandomAccessibleInterval<FloatType> buildFromTensorFloat(TFloat32
164144
return Utils.transpose(rai);
165145
}
166146

167-
/**
168-
* Builds a {@link RandomAccessibleInterval} from a unsigned float64-typed {@link TFloat64} tensor.
169-
*
170-
* @param tensor
171-
* The {@link TFloat64} tensor data is read from.
172-
* @return The {@link RandomAccessibleInterval} built from the tensor, of type {@link DoubleType}.
173-
*/
174147
private static RandomAccessibleInterval<DoubleType> buildFromTensorDouble(TFloat64 tensor)
175148
{
176149
long[] arrayShape = tensor.shape().asArray();
@@ -187,13 +160,6 @@ private static RandomAccessibleInterval<DoubleType> buildFromTensorDouble(TFloat
187160
return Utils.transpose(rai);
188161
}
189162

190-
/**
191-
* Builds a {@link RandomAccessibleInterval} from a unsigned int64-typed {@link TInt64} tensor.
192-
*
193-
* @param tensor
194-
* The {@link TInt64} tensor data is read from.
195-
* @return The {@link RandomAccessibleInterval} built from the tensor, of type {@link LongType}.
196-
*/
197163
private static RandomAccessibleInterval<LongType> buildFromTensorLong(TInt64 tensor)
198164
{
199165
long[] arrayShape = tensor.shape().asArray();

0 commit comments

Comments
 (0)