From ddf6e46e3e9b59b84ec0766ee27fb89a61f2b1c8 Mon Sep 17 00:00:00 2001 From: sampathweb <1437573+sampathweb@users.noreply.github.com> Date: Thu, 21 Mar 2024 12:59:44 -0700 Subject: [PATCH 1/2] Fix Segformer test for num_classes 1 with softmax --- keras_cv/models/segmentation/segformer/segformer_test.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/keras_cv/models/segmentation/segformer/segformer_test.py b/keras_cv/models/segmentation/segformer/segformer_test.py index 5f33b033da..4ae247422d 100644 --- a/keras_cv/models/segmentation/segformer/segformer_test.py +++ b/keras_cv/models/segmentation/segformer/segformer_test.py @@ -53,7 +53,7 @@ def test_segformer_preset_error(self): @pytest.mark.large def test_segformer_call(self): backbone = MiTBackbone.from_preset("mit_b0") - mit_model = SegFormer(backbone=backbone, num_classes=1) + mit_model = SegFormer(backbone=backbone, num_classes=2) images = np.random.uniform(size=(2, 224, 224, 3)) mit_output = mit_model(images) @@ -98,7 +98,7 @@ def test_saved_model(self): target_size = [512, 512, 3] backbone = MiTBackbone.from_preset("mit_b0", input_shape=[512, 512, 3]) - model = SegFormer(backbone=backbone, num_classes=1) + model = SegFormer(backbone=backbone, num_classes=2) input_batch = np.ones(shape=[2] + target_size) model_output = model(input_batch) @@ -121,7 +121,7 @@ def test_saved_model(self): def test_preset_saved_model(self): target_size = [224, 224, 3] - model = SegFormer.from_preset("segformer_b0", num_classes=1) + model = SegFormer.from_preset("segformer_b0", num_classes=2) input_batch = np.ones(shape=[2] + target_size) model_output = model(input_batch) From 2028392f927a92366bfe0b85e718a7cd6190142f Mon Sep 17 00:00:00 2001 From: sampathweb <1437573+sampathweb@users.noreply.github.com> Date: Fri, 22 Mar 2024 09:56:10 -0700 Subject: [PATCH 2/2] fix segformer test gpu --- keras_cv/models/segmentation/segformer/segformer_test.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/keras_cv/models/segmentation/segformer/segformer_test.py b/keras_cv/models/segmentation/segformer/segformer_test.py index 4ae247422d..bbd33ad472 100644 --- a/keras_cv/models/segmentation/segformer/segformer_test.py +++ b/keras_cv/models/segmentation/segformer/segformer_test.py @@ -53,13 +53,14 @@ def test_segformer_preset_error(self): @pytest.mark.large def test_segformer_call(self): backbone = MiTBackbone.from_preset("mit_b0") - mit_model = SegFormer(backbone=backbone, num_classes=2) - + mit_model = SegFormer(backbone=backbone, num_classes=1) + mit_model.compile(loss=keras.losses.BinaryCrossentropy()) images = np.random.uniform(size=(2, 224, 224, 3)) mit_output = mit_model(images) mit_pred = mit_model.predict(images) seg_model = SegFormer.from_preset("segformer_b0", num_classes=1) + seg_model.compile(loss=keras.losses.BinaryCrossentropy()) seg_output = seg_model(images) seg_pred = seg_model.predict(images)