26
26
27
27
import java .io .IOException ;
28
28
import java .nio .ByteBuffer ;
29
+ import java .nio .ByteOrder ;
29
30
import java .util .Arrays ;
30
31
31
32
import org .tensorflow .types .TFloat32 ;
@@ -102,9 +103,9 @@ private static void buildFromTensorUByte(TUint8 tensor, String memoryName) throw
102
103
SharedMemoryArray shma = SharedMemoryArray .readOrCreate (memoryName , arrayShape , new UnsignedByteType (), false , true );
103
104
ByteBuffer buff = shma .getDataBufferNoHeader ();
104
105
byte [] flat = new byte [buff .capacity ()];
105
- ByteBuffer buff2 = ByteBuffer .wrap (flat );
106
+ ByteBuffer buff2 = ByteBuffer .wrap (flat ). order ( ByteOrder . LITTLE_ENDIAN ) ;
106
107
tensor .asRawTensor ().data ().read (flat , 0 , buff .capacity ());
107
- buff = buff2 ;
108
+ buff . put ( buff2 ) ;
108
109
if (PlatformDetection .isWindows ()) shma .close ();
109
110
}
110
111
@@ -118,9 +119,9 @@ private static void buildFromTensorInt(TInt32 tensor, String memoryName) throws
118
119
SharedMemoryArray shma = SharedMemoryArray .readOrCreate (memoryName , arrayShape , new IntType (), false , true );
119
120
ByteBuffer buff = shma .getDataBufferNoHeader ();
120
121
byte [] flat = new byte [buff .capacity ()];
121
- ByteBuffer buff2 = ByteBuffer .wrap (flat );
122
+ ByteBuffer buff2 = ByteBuffer .wrap (flat ). order ( ByteOrder . LITTLE_ENDIAN ) ;
122
123
tensor .asRawTensor ().data ().read (flat , 0 , buff .capacity ());
123
- buff = buff2 ;
124
+ buff . put ( buff2 ) ;
124
125
if (PlatformDetection .isWindows ()) shma .close ();
125
126
}
126
127
@@ -134,9 +135,9 @@ private static void buildFromTensorFloat(TFloat32 tensor, String memoryName) thr
134
135
SharedMemoryArray shma = SharedMemoryArray .readOrCreate (memoryName , arrayShape , new FloatType (), false , true );
135
136
ByteBuffer buff = shma .getDataBufferNoHeader ();
136
137
byte [] flat = new byte [buff .capacity ()];
137
- ByteBuffer buff2 = ByteBuffer .wrap (flat );
138
+ ByteBuffer buff2 = ByteBuffer .wrap (flat ). order ( ByteOrder . LITTLE_ENDIAN ) ;
138
139
tensor .asRawTensor ().data ().read (flat , 0 , buff .capacity ());
139
- buff = buff2 ;
140
+ buff . put ( buff2 ) ;
140
141
if (PlatformDetection .isWindows ()) shma .close ();
141
142
}
142
143
@@ -150,9 +151,9 @@ private static void buildFromTensorDouble(TFloat64 tensor, String memoryName) th
150
151
SharedMemoryArray shma = SharedMemoryArray .readOrCreate (memoryName , arrayShape , new DoubleType (), false , true );
151
152
ByteBuffer buff = shma .getDataBufferNoHeader ();
152
153
byte [] flat = new byte [buff .capacity ()];
153
- ByteBuffer buff2 = ByteBuffer .wrap (flat );
154
+ ByteBuffer buff2 = ByteBuffer .wrap (flat ). order ( ByteOrder . LITTLE_ENDIAN ) ;
154
155
tensor .asRawTensor ().data ().read (flat , 0 , buff .capacity ());
155
- buff = buff2 ;
156
+ buff . put ( buff2 ) ;
156
157
if (PlatformDetection .isWindows ()) shma .close ();
157
158
}
158
159
@@ -167,9 +168,9 @@ private static void buildFromTensorLong(TInt64 tensor, String memoryName) throws
167
168
SharedMemoryArray shma = SharedMemoryArray .readOrCreate (memoryName , arrayShape , new LongType (), false , true );
168
169
ByteBuffer buff = shma .getDataBufferNoHeader ();
169
170
byte [] flat = new byte [buff .capacity ()];
170
- ByteBuffer buff2 = ByteBuffer .wrap (flat );
171
+ ByteBuffer buff2 = ByteBuffer .wrap (flat ). order ( ByteOrder . LITTLE_ENDIAN ) ;
171
172
tensor .asRawTensor ().data ().read (flat , 0 , buff .capacity ());
172
- buff = buff2 ;
173
+ buff . put ( buff2 ) ;
173
174
if (PlatformDetection .isWindows ()) shma .close ();
174
175
}
175
176
}
0 commit comments