Skip to content

Commit 38b88e7

Browse files
committed
save array to try to understand
1 parent c0c55b2 commit 38b88e7

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

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

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

28+
import java.io.FileOutputStream;
29+
import java.io.IOException;
2830
import java.nio.ByteBuffer;
2931
import java.nio.DoubleBuffer;
3032
import java.nio.FloatBuffer;
3133
import java.nio.IntBuffer;
3234
import java.nio.LongBuffer;
35+
import java.nio.channels.FileChannel;
3336
import java.util.Arrays;
37+
import java.util.UUID;
3438

3539
import org.tensorflow.Tensor;
3640
import org.tensorflow.types.UInt8;
@@ -133,6 +137,19 @@ private static Tensor<Float> buildFloat(SharedMemoryArray tensor)
133137
+ " is too big. Max number of elements per ubyte tensor supported: " + Integer.MAX_VALUE);
134138
if (!tensor.isNumpyFormat())
135139
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+
136153
ByteBuffer buff = tensor.getDataBufferNoHeader();
137154
FloatBuffer floatBuff = buff.asFloatBuffer();
138155
Tensor<Float> ndarray = Tensor.create(ogShape, floatBuff);

0 commit comments

Comments
 (0)