@@ -2511,6 +2511,86 @@ def testNameScope(self):
2511
2511
y = image_ops .resize_images (single_image , [55 , 66 ])
2512
2512
self .assertTrue (y .op .name .startswith ("resize_images" ))
2513
2513
2514
+ def _ResizeImageCall (self , x , max_h , max_w , preserve_aspect_ratio ,
2515
+ use_tensor_inputs ):
2516
+ if use_tensor_inputs :
2517
+ target_max = ops .convert_to_tensor ([max_h , max_w ])
2518
+ x_tensor = array_ops .placeholder (x .dtype , shape = [None ] * x .ndim )
2519
+ feed_dict = {x_tensor : x }
2520
+ else :
2521
+ target_max = [max_h , max_w ]
2522
+ x_tensor = x
2523
+ feed_dict = {}
2524
+
2525
+ y = image_ops .resize_images (x_tensor , target_max ,
2526
+ preserve_aspect_ratio = preserve_aspect_ratio )
2527
+
2528
+ with self .test_session (use_gpu = True ):
2529
+ return y .eval (feed_dict = feed_dict )
2530
+
2531
+ def _assertResizeEqual (self , x , x_shape , y , y_shape ,
2532
+ preserve_aspect_ratio = True ,
2533
+ use_tensor_inputs_options = None ):
2534
+ use_tensor_inputs_options = use_tensor_inputs_options or [False , True ]
2535
+ target_height , target_width , _ = y_shape
2536
+ x = np .array (x ).reshape (x_shape )
2537
+ y = np .array (y ).reshape (y_shape )
2538
+
2539
+ for use_tensor_inputs in use_tensor_inputs_options :
2540
+ y_tf = self ._ResizeImageCall (x , target_height , target_width ,
2541
+ preserve_aspect_ratio , use_tensor_inputs )
2542
+ self .assertAllClose (y , y_tf )
2543
+
2544
+ def _assertResizeCheckShape (self , x , x_shape , target_shape ,
2545
+ y_shape , preserve_aspect_ratio = True ,
2546
+ use_tensor_inputs_options = None ):
2547
+ use_tensor_inputs_options = use_tensor_inputs_options or [False , True ]
2548
+ target_height , target_width = target_shape
2549
+ x = np .array (x ).reshape (x_shape )
2550
+ y = np .zeros (y_shape )
2551
+
2552
+ for use_tensor_inputs in use_tensor_inputs_options :
2553
+ y_tf = self ._ResizeImageCall (x , target_height , target_width ,
2554
+ preserve_aspect_ratio , use_tensor_inputs )
2555
+ self .assertShapeEqual (y , ops .convert_to_tensor (y_tf ))
2556
+
2557
+ def testPreserveAspectRatioMultipleImages (self ):
2558
+ x_shape = [10 , 100 , 100 , 10 ]
2559
+ x = np .random .uniform (size = x_shape )
2560
+
2561
+ self ._assertResizeCheckShape (x , x_shape , [250 , 250 ], [10 , 250 , 250 , 10 ],
2562
+ preserve_aspect_ratio = False )
2563
+
2564
+ def testPreserveAspectRatioNoOp (self ):
2565
+ x_shape = [10 , 10 , 10 ]
2566
+ x = np .random .uniform (size = x_shape )
2567
+
2568
+ self ._assertResizeEqual (x , x_shape , x , x_shape )
2569
+
2570
+ def testPreserveAspectRatioSmaller (self ):
2571
+ x_shape = [100 , 100 , 10 ]
2572
+ x = np .random .uniform (size = x_shape )
2573
+
2574
+ self ._assertResizeCheckShape (x , x_shape , [75 , 50 ], [50 , 50 , 10 ])
2575
+
2576
+ def testPreserveAspectRatioSmallerMultipleImages (self ):
2577
+ x_shape = [10 , 100 , 100 , 10 ]
2578
+ x = np .random .uniform (size = x_shape )
2579
+
2580
+ self ._assertResizeCheckShape (x , x_shape , [75 , 50 ], [10 , 50 , 50 , 10 ])
2581
+
2582
+ def testPreserveAspectRatioLarger (self ):
2583
+ x_shape = [100 , 100 , 10 ]
2584
+ x = np .random .uniform (size = x_shape )
2585
+
2586
+ self ._assertResizeCheckShape (x , x_shape , [150 , 200 ], [150 , 150 , 10 ])
2587
+
2588
+ def testPreserveAspectRatioSameRatio (self ):
2589
+ x_shape = [1920 , 1080 , 3 ]
2590
+ x = np .random .uniform (size = x_shape )
2591
+
2592
+ self ._assertResizeCheckShape (x , x_shape , [3840 , 2160 ], [3840 , 2160 , 3 ])
2593
+
2514
2594
2515
2595
class ResizeImageWithCropOrPadTest (test_util .TensorFlowTestCase ):
2516
2596
0 commit comments