Skip to content

Commit cb2a417

Browse files
committed
correct bug that was not copying data to shm
1 parent 6d2f6bb commit cb2a417

File tree

1 file changed

+11
-10
lines changed
  • src/main/java/io/bioimage/modelrunner/tensorflow/v2/api050/shm

1 file changed

+11
-10
lines changed

src/main/java/io/bioimage/modelrunner/tensorflow/v2/api050/shm/ShmBuilder.java

+11-10
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import java.io.IOException;
2828
import java.nio.ByteBuffer;
29+
import java.nio.ByteOrder;
2930
import java.util.Arrays;
3031

3132
import org.tensorflow.types.TFloat32;
@@ -102,9 +103,9 @@ private static void buildFromTensorUByte(TUint8 tensor, String memoryName) throw
102103
SharedMemoryArray shma = SharedMemoryArray.readOrCreate(memoryName, arrayShape, new UnsignedByteType(), false, true);
103104
ByteBuffer buff = shma.getDataBufferNoHeader();
104105
byte[] flat = new byte[buff.capacity()];
105-
ByteBuffer buff2 = ByteBuffer.wrap(flat);
106+
ByteBuffer buff2 = ByteBuffer.wrap(flat).order(ByteOrder.LITTLE_ENDIAN);
106107
tensor.asRawTensor().data().read(flat, 0, buff.capacity());
107-
buff = buff2;
108+
buff.put(buff2);
108109
if (PlatformDetection.isWindows()) shma.close();
109110
}
110111

@@ -118,9 +119,9 @@ private static void buildFromTensorInt(TInt32 tensor, String memoryName) throws
118119
SharedMemoryArray shma = SharedMemoryArray.readOrCreate(memoryName, arrayShape, new IntType(), false, true);
119120
ByteBuffer buff = shma.getDataBufferNoHeader();
120121
byte[] flat = new byte[buff.capacity()];
121-
ByteBuffer buff2 = ByteBuffer.wrap(flat);
122+
ByteBuffer buff2 = ByteBuffer.wrap(flat).order(ByteOrder.LITTLE_ENDIAN);
122123
tensor.asRawTensor().data().read(flat, 0, buff.capacity());
123-
buff = buff2;
124+
buff.put(buff2);
124125
if (PlatformDetection.isWindows()) shma.close();
125126
}
126127

@@ -134,9 +135,9 @@ private static void buildFromTensorFloat(TFloat32 tensor, String memoryName) thr
134135
SharedMemoryArray shma = SharedMemoryArray.readOrCreate(memoryName, arrayShape, new FloatType(), false, true);
135136
ByteBuffer buff = shma.getDataBufferNoHeader();
136137
byte[] flat = new byte[buff.capacity()];
137-
ByteBuffer buff2 = ByteBuffer.wrap(flat);
138+
ByteBuffer buff2 = ByteBuffer.wrap(flat).order(ByteOrder.LITTLE_ENDIAN);
138139
tensor.asRawTensor().data().read(flat, 0, buff.capacity());
139-
buff = buff2;
140+
buff.put(buff2);
140141
if (PlatformDetection.isWindows()) shma.close();
141142
}
142143

@@ -150,9 +151,9 @@ private static void buildFromTensorDouble(TFloat64 tensor, String memoryName) th
150151
SharedMemoryArray shma = SharedMemoryArray.readOrCreate(memoryName, arrayShape, new DoubleType(), false, true);
151152
ByteBuffer buff = shma.getDataBufferNoHeader();
152153
byte[] flat = new byte[buff.capacity()];
153-
ByteBuffer buff2 = ByteBuffer.wrap(flat);
154+
ByteBuffer buff2 = ByteBuffer.wrap(flat).order(ByteOrder.LITTLE_ENDIAN);
154155
tensor.asRawTensor().data().read(flat, 0, buff.capacity());
155-
buff = buff2;
156+
buff.put(buff2);
156157
if (PlatformDetection.isWindows()) shma.close();
157158
}
158159

@@ -167,9 +168,9 @@ private static void buildFromTensorLong(TInt64 tensor, String memoryName) throws
167168
SharedMemoryArray shma = SharedMemoryArray.readOrCreate(memoryName, arrayShape, new LongType(), false, true);
168169
ByteBuffer buff = shma.getDataBufferNoHeader();
169170
byte[] flat = new byte[buff.capacity()];
170-
ByteBuffer buff2 = ByteBuffer.wrap(flat);
171+
ByteBuffer buff2 = ByteBuffer.wrap(flat).order(ByteOrder.LITTLE_ENDIAN);
171172
tensor.asRawTensor().data().read(flat, 0, buff.capacity());
172-
buff = buff2;
173+
buff.put(buff2);
173174
if (PlatformDetection.isWindows()) shma.close();
174175
}
175176
}

0 commit comments

Comments
 (0)