Skip to content

Commit

Permalink
use values instead of Fixed for user specified hp value (#1534)
Browse files Browse the repository at this point in the history
Co-authored-by: Haifeng Jin <haifeng-jin@users.noreply.github.com>
  • Loading branch information
haifeng-jin and haifeng-jin committed Mar 12, 2021
1 parent 664e83e commit 1b3425f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
5 changes: 2 additions & 3 deletions autokeras/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import kerastuner
import tensorflow as tf
from kerastuner.engine import hyperparameters
from packaging.version import parse
from tensorflow.python.util import nest

Expand Down Expand Up @@ -114,8 +113,6 @@ def run_with_adaptive_batch_size(batch_size, func, **fit_kwargs):
def get_hyperparameter(value, hp, dtype):
if value is None:
return hp
elif isinstance(value, dtype):
return hyperparameters.Fixed(hp.name, value)
return value


Expand All @@ -126,6 +123,8 @@ def add_to_hp(hp, hps, name=None):
hp: kerastuner.HyperParameters.
name: String. If left unspecified, the hp name is used.
"""
if not isinstance(hp, kerastuner.engine.hyperparameters.HyperParameter):
return hp
kwargs = hp.get_config()
if name is None:
name = hp.name
Expand Down
7 changes: 4 additions & 3 deletions tests/unit_tests/utils/utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ def test_get_hyperparameter_with_none_return_hp():
assert isinstance(hp, hyperparameters.Choice)


def test_get_hyperparameter_with_int_return_fixed():
hp = utils.get_hyperparameter(10, hyperparameters.Choice("hp", [10, 20]), int)
assert isinstance(hp, hyperparameters.Fixed)
def test_get_hyperparameter_with_int_return_int():
value = utils.get_hyperparameter(10, hyperparameters.Choice("hp", [10, 20]), int)
assert isinstance(value, int)
assert value == 10


def test_get_hyperparameter_with_hp_return_same():
Expand Down

0 comments on commit 1b3425f

Please sign in to comment.