Example #1
0
def convert_optimizer_trial_to_hps(
        hps: hp_module.HyperParameters,
        optimizer_trial: Dict[Text, Any]) -> hp_module.HyperParameters:
    """Converts Optimizer Trial parameters into KerasTuner HyperParameters."""
    hps = hp_module.HyperParameters.from_config(hps.get_config())
    hps.values = {}
    for param in optimizer_trial["parameters"]:
        if "floatValue" in param:
            hps.values[param["parameter"]] = float(param["floatValue"])
        if "intValue" in param:
            hps.values[param["parameter"]] = int(param["intValue"])
        if "stringValue" in param:
            hps.values[param["parameter"]] = str(param["stringValue"])
    return hps
Example #2
0
def convert_vizier_trial_to_hps(
        hps: hp_module.HyperParameters,
        vizier_trial: Dict[Text, Any]) -> hp_module.HyperParameters:
    """Converts Vizier Trial parameters into KerasTuner HyperParameters.

    Args:
        hps: Sample KerasTuner HyperParameters object for config initialization
        vizier_trial: A Vizier Trial instance.

    Returns:
        A KerasTuner HyperParameters object that holds the Vizier Trial
        parameters.
    """
    hps = hp_module.HyperParameters.from_config(hps.get_config())
    hps.values = convert_vizier_trial_to_dict(vizier_trial)
    return hps