diff --git a/src/main/java/io/bioimage/modelrunner/tensorflow/v2/api030/shm/ShmBuilder.java b/src/main/java/io/bioimage/modelrunner/tensorflow/v2/api030/shm/ShmBuilder.java index e378be3..2e9e111 100644 --- a/src/main/java/io/bioimage/modelrunner/tensorflow/v2/api030/shm/ShmBuilder.java +++ b/src/main/java/io/bioimage/modelrunner/tensorflow/v2/api030/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; @@ -104,7 +105,7 @@ private static void buildFromTensorUByte(TUint8 tensor, String memoryName) throw byte[] flat = new byte[buff.capacity()]; ByteBuffer buff2 = ByteBuffer.wrap(flat); tensor.asRawTensor().data().read(flat, 0, buff.capacity()); - buff = buff2; + buff.put(buff2); if (PlatformDetection.isWindows()) shma.close(); } @@ -120,7 +121,7 @@ private static void buildFromTensorInt(TInt32 tensor, String memoryName) throws byte[] flat = new byte[buff.capacity()]; ByteBuffer buff2 = ByteBuffer.wrap(flat); tensor.asRawTensor().data().read(flat, 0, buff.capacity()); - buff = buff2; + buff.put(buff2); if (PlatformDetection.isWindows()) shma.close(); } @@ -134,9 +135,14 @@ 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); - tensor.asRawTensor().data().read(flat, 0, buff.capacity()); - buff = buff2; + ByteBuffer buff2 = ByteBuffer.wrap(flat).order(ByteOrder.LITTLE_ENDIAN); + tensor.asRawTensor().data().asFloats().read(buff2.asFloatBuffer().array(), 0, buff.capacity()); + buff.put(buff2); + + float sum = 0; + for (float ff : buff2.asFloatBuffer().array()) + sum += ff; + System.out.println("SECOND SUM: " + sum); if (PlatformDetection.isWindows()) shma.close(); } @@ -152,7 +158,7 @@ private static void buildFromTensorDouble(TFloat64 tensor, String memoryName) th byte[] flat = new byte[buff.capacity()]; ByteBuffer buff2 = ByteBuffer.wrap(flat); tensor.asRawTensor().data().read(flat, 0, buff.capacity()); - buff = buff2; + buff.put(buff2); if (PlatformDetection.isWindows()) shma.close(); } @@ -169,7 +175,7 @@ private static void buildFromTensorLong(TInt64 tensor, String memoryName) throws byte[] flat = new byte[buff.capacity()]; ByteBuffer buff2 = ByteBuffer.wrap(flat); tensor.asRawTensor().data().read(flat, 0, buff.capacity()); - buff = buff2; + buff.put(buff2); if (PlatformDetection.isWindows()) shma.close(); } } diff --git a/src/main/java/io/bioimage/modelrunner/tensorflow/v2/api030/shm/TensorBuilder.java b/src/main/java/io/bioimage/modelrunner/tensorflow/v2/api030/shm/TensorBuilder.java index ca39c52..6fcae42 100644 --- a/src/main/java/io/bioimage/modelrunner/tensorflow/v2/api030/shm/TensorBuilder.java +++ b/src/main/java/io/bioimage/modelrunner/tensorflow/v2/api030/shm/TensorBuilder.java @@ -156,6 +156,10 @@ private static TFloat32 buildFloat(SharedMemoryArray tensor) float[] flat = new float[buff.capacity() / 4]; buff.asFloatBuffer().get(flat); buff.rewind(); + float sum = 0; + for (float ff : flat) + sum += ff; + System.out.println(sum); FloatDataBuffer dataBuffer = RawDataBufferFactory.create(flat, false); TFloat32 ndarray = TFloat32.tensorOf(Shape.of(ogShape), dataBuffer); return ndarray;