Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions keras_hub/src/models/mobilenet/mobilenet_backbone_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ def setUp(self):
"input_activation": "hard_swish",
"output_activation": "hard_swish",
"input_num_filters": 16,
"image_shape": (224, 224, 3),
"image_shape": (32, 32, 3),
"depthwise_filters": 8,
"squeeze_and_excite": 0.5,
"last_layer_filter": 288,
}
self.input_data = keras.ops.ones((2, 224, 224, 3), dtype="float32")
self.input_data = keras.ops.ones((2, 32, 32, 3), dtype="float32")

def test_backbone_basics(self):
self.run_vision_backbone_test(
cls=MobileNetBackbone,
init_kwargs=self.init_kwargs,
input_data=self.input_data,
expected_output_shape=(2, 7, 7, 288),
expected_output_shape=(2, 1, 1, 288),
run_mixed_precision_check=True,
run_data_format_check=False,
)
Expand Down
28 changes: 19 additions & 9 deletions keras_hub/src/models/mobilenet/mobilenet_image_classifier_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@
from keras_hub.src.models.mobilenet.mobilenet_image_classifier import (
MobileNetImageClassifier,
)
from keras_hub.src.models.mobilenet.mobilenet_image_classifier_preprocessor import ( # noqa: E501
MobileNetImageClassifierPreprocessor,
)
from keras_hub.src.models.mobilenet.mobilenet_image_converter import (
MobileNetImageConverter,
)
from keras_hub.src.tests.test_case import TestCase


class MobileNetImageClassifierTest(TestCase):
def setUp(self):
# Setup model.
self.images = np.ones((2, 224, 224, 3), dtype="float32")
self.labels = [0, 3]
self.images = np.ones((2, 32, 32, 3), dtype="float32")
self.labels = [0, 2]
self.backbone = MobileNetBackbone(
stackwise_expansion=[
[40, 56],
Expand Down Expand Up @@ -46,34 +52,38 @@ def setUp(self):
input_activation="hard_swish",
output_activation="hard_swish",
input_num_filters=16,
image_shape=(224, 224, 3),
image_shape=(32, 32, 3),
depthwise_filters=8,
squeeze_and_excite=0.5,
last_layer_filter=288,
)
self.image_converter = MobileNetImageConverter(
height=32, width=32, scale=1 / 255.0
)
self.preprocessor = MobileNetImageClassifierPreprocessor(
self.image_converter
)
self.init_kwargs = {
"backbone": self.backbone,
"num_classes": 2,
"activation": "softmax",
"preprocessor": self.preprocessor,
"num_classes": 3,
}
self.train_data = (
self.images,
self.labels,
)

def test_classifier_basics(self):
pytest.skip(
reason="TODO: enable after preprocessor flow is figured out"
)
self.run_task_test(
cls=MobileNetImageClassifier,
init_kwargs=self.init_kwargs,
train_data=self.train_data,
expected_output_shape=(2, 2),
expected_output_shape=(2, 3),
)

@pytest.mark.large
def test_smallest_preset(self):
pytest.skip(reason="TODO: enable after presets are uploaded")
# Test that our forward pass is stable!
image_batch = self.load_test_image()[None, ...] / 255.0
self.run_preset_test(
Expand Down
Loading