Skip to content

Commit 4e16673

Browse files
committed
Remove old asserts for python 3.12 support
1 parent 94b0a55 commit 4e16673

29 files changed

+147
-147
lines changed

keras_cv/src/datasets/pascal_voc/segmentation_test.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@ def test_get_image_ids(self):
105105
train_ids = ["2007_000032", "2007_000039", "2007_000063"]
106106
eval_ids = ["2007_000033"]
107107
train_eval_ids = train_ids + eval_ids
108-
self.assertEquals(
108+
self.assertEqual(
109109
segmentation._get_image_ids(data_dir, "train"), train_ids
110110
)
111-
self.assertEquals(
111+
self.assertEqual(
112112
segmentation._get_image_ids(data_dir, "eval"), eval_ids
113113
)
114-
self.assertEquals(
114+
self.assertEqual(
115115
segmentation._get_image_ids(data_dir, "trainval"), train_eval_ids
116116
)
117117

@@ -161,7 +161,7 @@ def test_parse_annotation_file(self):
161161
},
162162
],
163163
}
164-
self.assertEquals(metadata, expected_result)
164+
self.assertEqual(metadata, expected_result)
165165

166166
def test_decode_png_mask(self):
167167
local_data_dir = os.path.join(self.tempdir, "pascal_voc_2012/")
@@ -177,19 +177,19 @@ def test_decode_png_mask(self):
177177
segmentation._maybe_populate_voc_color_mapping()
178178
mask = segmentation._decode_png_mask(mask)
179179

