|
7 | 7 | from keras.src import backend
|
8 | 8 | from keras.src import layers
|
9 | 9 | from keras.src import testing
|
| 10 | +from keras.src.testing.test_utils import named_product |
10 | 11 |
|
11 | 12 |
|
12 | 13 | class ResizingTest(testing.TestCase):
|
13 |
| - def test_resizing_basics(self): |
14 |
| - self.run_layer_test( |
15 |
| - layers.Resizing, |
16 |
| - init_kwargs={ |
17 |
| - "height": 6, |
18 |
| - "width": 6, |
19 |
| - "data_format": "channels_last", |
20 |
| - "interpolation": "bicubic", |
21 |
| - "crop_to_aspect_ratio": True, |
22 |
| - }, |
23 |
| - input_shape=(2, 12, 12, 3), |
24 |
| - expected_output_shape=(2, 6, 6, 3), |
25 |
| - expected_num_trainable_weights=0, |
26 |
| - expected_num_non_trainable_weights=0, |
27 |
| - expected_num_seed_generators=0, |
28 |
| - expected_num_losses=0, |
29 |
| - supports_masking=False, |
30 |
| - run_training_check=False, |
31 |
| - ) |
32 |
| - self.run_layer_test( |
33 |
| - layers.Resizing, |
34 |
| - init_kwargs={ |
35 |
| - "height": 6, |
36 |
| - "width": 6, |
37 |
| - "data_format": "channels_first", |
38 |
| - "interpolation": "bilinear", |
39 |
| - "crop_to_aspect_ratio": True, |
40 |
| - }, |
41 |
| - input_shape=(2, 3, 12, 12), |
42 |
| - expected_output_shape=(2, 3, 6, 6), |
43 |
| - expected_num_trainable_weights=0, |
44 |
| - expected_num_non_trainable_weights=0, |
45 |
| - expected_num_seed_generators=0, |
46 |
| - expected_num_losses=0, |
47 |
| - supports_masking=False, |
48 |
| - run_training_check=False, |
49 |
| - ) |
50 |
| - self.run_layer_test( |
51 |
| - layers.Resizing, |
52 |
| - init_kwargs={ |
53 |
| - "height": 6, |
54 |
| - "width": 6, |
55 |
| - "data_format": "channels_last", |
56 |
| - "interpolation": "nearest", |
57 |
| - "crop_to_aspect_ratio": False, |
58 |
| - }, |
59 |
| - input_shape=(2, 12, 12, 3), |
60 |
| - expected_output_shape=(2, 6, 6, 3), |
61 |
| - expected_num_trainable_weights=0, |
62 |
| - expected_num_non_trainable_weights=0, |
63 |
| - expected_num_seed_generators=0, |
64 |
| - expected_num_losses=0, |
65 |
| - supports_masking=False, |
66 |
| - run_training_check=False, |
| 14 | + @parameterized.named_parameters( |
| 15 | + named_product( |
| 16 | + interpolation=["nearest", "bilinear", "bicubic", "lanczos5"], |
| 17 | + crop_pad=[(False, False), (True, False), (False, True)], |
| 18 | + antialias=[False, True], |
| 19 | + data_format=["channels_last", "channels_first"], |
67 | 20 | )
|
68 |
| - |
69 |
| - @pytest.mark.skipif( |
70 |
| - backend.backend() == "torch", reason="Torch does not support lanczos." |
71 | 21 | )
|
72 |
| - def test_resizing_basics_lanczos5(self): |
| 22 | + def test_resizing_basics( |
| 23 | + self, |
| 24 | + interpolation, |
| 25 | + crop_pad, |
| 26 | + antialias, |
| 27 | + data_format, |
| 28 | + ): |
| 29 | + if interpolation == "lanczos5" and backend.backend() == "torch": |
| 30 | + self.skipTest("Torch does not support lanczos.") |
| 31 | + |
| 32 | + crop_to_aspect_ratio, pad_to_aspect_ratio = crop_pad |
| 33 | + if data_format == "channels_last": |
| 34 | + input_shape = (2, 12, 12, 3) |
| 35 | + expected_output_shape = (2, 6, 6, 3) |
| 36 | + else: |
| 37 | + input_shape = (2, 3, 12, 12) |
| 38 | + expected_output_shape = (2, 3, 6, 6) |
| 39 | + |
73 | 40 | self.run_layer_test(
|
74 | 41 | layers.Resizing,
|
75 | 42 | init_kwargs={
|
76 | 43 | "height": 6,
|
77 | 44 | "width": 6,
|
78 |
| - "data_format": "channels_first", |
79 |
| - "interpolation": "lanczos5", |
80 |
| - "crop_to_aspect_ratio": False, |
| 45 | + "interpolation": interpolation, |
| 46 | + "crop_to_aspect_ratio": crop_to_aspect_ratio, |
| 47 | + "pad_to_aspect_ratio": pad_to_aspect_ratio, |
| 48 | + "antialias": antialias, |
| 49 | + "data_format": data_format, |
81 | 50 | },
|
82 |
| - input_shape=(2, 3, 12, 12), |
83 |
| - expected_output_shape=(2, 3, 6, 6), |
| 51 | + input_shape=input_shape, |
| 52 | + expected_output_shape=expected_output_shape, |
84 | 53 | expected_num_trainable_weights=0,
|
85 | 54 | expected_num_non_trainable_weights=0,
|
86 | 55 | expected_num_seed_generators=0,
|
|
0 commit comments