From d8c0725062dfb3e9a87ab4e50c81b18f37be67ee Mon Sep 17 00:00:00 2001 From: carlosuc3m <100329787@alumnos.uc3m.es> Date: Wed, 2 Oct 2024 18:54:22 +0200 Subject: [PATCH] improve small errors on shm communication --- .../modelrunner/tensorflow/v1/shm/ShmBuilder.java | 10 +++++----- .../modelrunner/tensorflow/v1/shm/TensorBuilder.java | 8 -------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/main/java/io/bioimage/modelrunner/tensorflow/v1/shm/ShmBuilder.java b/src/main/java/io/bioimage/modelrunner/tensorflow/v1/shm/ShmBuilder.java index 1e700a0..6d432b8 100644 --- a/src/main/java/io/bioimage/modelrunner/tensorflow/v1/shm/ShmBuilder.java +++ b/src/main/java/io/bioimage/modelrunner/tensorflow/v1/shm/ShmBuilder.java @@ -93,7 +93,7 @@ private static void buildFromTensorUByte(Tensor tensor, String memoryName throw new IllegalArgumentException("Model output tensor with shape " + Arrays.toString(arrayShape) + " is too big. Max number of elements per ubyte output tensor supported: " + Integer.MAX_VALUE / 1); SharedMemoryArray shma = SharedMemoryArray.readOrCreate(memoryName, arrayShape, new UnsignedByteType(), false, true); - ByteBuffer buff = shma.getDataBuffer(); + ByteBuffer buff = shma.getDataBufferNoHeader(); tensor.writeTo(buff); if (PlatformDetection.isWindows()) shma.close(); } @@ -106,7 +106,7 @@ private static void buildFromTensorInt(Tensor tensor, String memoryName + " is too big. Max number of elements per int output tensor supported: " + Integer.MAX_VALUE / 4); SharedMemoryArray shma = SharedMemoryArray.readOrCreate(memoryName, arrayShape, new IntType(), false, true); - ByteBuffer buff = shma.getDataBuffer(); + ByteBuffer buff = shma.getDataBufferNoHeader(); tensor.writeTo(buff); if (PlatformDetection.isWindows()) shma.close(); } @@ -119,7 +119,7 @@ private static void buildFromTensorFloat(Tensor tensor, String memoryName + " is too big. Max number of elements per float output tensor supported: " + Integer.MAX_VALUE / 4); SharedMemoryArray shma = SharedMemoryArray.readOrCreate(memoryName, arrayShape, new FloatType(), false, true); - ByteBuffer buff = shma.getDataBuffer(); + ByteBuffer buff = shma.getDataBufferNoHeader(); tensor.writeTo(buff); if (PlatformDetection.isWindows()) shma.close(); } @@ -132,7 +132,7 @@ private static void buildFromTensorDouble(Tensor tensor, String memoryNa + " is too big. Max number of elements per double output tensor supported: " + Integer.MAX_VALUE / 8); SharedMemoryArray shma = SharedMemoryArray.readOrCreate(memoryName, arrayShape, new DoubleType(), false, true); - ByteBuffer buff = shma.getDataBuffer(); + ByteBuffer buff = shma.getDataBufferNoHeader(); tensor.writeTo(buff); if (PlatformDetection.isWindows()) shma.close(); } @@ -146,7 +146,7 @@ private static void buildFromTensorLong(Tensor tensor, String memoryName) SharedMemoryArray shma = SharedMemoryArray.readOrCreate(memoryName, arrayShape, new LongType(), false, true); - ByteBuffer buff = shma.getDataBuffer(); + ByteBuffer buff = shma.getDataBufferNoHeader(); tensor.writeTo(buff); if (PlatformDetection.isWindows()) shma.close(); } diff --git a/src/main/java/io/bioimage/modelrunner/tensorflow/v1/shm/TensorBuilder.java b/src/main/java/io/bioimage/modelrunner/tensorflow/v1/shm/TensorBuilder.java index d0ba4b6..beb76b1 100644 --- a/src/main/java/io/bioimage/modelrunner/tensorflow/v1/shm/TensorBuilder.java +++ b/src/main/java/io/bioimage/modelrunner/tensorflow/v1/shm/TensorBuilder.java @@ -105,8 +105,6 @@ private static Tensor buildInt(SharedMemoryArray tensor) throw new IllegalArgumentException("Shared memory arrays must be saved in numpy format."); ByteBuffer buff = tensor.getDataBufferNoHeader(); IntBuffer intBuff = buff.asIntBuffer(); - int[] intArray = new int[intBuff.capacity()]; - intBuff.get(intArray); Tensor ndarray = Tensor.create(ogShape, intBuff); return ndarray; } @@ -122,8 +120,6 @@ private static Tensor buildLong(SharedMemoryArray tensor) throw new IllegalArgumentException("Shared memory arrays must be saved in numpy format."); ByteBuffer buff = tensor.getDataBufferNoHeader(); LongBuffer longBuff = buff.asLongBuffer(); - long[] longArray = new long[longBuff.capacity()]; - longBuff.get(longArray); Tensor ndarray = Tensor.create(ogShape, longBuff); return ndarray; } @@ -139,8 +135,6 @@ private static Tensor buildFloat(SharedMemoryArray tensor) throw new IllegalArgumentException("Shared memory arrays must be saved in numpy format."); ByteBuffer buff = tensor.getDataBufferNoHeader(); FloatBuffer floatBuff = buff.asFloatBuffer(); - float[] floatArray = new float[floatBuff.capacity()]; - floatBuff.get(floatArray); Tensor ndarray = Tensor.create(ogShape, floatBuff); return ndarray; } @@ -156,8 +150,6 @@ private static Tensor buildDouble(SharedMemoryArray tensor) throw new IllegalArgumentException("Shared memory arrays must be saved in numpy format."); ByteBuffer buff = tensor.getDataBufferNoHeader(); DoubleBuffer doubleBuff = buff.asDoubleBuffer(); - double[] doubleArray = new double[doubleBuff.capacity()]; - doubleBuff.get(doubleArray); Tensor ndarray = Tensor.create(ogShape, doubleBuff); return ndarray; }