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
4 changes: 4 additions & 0 deletions keras_hub/src/models/task_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ def test_save_to_preset(self):
new_out = restored_task.backbone.predict(data)
self.assertAllClose(ref_out, new_out)

# Check setting dtype.
restored_task = TextClassifier.from_preset(save_dir, dtype="float16")
self.assertEqual("float16", restored_task.backbone.dtype_policy.name)

@pytest.mark.large
def test_save_to_preset_custom_backbone_and_preprocessor(self):
preprocessor = keras.layers.Rescaling(1 / 255.0)
Expand Down
6 changes: 6 additions & 0 deletions keras_hub/src/utils/preset_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,12 @@ def load_task(self, cls, load_weights, load_task_weights, **kwargs):
cls, load_weights, load_task_weights, **kwargs
)
# We found a `task.json` with a complete config for our class.
# Forward backbone args.
backbone_kwargs, kwargs = self.get_backbone_kwargs(**kwargs)
if "backbone" in task_config["config"]:
backbone_config = task_config["config"]["backbone"]["config"]
backbone_config = {**backbone_config, **backbone_kwargs}
task_config["config"]["backbone"]["config"] = backbone_config
task = load_serialized_object(task_config, **kwargs)
if task.preprocessor and hasattr(
task.preprocessor, "load_preset_assets"
Expand Down
Loading