180-
self.assertEquals(mask.shape, (281, 500, 1))
181-
self.assertEquals(
180+
self.assertEqual(mask.shape, (281, 500, 1))
181+
self.assertEqual(
182182
tf.reduce_max(mask), 255
183183
) # The 255 value is for the boundary
184-
self.assertEquals(
184+
self.assertEqual(
185185
tf.reduce_min(mask), 0
186186
) # The 0 value is for the background
187187
# The mask contains two classes, 1 and 15, see the label section in the
188188
# previous test case.
189-
self.assertEquals(
189+
self.assertEqual(
190190
tf.reduce_sum(tf.cast(tf.equal(mask, 1), tf.int32)), 4734
191191
)
192-
self.assertEquals(
192+
self.assertEqual(
193193
tf.reduce_sum(tf.cast(tf.equal(mask, 15), tf.int32)), 866
194194
)
195195

@@ -245,7 +245,7 @@ def test_parse_single_image(self):
245245
data_dir, "SegmentationObject", "2007_000032.png"
246246
),
247247
}
248-
self.assertEquals(result_dict, expected_result)
248+
self.assertEqual(result_dict, expected_result)
249249

250250
def test_build_metadata(self):
251251
local_data_dir = os.path.join(self.tempdir, "pascal_voc_2012/")
@@ -257,7 +257,7 @@ def test_build_metadata(self):
257257
image_ids = segmentation._get_image_ids(data_dir, "trainval")
258258
metadata = segmentation._build_metadata(data_dir, image_ids)
259259

260-
self.assertEquals(
260+
self.assertEqual(
261261
metadata["image/filename"],
262262
[
263263
"2007_000032.jpg",
@@ -296,7 +296,7 @@ def test_build_dataset(self):
296296
dataset = segmentation._build_dataset_from_metadata(metadata)
297297

298298
entry = next(dataset.take(1).as_numpy_iterator())
299-
self.assertEquals(entry["image/filename"], b"2007_000032.jpg")
299+
self.assertEqual(entry["image/filename"], b"2007_000032.jpg")
300300
expected_keys = [
301301
"image",
302302
"image/filename",
@@ -316,18 +316,18 @@ def test_build_dataset(self):
316316

317317
# Check the mask png content
318318
png = entry["class_segmentation"]
319-
self.assertEquals(png.shape, (281, 500, 1))
320-
self.assertEquals(
319+
self.assertEqual(png.shape, (281, 500, 1))
320+
self.assertEqual(
321321
tf.reduce_max(png), 255
322322
) # The 255 value is for the boundary
323-
self.assertEquals(
323+
self.assertEqual(
324324
tf.reduce_min(png), 0
325325
) # The 0 value is for the background
326326
# The mask contains two classes, 1 and 15, see the label section in the
327327
# previous test case.
328-
self.assertEquals(
328+
self.assertEqual(
329329
tf.reduce_sum(tf.cast(tf.equal(png, 1), tf.int32)), 4734
330330
)
331-
self.assertEquals(
331+
self.assertEqual(
332332
tf.reduce_sum(tf.cast(tf.equal(png, 15), tf.int32)), 866
333333
)

keras_cv/src/datasets/waymo/load_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_load_from_directory(self):
4444
# Extract records into a list
4545
dataset = [record for record in dataset]
4646

47-
self.assertEquals(len(dataset), 1)
47+
self.assertEqual(len(dataset), 1)
4848
self.assertNotEqual(dataset[0]["timestamp_micros"], 0)
4949

5050
@pytest.mark.skipif(
@@ -58,5 +58,5 @@ def test_load_from_files(self):
5858
# Extract records into a list
5959
dataset = [record for record in dataset]
6060

61-
self.assertEquals(len(dataset), 1)
61+
self.assertEqual(len(dataset), 1)
6262
self.assertNotEqual(dataset[0]["timestamp_micros"], 0)

keras_cv/src/layers/augmenter_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_call(self):
2727
]
2828
)
2929
output = augmenter(images)
30-
self.assertEquals(output.shape, images.shape)
30+
self.assertEqual(output.shape, images.shape)
3131

3232
def test_call_with_labels(self):
3333
images = {
@@ -43,4 +43,4 @@ def test_call_with_labels(self):
4343
]
4444
)
4545
output = augmenter(images)
46-
self.assertEquals(output["images"].shape, images["images"].shape)
46+
self.assertEqual(output["images"].shape, images["images"].shape)

keras_cv/src/layers/feature_pyramid_test.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_return_type_dict(self):
3030
inputs = {2: c2, 3: c3, 4: c4, 5: c5}
3131
output = layer(inputs)
3232
self.assertTrue(isinstance(output, dict))
33-
self.assertEquals(sorted(output.keys()), [2, 3, 4, 5])
33+
self.assertEqual(sorted(output.keys()), [2, 3, 4, 5])
3434

3535
def test_result_shapes(self):
3636
layer = FeaturePyramid(min_level=2, max_level=5)
@@ -42,9 +42,9 @@ def test_result_shapes(self):
4242
inputs = {2: c2, 3: c3, 4: c4, 5: c5}
4343
output = layer(inputs)
4444
for level in inputs.keys():
45-
self.assertEquals(output[level].shape[1], inputs[level].shape[1])
46-
self.assertEquals(output[level].shape[2], inputs[level].shape[2])
47-
self.assertEquals(output[level].shape[3], layer.num_channels)
45+
self.assertEqual(output[level].shape[1], inputs[level].shape[1])
46+
self.assertEqual(output[level].shape[2], inputs[level].shape[2])
47+
self.assertEqual(output[level].shape[3], layer.num_channels)
4848

4949
# Test with different resolution and channel size
5050
c2 = np.ones([2, 64, 128, 4])
@@ -56,9 +56,9 @@ def test_result_shapes(self):
5656
layer = FeaturePyramid(min_level=2, max_level=5)
5757
output = layer(inputs)
5858
for level in inputs.keys():
59-
self.assertEquals(output[level].shape[1], inputs[level].shape[1])
60-
self.assertEquals(output[level].shape[2], inputs[level].shape[2])
61-
self.assertEquals(output[level].shape[3], layer.num_channels)
59+
self.assertEqual(output[level].shape[1], inputs[level].shape[1])
60+
self.assertEqual(output[level].shape[2], inputs[level].shape[2])
61+
self.assertEqual(output[level].shape[3], layer.num_channels)
6262

6363
def test_with_keras_input_tensor(self):
6464
# This mimic the model building with Backbone network
@@ -71,13 +71,13 @@ def test_with_keras_input_tensor(self):
7171
inputs = {2: c2, 3: c3, 4: c4, 5: c5}
7272
output = layer(inputs)
7373
for level in inputs.keys():
74-
self.assertEquals(output[level].shape[1], inputs[level].shape[1])
75-
self.assertEquals(output[level].shape[2], inputs[level].shape[2])
76-
self.assertEquals(output[level].shape[3], layer.num_channels)
74+
self.assertEqual(output[level].shape[1], inputs[level].shape[1])
75+
self.assertEqual(output[level].shape[2], inputs[level].shape[2])
76+
self.assertEqual(output[level].shape[3], layer.num_channels)
7777

7878
def test_invalid_lateral_layers(self):
7979
lateral_layers = [keras.layers.Conv2D(256, 1)] * 3
80-
with self.assertRaisesRegexp(
80+
with self.assertRaisesRegex(
8181
ValueError, "Expect lateral_layers to be a dict"
8282
):
8383
_ = FeaturePyramid(
@@ -88,7 +88,7 @@ def test_invalid_lateral_layers(self):
8888
3: keras.layers.Conv2D(256, 1),
8989
4: keras.layers.Conv2D(256, 1),
9090
}
91-
with self.assertRaisesRegexp(
91+
with self.assertRaisesRegex(
9292
ValueError, "with keys as .* [2, 3, 4, 5]"
9393
):
9494
_ = FeaturePyramid(
@@ -97,7 +97,7 @@ def test_invalid_lateral_layers(self):
9797

9898
def test_invalid_output_layers(self):
9999
output_layers = [keras.layers.Conv2D(256, 3)] * 3
100-
with self.assertRaisesRegexp(
100+
with self.assertRaisesRegex(
101101
ValueError, "Expect output_layers to be a dict"
102102
):
103103
_ = FeaturePyramid(
@@ -108,7 +108,7 @@ def test_invalid_output_layers(self):
108108
3: keras.layers.Conv2D(256, 3),
109109
4: keras.layers.Conv2D(256, 3),
110110
}
111-
with self.assertRaisesRegexp(
111+
with self.assertRaisesRegex(
112112
ValueError, "with keys as .* [2, 3, 4, 5]"
113113
):
114114
_ = FeaturePyramid(
@@ -126,13 +126,13 @@ def test_invalid_input_features(self):
126126
# Build required for Keas 3
127127
_ = layer(inputs)
128128
list_input = [c2, c3, c4, c5]
129-
with self.assertRaisesRegexp(
129+
with self.assertRaisesRegex(
130130
ValueError, "expects input features to be a dict"
131131
):
132132
layer(list_input)
133133

134134
dict_input_with_missing_feature = {2: c2, 3: c3, 4: c4}
135-
with self.assertRaisesRegexp(
135+
with self.assertRaisesRegex(
136136
ValueError, "Expect feature keys.*[2, 3, 4, 5]"
137137
):
138138
layer(dict_input_with_missing_feature)

keras_cv/src/layers/fusedmbconv_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def test_same_input_output_shapes(self):
3636
layer = FusedMBConvBlock(input_filters=32, output_filters=32)
3737

3838
output = layer(inputs)
39-
self.assertEquals(output.shape, [1, 64, 64, 32])
39+
self.assertEqual(output.shape, [1, 64, 64, 32])
4040
self.assertLen(output, 1)
4141
self.assertTrue(isinstance(output, tf.Tensor))
4242

@@ -45,7 +45,7 @@ def test_different_input_output_shapes(self):
4545
layer = FusedMBConvBlock(input_filters=32, output_filters=48)
4646

4747
output = layer(inputs)
48-
self.assertEquals(output.shape, [1, 64, 64, 48])
48+
self.assertEqual(output.shape, [1, 64, 64, 48])
4949
self.assertLen(output, 1)
5050
self.assertTrue(isinstance(output, tf.Tensor))
5151

@@ -56,6 +56,6 @@ def test_squeeze_excitation_ratio(self):
5656
)
5757

5858
output = layer(inputs)
59-
self.assertEquals(output.shape, [1, 64, 64, 48])
59+
self.assertEqual(output.shape, [1, 64, 64, 48])
6060
self.assertLen(output, 1)
6161
self.assertTrue(isinstance(output, tf.Tensor))

keras_cv/src/layers/mbconv_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def test_same_input_output_shapes(self):
3636
layer = MBConvBlock(input_filters=32, output_filters=32)
3737

3838
output = layer(inputs)
39-
self.assertEquals(output.shape, [1, 64, 64, 32])
39+
self.assertEqual(output.shape, [1, 64, 64, 32])
4040
self.assertLen(output, 1)
4141
self.assertTrue(isinstance(output, tf.Tensor))
4242

@@ -45,7 +45,7 @@ def test_different_input_output_shapes(self):
4545
layer = MBConvBlock(input_filters=32, output_filters=48)
4646

4747
output = layer(inputs)
48-
self.assertEquals(output.shape, [1, 64, 64, 48])
48+
self.assertEqual(output.shape, [1, 64, 64, 48])
4949
self.assertLen(output, 1)
5050
self.assertTrue(isinstance(output, tf.Tensor))
5151

@@ -54,6 +54,6 @@ def test_squeeze_excitation_ratio(self):
5454
layer = MBConvBlock(input_filters=32, output_filters=48, se_ratio=0.25)
5555

5656
output = layer(inputs)
57-
self.assertEquals(output.shape, [1, 64, 64, 48])
57+
self.assertEqual(output.shape, [1, 64, 64, 48])
5858
self.assertLen(output, 1)
5959
self.assertTrue(isinstance(output, tf.Tensor))

keras_cv/src/layers/preprocessing/cut_mix_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def test_single_image_input(self):
236236
ys = tf.one_hot(tf.constant([1]), 2)
237237
inputs = {"images": xs, "labels": ys}
238238
layer = CutMix()
239-
with self.assertRaisesRegexp(
239+
with self.assertRaisesRegex(
240240
ValueError, "CutMix received a single image to `call`"
241241
):
242242
_ = layer(inputs)
@@ -246,15 +246,15 @@ def test_int_labels(self):
246246
ys = tf.one_hot(tf.constant([1, 0]), 2, dtype=tf.int32)
247247
inputs = {"images": xs, "labels": ys}
248248
layer = CutMix()
249-
with self.assertRaisesRegexp(
249+
with self.assertRaisesRegex(
250250
ValueError, "CutMix received labels with type"
251251
):
252252
_ = layer(inputs)
253253

254254
def test_image_input(self):
255255
xs = tf.ones((2, 512, 512, 3))
256256
layer = CutMix()
257-
with self.assertRaisesRegexp(
257+
with self.assertRaisesRegex(
258258
ValueError, "CutMix expects inputs in a dictionary with format"
259259
):
260260
_ = layer(xs)

keras_cv/src/layers/preprocessing/fourier_mix_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def test_image_input_only(self):
147147
tf.float32,
148148
)
149149
layer = FourierMix()
150-
with self.assertRaisesRegexp(
150+
with self.assertRaisesRegex(
151151
ValueError, "expects inputs in a dictionary"
152152
):
153153
_ = layer(xs)
@@ -157,7 +157,7 @@ def test_single_image_input(self):
157157
ys = tf.one_hot(tf.constant([1]), 2)
158158
inputs = {"images": xs, "labels": ys}
159159
layer = FourierMix()
160-
with self.assertRaisesRegexp(
160+
with self.assertRaisesRegex(
161161
ValueError, "FourierMix received a single image to `call`"
162162
):
163163
_ = layer(inputs)

keras_cv/src/layers/preprocessing/mix_up_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def test_image_input_only(self):
159159
tf.float32,
160160
)
161161
layer = MixUp()
162-
with self.assertRaisesRegexp(
162+
with self.assertRaisesRegex(
163163
ValueError, "expects inputs in a dictionary"
164164
):
165165
_ = layer(xs)
@@ -169,7 +169,7 @@ def test_single_image_input(self):
169169
ys = tf.one_hot(tf.constant([1]), 2)
170170
inputs = {"images": xs, "labels": ys}
171171
layer = MixUp()
172-
with self.assertRaisesRegexp(
172+
with self.assertRaisesRegex(
173173
ValueError, "MixUp received a single image to `call`"
174174
):
175175
_ = layer(inputs)
@@ -179,15 +179,15 @@ def test_int_labels(self):
179179
ys = tf.one_hot(tf.constant([1, 0]), 2, dtype=tf.int32)
180180
inputs = {"images": xs, "labels": ys}
181181
layer = MixUp()
182-
with self.assertRaisesRegexp(
182+
with self.assertRaisesRegex(
183183
ValueError, "MixUp received labels with type"
184184
):
185185
_ = layer(inputs)
186186

187187
def test_image_input(self):
188188
xs = tf.ones((2, 512, 512, 3))
189189
layer = MixUp()
190-
with self.assertRaisesRegexp(
190+
with self.assertRaisesRegex(
191191
ValueError, "MixUp expects inputs in a dictionary with format"
192192
):
193193
_ = layer(xs)

keras_cv/src/layers/preprocessing/mosaic_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def test_image_input_only(self):
9191
tf.float32,
9292
)
9393
layer = Mosaic()
94-
with self.assertRaisesRegexp(
94+
with self.assertRaisesRegex(
9595
ValueError, "expects inputs in a dictionary"
9696
):
9797
_ = layer(xs)
@@ -101,15 +101,15 @@ def test_single_image_input(self):
101101
ys = tf.one_hot(tf.constant([1]), 2)
102102
inputs = {"images": xs, "labels": ys}
103103
layer = Mosaic()
104-
with self.assertRaisesRegexp(
104+
with self.assertRaisesRegex(
105105
ValueError, "Mosaic received a single image to `call`"
106106
):
107107
_ = layer(inputs)
108108

109109
def test_image_input(self):
110110
xs = tf.ones((2, 512, 512, 3))
111111
layer = Mosaic()
112-
with self.assertRaisesRegexp(
112+
with self.assertRaisesRegex(
113113
ValueError, "Mosaic expects inputs in a dictionary with format"
114114
):
115115
_ = layer(xs)

0 commit comments

Comments
 (0)