@@ -273,5 +273,43 @@ public void boolean_mask()
273
273
Assert . IsTrue ( Enumerable . SequenceEqual ( new int [ ] { 0 , 2 } , masked . ToArray < int > ( ) ) ) ;
274
274
}
275
275
}
276
+
277
+ /// <summary>
278
+ /// Creates a tensor from an image of 256x256x3 and resizes it to 100x100x3
279
+ /// </summary>
280
+ [ TestMethod ]
281
+ public unsafe void tensor_resize ( )
282
+ {
283
+ var imageArray = new float [ 256 * 256 * 3 ] ;
284
+
285
+ using var newSize = tf . convert_to_tensor ( new int [ ] { 100 , 100 } ) ;
286
+
287
+ using ( var t = new Tensor ( imageArray , new long [ ] { 1 , 256 , 256 , 3 } , tf . float32 ) )
288
+ {
289
+ Assert . IsFalse ( t . IsDisposed ) ;
290
+ Assert . AreEqual ( 256 * 256 * 3 * sizeof ( float ) , ( int ) t . bytesize ) ;
291
+
292
+ using var resized = tf . image . resize_bilinear ( t , newSize ) ;
293
+ EXPECT_EQ ( ( int ) resized . shape [ 0 ] , 1 ) ;
294
+ EXPECT_EQ ( ( int ) resized . shape [ 1 ] , 100 ) ;
295
+ EXPECT_EQ ( ( int ) resized . shape [ 2 ] , 100 ) ;
296
+ EXPECT_EQ ( ( int ) resized . shape [ 3 ] , 3 ) ;
297
+ }
298
+
299
+ fixed ( float * ptr = & imageArray [ 0 ] )
300
+ {
301
+ using ( var t = new Tensor ( ( IntPtr ) ptr , new long [ ] { imageArray . Length } , tf . float32 , 4 * imageArray . Length ) )
302
+ {
303
+ Assert . IsFalse ( t . IsDisposed ) ;
304
+ Assert . AreEqual ( 256 * 256 * 3 * sizeof ( float ) , ( int ) t . bytesize ) ;
305
+
306
+ using var resized = tf . image . resize_bilinear ( t , newSize ) ;
307
+ EXPECT_EQ ( ( int ) resized . shape [ 0 ] , 1 ) ;
308
+ EXPECT_EQ ( ( int ) resized . shape [ 1 ] , 100 ) ;
309
+ EXPECT_EQ ( ( int ) resized . shape [ 2 ] , 100 ) ;
310
+ EXPECT_EQ ( ( int ) resized . shape [ 3 ] , 3 ) ;
311
+ }
312
+ }
313
+ }
276
314
}
277
315
}
0 commit comments