36
36
import org .tensorflow .types .TUint8 ;
37
37
import org .tensorflow .types .family .TType ;
38
38
39
- import net .imglib2 .RandomAccessibleInterval ;
40
39
import net .imglib2 .type .numeric .integer .IntType ;
41
40
import net .imglib2 .type .numeric .integer .LongType ;
42
41
import net .imglib2 .type .numeric .integer .UnsignedByteType ;
43
42
import net .imglib2 .type .numeric .real .DoubleType ;
44
43
import net .imglib2 .type .numeric .real .FloatType ;
45
44
46
45
/**
47
- * A {@link RandomAccessibleInterval} builder for TensorFlow {@link Tensor} objects.
48
- * Build ImgLib2 objects (backend of {@link io.bioimage.modelrunner.tensor.Tensor})
49
- * from Tensorflow 2 {@link Tensor}
46
+ * A utility class that converts {@link Tensor}s into {@link SharedMemoryArray}s for
47
+ * interprocessing communication
50
48
*
51
- * @author Carlos Garcia Lopez de Haro and Daniel Felipe Gonzalez Obando
49
+ * @author Carlos Garcia Lopez de Haro
52
50
*/
53
51
public final class ShmBuilder
54
52
{
@@ -59,16 +57,15 @@ private ShmBuilder()
59
57
{
60
58
}
61
59
62
- /**
63
- * Creates a {@link RandomAccessibleInterval} from a given {@link TType} tensor
64
- *
65
- * @param <T>
66
- * the possible ImgLib2 datatypes of the image
67
- * @param tensor
68
- * The {@link TType} tensor data is read from.
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 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
+ */
72
69
@ SuppressWarnings ("unchecked" )
73
70
public static void build (Tensor <? extends TType > tensor , String memoryName ) throws IllegalArgumentException , IOException
74
71
{
@@ -89,14 +86,6 @@ public static void build(Tensor<? extends TType> tensor, String memoryName) thr
89
86
}
90
87
}
91
88
92
- /**
93
- * Builds a {@link RandomAccessibleInterval} from a unsigned byte-typed {@link TUint8} tensor.
94
- *
95
- * @param tensor
96
- * The {@link TUint8} tensor data is read from.
97
- * @return The {@link RandomAccessibleInterval} built from the tensor, of type {@link UnsignedByteType}.
98
- * @throws IOException
99
- */
100
89
private static void buildFromTensorUByte (Tensor <TUint8 > tensor , String memoryName ) throws IOException
101
90
{
102
91
long [] arrayShape = tensor .shape ().asArray ();
@@ -114,14 +103,6 @@ private static void buildFromTensorUByte(Tensor<TUint8> tensor, String memoryNam
114
103
if (PlatformDetection .isWindows ()) shma .close ();
115
104
}
116
105
117
- /**
118
- * Builds a {@link RandomAccessibleInterval} from a unsigned int32-typed {@link TInt32} tensor.
119
- *
120
- * @param tensor
121
- * The {@link TInt32} tensor data is read from.
122
- * @return The {@link RandomAccessibleInterval} built from the tensor, of type {@link IntType}.
123
- * @throws IOException
124
- */
125
106
private static void buildFromTensorInt (Tensor <TInt32 > tensor , String memoryName ) throws IOException
126
107
{
127
108
long [] arrayShape = tensor .shape ().asArray ();
@@ -140,14 +121,6 @@ private static void buildFromTensorInt(Tensor<TInt32> tensor, String memoryName)
140
121
if (PlatformDetection .isWindows ()) shma .close ();
141
122
}
142
123
143
- /**
144
- * Builds a {@link RandomAccessibleInterval} from a unsigned float32-typed {@link TFloat32} tensor.
145
- *
146
- * @param tensor
147
- * The {@link TFloat32} tensor data is read from.
148
- * @return The {@link RandomAccessibleInterval} built from the tensor, of type {@link FloatType}.
149
- * @throws IOException
150
- */
151
124
private static void buildFromTensorFloat (Tensor <TFloat32 > tensor , String memoryName ) throws IOException
152
125
{
153
126
long [] arrayShape = tensor .shape ().asArray ();
@@ -166,14 +139,6 @@ private static void buildFromTensorFloat(Tensor<TFloat32> tensor, String memoryN
166
139
if (PlatformDetection .isWindows ()) shma .close ();
167
140
}
168
141
169
- /**
170
- * Builds a {@link RandomAccessibleInterval} from a unsigned float64-typed {@link TFloat64} tensor.
171
- *
172
- * @param tensor
173
- * The {@link TFloat64} tensor data is read from.
174
- * @return The {@link RandomAccessibleInterval} built from the tensor, of type {@link DoubleType}.
175
- * @throws IOException
176
- */
177
142
private static void buildFromTensorDouble (Tensor <TFloat64 > tensor , String memoryName ) throws IOException
178
143
{
179
144
long [] arrayShape = tensor .shape ().asArray ();
@@ -192,14 +157,6 @@ private static void buildFromTensorDouble(Tensor<TFloat64> tensor, String memory
192
157
if (PlatformDetection .isWindows ()) shma .close ();
193
158
}
194
159
195
- /**
196
- * Builds a {@link RandomAccessibleInterval} from a unsigned int64-typed {@link TInt64} tensor.
197
- *
198
- * @param tensor
199
- * The {@link TInt64} tensor data is read from.
200
- * @return The {@link RandomAccessibleInterval} built from the tensor, of type {@link LongType}.
201
- * @throws IOException
202
- */
203
160
private static void buildFromTensorLong (Tensor <TInt64 > tensor , String memoryName ) throws IOException
204
161
{
205
162
long [] arrayShape = tensor .shape ().asArray ();
0 commit comments