2626
2727import java .io .IOException ;
2828import java .nio .ByteBuffer ;
29+ import java .nio .ByteOrder ;
2930import java .util .Arrays ;
3031
3132import org .tensorflow .Tensor ;
@@ -100,9 +101,9 @@ private static void buildFromTensorUByte(Tensor<TUint8> tensor, String memoryNam
100101 SharedMemoryArray shma = SharedMemoryArray .readOrCreate (memoryName , arrayShape , new UnsignedByteType (), false , true );
101102 ByteBuffer buff = shma .getDataBufferNoHeader ();
102103 byte [] flat = new byte [buff .capacity ()];
103- ByteBuffer buff2 = ByteBuffer .wrap (flat );
104+ ByteBuffer buff2 = ByteBuffer .wrap (flat ). order ( ByteOrder . LITTLE_ENDIAN ) ;
104105 tensor .rawData ().read (flat , 0 , buff .capacity ());
105- buff = buff2 ;
106+ buff . put ( buff2 ) ;
106107 if (PlatformDetection .isWindows ()) shma .close ();
107108 }
108109
@@ -116,9 +117,9 @@ private static void buildFromTensorInt(Tensor<TInt32> tensor, String memoryName)
116117 SharedMemoryArray shma = SharedMemoryArray .readOrCreate (memoryName , arrayShape , new IntType (), false , true );
117118 ByteBuffer buff = shma .getDataBufferNoHeader ();
118119 byte [] flat = new byte [buff .capacity ()];
119- ByteBuffer buff2 = ByteBuffer .wrap (flat );
120+ ByteBuffer buff2 = ByteBuffer .wrap (flat ). order ( ByteOrder . LITTLE_ENDIAN ) ;
120121 tensor .rawData ().read (flat , 0 , buff .capacity ());
121- buff = buff2 ;
122+ buff . put ( buff2 ) ;
122123 if (PlatformDetection .isWindows ()) shma .close ();
123124 }
124125
@@ -132,9 +133,9 @@ private static void buildFromTensorFloat(Tensor<TFloat32> tensor, String memoryN
132133 SharedMemoryArray shma = SharedMemoryArray .readOrCreate (memoryName , arrayShape , new FloatType (), false , true );
133134 ByteBuffer buff = shma .getDataBufferNoHeader ();
134135 byte [] flat = new byte [buff .capacity ()];
135- ByteBuffer buff2 = ByteBuffer .wrap (flat );
136+ ByteBuffer buff2 = ByteBuffer .wrap (flat ). order ( ByteOrder . LITTLE_ENDIAN ) ;
136137 tensor .rawData ().read (flat , 0 , buff .capacity ());
137- buff = buff2 ;
138+ buff . put ( buff2 ) ;
138139 if (PlatformDetection .isWindows ()) shma .close ();
139140 }
140141
@@ -148,9 +149,9 @@ private static void buildFromTensorDouble(Tensor<TFloat64> tensor, String memory
148149 SharedMemoryArray shma = SharedMemoryArray .readOrCreate (memoryName , arrayShape , new DoubleType (), false , true );
149150 ByteBuffer buff = shma .getDataBufferNoHeader ();
150151 byte [] flat = new byte [buff .capacity ()];
151- ByteBuffer buff2 = ByteBuffer .wrap (flat );
152+ ByteBuffer buff2 = ByteBuffer .wrap (flat ). order ( ByteOrder . LITTLE_ENDIAN ) ;
152153 tensor .rawData ().read (flat , 0 , buff .capacity ());
153- buff = buff2 ;
154+ buff . put ( buff2 ) ;
154155 if (PlatformDetection .isWindows ()) shma .close ();
155156 }
156157
@@ -165,9 +166,9 @@ private static void buildFromTensorLong(Tensor<TInt64> tensor, String memoryName
165166 SharedMemoryArray shma = SharedMemoryArray .readOrCreate (memoryName , arrayShape , new LongType (), false , true );
166167 ByteBuffer buff = shma .getDataBufferNoHeader ();
167168 byte [] flat = new byte [buff .capacity ()];
168- ByteBuffer buff2 = ByteBuffer .wrap (flat );
169+ ByteBuffer buff2 = ByteBuffer .wrap (flat ). order ( ByteOrder . LITTLE_ENDIAN ) ;
169170 tensor .rawData ().read (flat , 0 , buff .capacity ());
170- buff = buff2 ;
171+ buff . put ( buff2 ) ;
171172 if (PlatformDetection .isWindows ()) shma .close ();
172173 }
173174}
0 commit comments