Skip to content

Commit

Permalink
write teh output
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Jan 2, 2025
1 parent 38b88e7 commit 5765157
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@
import io.bioimage.modelrunner.tensor.shm.SharedMemoryArray;
import io.bioimage.modelrunner.utils.CommonUtils;

import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
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 @@ -121,6 +124,18 @@ private static void buildFromTensorFloat(Tensor<Float> tensor, String memoryName
SharedMemoryArray shma = SharedMemoryArray.readOrCreate(memoryName, arrayShape, new FloatType(), false, true);
ByteBuffer buff = shma.getDataBufferNoHeader();
tensor.writeTo(buff);
try (FileOutputStream fos = new FileOutputStream("/home/carlos/git/interp_out" + UUID.randomUUID().toString() + ".npy");
FileChannel fileChannel = fos.getChannel()) {
buff.rewind();
// Write the buffer's content to the file
while (buff.hasRemaining()) {
fileChannel.write(buff);
}
buff.rewind();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (PlatformDetection.isWindows()) shma.close();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,12 @@
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 @@ -137,19 +133,6 @@ 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 5765157

Please sign in to comment.