From cb2a417ec86ae7e20dbebb73383279efd5344a4b Mon Sep 17 00:00:00 2001 From: carlosuc3m <100329787@alumnos.uc3m.es> Date: Mon, 25 Nov 2024 03:00:45 +0100 Subject: [PATCH] correct bug that was not copying data to shm --- .../tensorflow/v2/api050/shm/ShmBuilder.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/java/io/bioimage/modelrunner/tensorflow/v2/api050/shm/ShmBuilder.java b/src/main/java/io/bioimage/modelrunner/tensorflow/v2/api050/shm/ShmBuilder.java index 78b75b9..d5fa442 100644 --- a/src/main/java/io/bioimage/modelrunner/tensorflow/v2/api050/shm/ShmBuilder.java +++ b/src/main/java/io/bioimage/modelrunner/tensorflow/v2/api050/shm/ShmBuilder.java @@ -26,6 +26,7 @@ import java.io.IOException; import java.nio.ByteBuffer; +import java.nio.ByteOrder; import java.util.Arrays; import org.tensorflow.types.TFloat32; @@ -102,9 +103,9 @@ private static void buildFromTensorUByte(TUint8 tensor, String memoryName) throw SharedMemoryArray shma = SharedMemoryArray.readOrCreate(memoryName, arrayShape, new UnsignedByteType(), false, true); ByteBuffer buff = shma.getDataBufferNoHeader(); byte[] flat = new byte[buff.capacity()]; - ByteBuffer buff2 = ByteBuffer.wrap(flat); + ByteBuffer buff2 = ByteBuffer.wrap(flat).order(ByteOrder.LITTLE_ENDIAN); tensor.asRawTensor().data().read(flat, 0, buff.capacity()); - buff = buff2; + buff.put(buff2); if (PlatformDetection.isWindows()) shma.close(); } @@ -118,9 +119,9 @@ private static void buildFromTensorInt(TInt32 tensor, String memoryName) throws SharedMemoryArray shma = SharedMemoryArray.readOrCreate(memoryName, arrayShape, new IntType(), false, true); ByteBuffer buff = shma.getDataBufferNoHeader(); byte[] flat = new byte[buff.capacity()]; - ByteBuffer buff2 = ByteBuffer.wrap(flat); + ByteBuffer buff2 = ByteBuffer.wrap(flat).order(ByteOrder.LITTLE_ENDIAN); tensor.asRawTensor().data().read(flat, 0, buff.capacity()); - buff = buff2; + buff.put(buff2); if (PlatformDetection.isWindows()) shma.close(); } @@ -134,9 +135,9 @@ private static void buildFromTensorFloat(TFloat32 tensor, String memoryName) thr SharedMemoryArray shma = SharedMemoryArray.readOrCreate(memoryName, arrayShape, new FloatType(), false, true); ByteBuffer buff = shma.getDataBufferNoHeader(); byte[] flat = new byte[buff.capacity()]; - ByteBuffer buff2 = ByteBuffer.wrap(flat); + ByteBuffer buff2 = ByteBuffer.wrap(flat).order(ByteOrder.LITTLE_ENDIAN); tensor.asRawTensor().data().read(flat, 0, buff.capacity()); - buff = buff2; + buff.put(buff2); if (PlatformDetection.isWindows()) shma.close(); } @@ -150,9 +151,9 @@ private static void buildFromTensorDouble(TFloat64 tensor, String memoryName) th SharedMemoryArray shma = SharedMemoryArray.readOrCreate(memoryName, arrayShape, new DoubleType(), false, true); ByteBuffer buff = shma.getDataBufferNoHeader(); byte[] flat = new byte[buff.capacity()]; - ByteBuffer buff2 = ByteBuffer.wrap(flat); + ByteBuffer buff2 = ByteBuffer.wrap(flat).order(ByteOrder.LITTLE_ENDIAN); tensor.asRawTensor().data().read(flat, 0, buff.capacity()); - buff = buff2; + buff.put(buff2); if (PlatformDetection.isWindows()) shma.close(); } @@ -167,9 +168,9 @@ private static void buildFromTensorLong(TInt64 tensor, String memoryName) throws SharedMemoryArray shma = SharedMemoryArray.readOrCreate(memoryName, arrayShape, new LongType(), false, true); ByteBuffer buff = shma.getDataBufferNoHeader(); byte[] flat = new byte[buff.capacity()]; - ByteBuffer buff2 = ByteBuffer.wrap(flat); + ByteBuffer buff2 = ByteBuffer.wrap(flat).order(ByteOrder.LITTLE_ENDIAN); tensor.asRawTensor().data().read(flat, 0, buff.capacity()); - buff = buff2; + buff.put(buff2); if (PlatformDetection.isWindows()) shma.close(); } }