in src/python/tensorflow_cloud/tuner/utils.py [0:0]
def format_objective(
objective: Union[Text, oracle_module.Objective,
List[Union[Text, oracle_module.Objective]]],
direction: Optional[Text] = None) -> List[oracle_module.Objective]:
"""Formats objective to a list of oracle_module.Objective.
Args:
objective: If a string, the direction of the optimization (min or max)
will be inferred.
direction: Optional. e.g. 'min' or 'max'.
Returns:
A list of oracle_module.Objective.
Raises:
TypeError: indicates wrong objective format.
"""
if isinstance(objective, oracle_module.Objective):
return [objective]
if isinstance(objective, str):
if direction:
return [oracle_module.Objective(objective, direction)]
return [
oracle_module.Objective(
objective, metrics_tracking.infer_metric_direction(objective)
)
]
if isinstance(objective, list):
if isinstance(objective[0], oracle_module.Objective):
return objective
if isinstance(objective[0], str):
return [
oracle_module.Objective(
m, metrics_tracking.infer_metric_direction(m))
for m in objective
]
raise TypeError(
"Objective should be either string or oracle_module.Objective, "
"found {}".format(objective)
)