Skip to content

Commit 5765157

Browse files
committed
write teh output
1 parent 38b88e7 commit 5765157

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

src/main/java/io/bioimage/modelrunner/tensorflow/v1/shm/ShmBuilder.java

+15
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@
2424
import io.bioimage.modelrunner.tensor.shm.SharedMemoryArray;
2525
import io.bioimage.modelrunner.utils.CommonUtils;
2626

27+
import java.io.FileOutputStream;
2728
import java.io.IOException;
2829
import java.nio.ByteBuffer;
30+
import java.nio.channels.FileChannel;
2931
import java.util.Arrays;
32+
import java.util.UUID;
3033

3134
import org.tensorflow.Tensor;
3235
import org.tensorflow.types.UInt8;
@@ -121,6 +124,18 @@ private static void buildFromTensorFloat(Tensor<Float> tensor, String memoryName
121124
SharedMemoryArray shma = SharedMemoryArray.readOrCreate(memoryName, arrayShape, new FloatType(), false, true);
122125
ByteBuffer buff = shma.getDataBufferNoHeader();
123126
tensor.writeTo(buff);
127+
try (FileOutputStream fos = new FileOutputStream("/home/carlos/git/interp_out" + UUID.randomUUID().toString() + ".npy");
128+
FileChannel fileChannel = fos.getChannel()) {
129+
buff.rewind();
130+
// Write the buffer's content to the file
131+
while (buff.hasRemaining()) {
132+
fileChannel.write(buff);
133+
}
134+
buff.rewind();
135+
} catch (IOException e) {
136+
// TODO Auto-generated catch block
137+
e.printStackTrace();
138+
}
124139
if (PlatformDetection.isWindows()) shma.close();
125140
}
126141

src/main/java/io/bioimage/modelrunner/tensorflow/v1/shm/TensorBuilder.java

-17
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,12 @@
2525
import io.bioimage.modelrunner.utils.CommonUtils;
2626
import net.imglib2.util.Cast;
2727

28-
import java.io.FileOutputStream;
29-
import java.io.IOException;
3028
import java.nio.ByteBuffer;
3129
import java.nio.DoubleBuffer;
3230
import java.nio.FloatBuffer;
3331
import java.nio.IntBuffer;
3432
import java.nio.LongBuffer;
35-
import java.nio.channels.FileChannel;
3633
import java.util.Arrays;
37-
import java.util.UUID;
3834

3935
import org.tensorflow.Tensor;
4036
import org.tensorflow.types.UInt8;
@@ -137,19 +133,6 @@ private static Tensor<Float> buildFloat(SharedMemoryArray tensor)
137133
+ " is too big. Max number of elements per ubyte tensor supported: " + Integer.MAX_VALUE);
138134
if (!tensor.isNumpyFormat())
139135
throw new IllegalArgumentException("Shared memory arrays must be saved in numpy format.");
140-
try (FileOutputStream fos = new FileOutputStream("/home/carlos/git/interp_inp" + UUID.randomUUID().toString() + ".npy");
141-
FileChannel fileChannel = fos.getChannel()) {
142-
ByteBuffer buffer = tensor.getDataBuffer();
143-
// Write the buffer's content to the file
144-
while (buffer.hasRemaining()) {
145-
fileChannel.write(buffer);
146-
}
147-
buffer.rewind();
148-
} catch (IOException e) {
149-
// TODO Auto-generated catch block
150-
e.printStackTrace();
151-
}
152-
153136
ByteBuffer buff = tensor.getDataBufferNoHeader();
154137
FloatBuffer floatBuff = buff.asFloatBuffer();
155138
Tensor<Float> ndarray = Tensor.create(ogShape, floatBuff);

0 commit comments

Comments
 (0)