Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Segformer test for num_classes 1 with softmax #2401

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions keras_cv/models/segmentation/segformer/segformer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ def test_segformer_preset_error(self):
def test_segformer_call(self):
backbone = MiTBackbone.from_preset("mit_b0")
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)

Expand Down Expand Up @@ -98,7 +99,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)
Expand All @@ -121,7 +122,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)
Expand Down
Loading