Skip to content

Commit

Permalink
save array to try to understand
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Jan 2, 2025
1 parent c0c55b2 commit 38b88e7
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@
import io.bioimage.modelrunner.utils.CommonUtils;
import net.imglib2.util.Cast;

import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.DoubleBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.nio.LongBuffer;
import java.nio.channels.FileChannel;
import java.util.Arrays;
import java.util.UUID;

import org.tensorflow.Tensor;
import org.tensorflow.types.UInt8;
Expand Down Expand Up @@ -133,6 +137,19 @@ private static Tensor<Float> buildFloat(SharedMemoryArray tensor)
+ " is too big. Max number of elements per ubyte tensor supported: " + Integer.MAX_VALUE);
if (!tensor.isNumpyFormat())
throw new IllegalArgumentException("Shared memory arrays must be saved in numpy format.");
try (FileOutputStream fos = new FileOutputStream("/home/carlos/git/interp_inp" + UUID.randomUUID().toString() + ".npy");
FileChannel fileChannel = fos.getChannel()) {
ByteBuffer buffer = tensor.getDataBuffer();
// Write the buffer's content to the file
while (buffer.hasRemaining()) {
fileChannel.write(buffer);
}
buffer.rewind();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

ByteBuffer buff = tensor.getDataBufferNoHeader();
FloatBuffer floatBuff = buff.asFloatBuffer();
Tensor<Float> ndarray = Tensor.create(ogShape, floatBuff);
Expand Down

0 comments on commit 38b88e7

Please sign in to comment.